Class NumberValue

All Implemented Interfaces:
CSSPrimitiveValue2, ExtendedCSSPrimitiveValue, ExtendedCSSValue, Cloneable, CSSPrimitiveValue, CSSValue
Direct Known Subclasses:
PercentageValue

public class NumberValue extends PrimitiveValue
Number-specific CSSPrimitiveValue.
  • Field Details

    • realvalue

      protected float realvalue
  • Constructor Details

    • NumberValue

      public NumberValue()
    • NumberValue

      protected NumberValue(NumberValue copied)
  • Method Details

    • getCssText

      public String getCssText()
      Description copied from class: StyleValue
      Get a string representation of the current value.
      Specified by:
      getCssText in interface CSSValue
      Specified by:
      getCssText in class StyleValue
      Returns:
      the css text representing the value of this property.
    • writeCssText

      public void writeCssText(SimpleWriter wri) throws IOException
      Description copied from interface: ExtendedCSSValue
      Serialize this value to a SimpleWriter.
      Parameters:
      wri - the SimpleWriter.
      Throws:
      IOException - if an error happened while writing.
    • serializeAbsolute

      public void serializeAbsolute(SimpleWriter wri) throws IOException
      Throws:
      IOException
    • getMinifiedCssText

      public String getMinifiedCssText(String propertyName)
      Description copied from interface: ExtendedCSSValue
      Gives a minified version of the css text of the property, for the given property name.
      Specified by:
      getMinifiedCssText in interface ExtendedCSSValue
      Overrides:
      getMinifiedCssText in class StyleValue
      Parameters:
      propertyName - the property name.
      Returns:
      the minified css text.
    • minifyAbsolute

      public String minifyAbsolute(String propertyName)
    • setFloatValue

      public void setFloatValue(short unitType, float floatValue) throws DOMException
      Specified by:
      setFloatValue in interface CSSPrimitiveValue
      Overrides:
      setFloatValue in class PrimitiveValue
      Throws:
      DOMException
    • setFloatValuePt

      public void setFloatValuePt(float floatValue)
    • setIntegerValue

      public void setIntegerValue(int intValue)
    • setExpectInteger

      public void setExpectInteger()
      Overrides:
      setExpectInteger in class PrimitiveValue
    • setCssText

      public void setCssText(String cssText) throws DOMException
      Description copied from class: StyleValue
      Attempts to change this value to match the supplied css text.

      In css4j, it is not recommended to set property values using this method.

      Specified by:
      setCssText in interface CSSValue
      Overrides:
      setCssText in class StyleValue
      Throws:
      DOMException - SYNTAX_ERR: Raised if the specified CSS string value has a syntax error (according to the attached property) or is unparsable.
      INVALID_MODIFICATION_ERR: Raised if the specified CSS string value represents a different type of values than the values allowed by the CSS property.
      NO_MODIFICATION_ALLOWED_ERR: Raised if this value is read-only.
    • isCalculatedNumber

      public boolean isCalculatedNumber()
      Description copied from interface: CSSPrimitiveValue2
      Test whether this is a numeric value that was the result of a calc() expression.
      Specified by:
      isCalculatedNumber in interface CSSPrimitiveValue2
      Overrides:
      isCalculatedNumber in class PrimitiveValue
      Returns:
      true if this is a numeric value, and it was produced as the output of a calculation (instead of declared as a plain, constant numeric value).
    • setAbsolutizedUnit

      public void setAbsolutizedUnit()
      Set that the value that this number represents was originally specified as a calculation or as a relative unit, but comes from being either calculated or absolutized.

      This has consequences as to how the number is serialized.

    • isNegativeNumber

      public boolean isNegativeNumber()
      Description copied from interface: CSSPrimitiveValue2
      Test whether this is a numeric value that is less than zero.
      Specified by:
      isNegativeNumber in interface CSSPrimitiveValue2
      Overrides:
      isNegativeNumber in class PrimitiveValue
      Returns:
      true if this is a numeric value and its value is negative.
    • isNumberZero

      public boolean isNumberZero()
      Description copied from class: PrimitiveValue
      Is this value a number set to a value of zero, or an absolute value less than 1e-5 ?
      Specified by:
      isNumberZero in interface ExtendedCSSPrimitiveValue
      Overrides:
      isNumberZero in class PrimitiveValue
      Returns:
      true if this is a number and is set to zero (or equivalently small value).
    • getFloatValue

      public float getFloatValue(short unitType) throws DOMException
      Gets a float value in a specified unit. If this CSS value doesn't contain a float value or can't be converted into the specified unit, a DOMException is raised.
      Specified by:
      getFloatValue in interface CSSPrimitiveValue
      Overrides:
      getFloatValue in class PrimitiveValue
      Parameters:
      unitType - A unit code to get the float value. The unit code can only be a float unit type (i.e. CSS_NUMBER, CSS_PERCENTAGE, CSS_EMS, CSS_EXS, CSS_PX, CSS_CM, CSS_MM, CSS_IN, CSS_PT, CSS_PC, CSS_DEG, CSS_RAD, CSS_GRAD, CSS_MS, CSS_S, CSS_HZ, CSS_KHZ, CSS_DIMENSION).
      Returns:
      The float value in the specified unit.
      Throws:
      DOMException - INVALID_ACCESS_ERR if the CSS value can't be converted into the specified unit.
    • floatValueConversion

      public static float floatValueConversion(float fvalue, short declType, short unitType) throws DOMException
      Converts a float value, expressed in declType units, to unitType units.
      Parameters:
      fvalue - the float value to convert.
      declType - the declared type of the value.
      unitType - the desired unit type.
      Returns:
      the value converted to the unitType unit.
      Throws:
      DOMException - if the unit conversion could not be done.
    • getDimensionUnitText

      public String getDimensionUnitText()
      Gives the text representation of the dimension unit, if this value represents a dimension.
      Returns:
      the text representation of the dimension unit, or the empty string if this value does not represent a dimension.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class PrimitiveValue
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class PrimitiveValue
    • clone

      public NumberValue clone()
      Description copied from class: PrimitiveValue
      Creates and returns a copy of this object.

      The object will be the same except for the subproperty flag, that will be disabled in the clone object.

      Specified by:
      clone in interface ExtendedCSSValue
      Specified by:
      clone in class PrimitiveValue
      Returns:
      a copy of this object.
    • isLengthUnitType

      public static boolean isLengthUnitType(short primitiveType)
    • isAngleUnitType

      public static boolean isAngleUnitType(short primitiveType)
    • createCSSNumberValue

      public static NumberValue createCSSNumberValue(short unit, float floatValue)