Class NumberValue

All Implemented Interfaces:
CSSPrimitiveValue, CSSTypedValue, CSSValue, Serializable, Cloneable
Direct Known Subclasses:
PercentageValue

public class NumberValue extends TypedValue
Number-specific value.
See Also:
  • Field Details

    • realvalue

      protected float realvalue
  • Constructor Details

    • NumberValue

      public NumberValue()
    • NumberValue

      protected NumberValue(NumberValue copied)
  • Method Details

    • getUnitType

      public short getUnitType()
      Description copied from interface: CSSPrimitiveValue
      If this is a numeric value, get its unit type.
      Returns:
      the unit type, CSS_INVALID if the unit or type are not valid.
    • 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(io.sf.carte.util.SimpleWriter wri) throws IOException
      Description copied from interface: CSSValue
      Serialize this value to a SimpleWriter.
      Parameters:
      wri - the SimpleWriter.
      Throws:
      IOException - if an error happened while writing.
    • serializeAbsolute

      public void serializeAbsolute(io.sf.carte.util.SimpleWriter wri) throws IOException
      Throws:
      IOException
    • getMinifiedCssText

      public String getMinifiedCssText(String propertyName)
      Description copied from interface: CSSValue
      Gives a minified version of the css text of the property.

      It may be customized for the given property name.

      Specified by:
      getMinifiedCssText in interface CSSValue
      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
      Description copied from interface: CSSTypedValue
      If this value is numeric, set a float value with the given unit.
      Specified by:
      setFloatValue in interface CSSTypedValue
      Overrides:
      setFloatValue in class TypedValue
      Parameters:
      unitType - the unit type according to CSSUnit.
      floatValue - the float value.
      Throws:
      DOMException - INVALID_ACCESS_ERR if the unit is not a CSSUnit one, or this value is not a number.
      NO_MODIFICATION_ALLOWED_ERR if this value is unmodifiable.
    • setFloatValuePt

      public void setFloatValuePt(float floatValue)
    • setIntegerValue

      public void setIntegerValue(int intValue)
    • setExpectInteger

      public void setExpectInteger()
      Description copied from interface: CSSPrimitiveValue
      This value is expected to contain an integer.

      If this value is a non-integer number, an exception will be thrown immediately.

      If this value is a calc() that ever produces a non-integer number, the value shall be rounded to the nearest integer.

      If the value is a proxy that ever produces other than an integer number (without calc() involvement), an exception should be thrown later.

      Specified by:
      setExpectInteger in interface CSSPrimitiveValue
      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
      Parameters:
      cssText - the text value.
      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: CSSTypedValue
      Test whether this is a numeric value that was the result of a calc() expression.
      Specified by:
      isCalculatedNumber in interface CSSTypedValue
      Overrides:
      isCalculatedNumber in class TypedValue
      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: CSSPrimitiveValue
      Test whether this is a numeric value that is less than zero.
      Returns:
      true if this is a numeric value and its value is negative.
    • isNumberZero

      public boolean isNumberZero()
      Description copied from class: TypedValue
      Is this value a number set to a value of zero, or an absolute value less than 1e-5 ?
      Specified by:
      isNumberZero in interface CSSTypedValue
      Overrides:
      isNumberZero in class TypedValue
      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.
      Specified by:
      getFloatValue in interface CSSTypedValue
      Overrides:
      getFloatValue in class TypedValue
      Parameters:
      unitType - A unit code to get the float value, like CSS_NUMBER, CSS_PERCENTAGE, CSS_PT or CSS_EX. If the type is CSS_OTHER, the value shall be returned as is, regardless of the unit that was set with.
      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: TypedValue
      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 CSSValue
      Specified by:
      clone in class TypedValue
      Returns:
      a copy of this object.
    • createCSSNumberValue

      public static NumberValue createCSSNumberValue(short unit, float floatValue)