Length
Inheritance: java.lang.Object
All Implemented Interfaces: com.groupdocs.editor.htmlcss.css.datatypes.ICssDataType
public class Length implements ICssDataType
Represents a CSS length value in any supportable unit, including percentage and unitless type. Values may be integer or float, negative, zero and positive. Immutable structure.
This type covers the next CSS data types:
https://developer.mozilla.org/en-US/docs/Web/CSS/length
https://developer.mozilla.org/en-US/docs/Web/CSS/percentage
Constructors
Constructor | Description |
---|---|
Length() |
Fields
Field | Description |
---|---|
UnitlessZero | Unitless integer zero - default value, the same as default parameterless constructor |
OneHundredPercents | 100% |
FiftyPercents | 50% |
ZeroPercents | 0% |
Methods
Method | Description |
---|---|
fromValueWithUnit(float value, int unit) | Creates and returns an instance of Length type by specified float number and unit |
fromValueWithUnit(double value, int unit) | Creates and returns an instance of Length type by specified double number and unit |
fromValueWithUnit(int value, int unit) | Creates and returns an instance of Length type by specified integer number and unit |
isUnitlessZero() | Determines whether this instance is a unitless zero or not. |
isDefault() | Indicates whether this Length instance has a default value \u2014 unitless zero. |
getUnitType() | Returns a unit type of this Length instance. |
isInteger() | Indicates whether the numeric value of this Length instance was originally specified and stored as an integer (INT32) number |
isFloat() | Indicates whether the numeric value of this Length instance was originally specified and stored as a float (FP32) number |
getFloatValue() | Returns a float numeric value of the Length instance. |
getIntegerValue() | Returns an integer numeric value of this Length instance, if it is internally stored as an integer, or throws an exception, if it was originally stored as a float number. |
isAbsolute() | Gets if the length is given in absolute units. |
isRelative() | Gets if the length is given in relative units. |
isZero() | Determines whether the numeric value of this length is a zero number |
isNegative() | Determines whether the numeric value of this length is a negative number |
isPositive() | Determines whether the numeric value of this length is a positive number |
isUnitlessNonZero() | The value has unitless type, but is not a zero - positive or negative number |
toPixel() | Converts the length to a number of pixels, if possible. |
to(int unit) | Converts the length to the given unit, if possible. |
toStringSpecified(int unit) | Returns a string representation of this length in specified unit type. |
serializeDefault() | Returns a string representation of this length in its original native form (as it is stored), without converting length value to some other unit type |
equals(Length other) | Defines whether this value is equal to the other specified length |
equals(Object obj) | Determines whether this length is equal to specified object |
op_Multiply(Length multiplicand, int factor) | Multiplicates the given Length onto the given factor |
op_Equality(Length left, Length right) | Checks the equality of the two given lengths. |
op_Inequality(Length left, Length right) | Checks the inequality of the two given lengths. |
hashCode() | Calculates and returns a hash-code of this Length instance by combining hash-codes of the value and unit type |
deepClone() | Returns a full copy of this Length instance |
getUnitFromName(String unitName) | Tries to parse specified unit name and return corresponding value of a Unit enum. |
tryParse(String input, Length[] result) | Tries to parse a specified string as a Length value, including its numeric value and unit name |
parse(String input) | Parses and returns specified string as a Length value, including its numeric value and unit name, or throws an exception on failure |
Length()
public Length()
UnitlessZero
public static final Length UnitlessZero
Unitless integer zero - default value, the same as default parameterless constructor
OneHundredPercents
public static final Length OneHundredPercents
100%
FiftyPercents
public static final Length FiftyPercents
50%
ZeroPercents
public static final Length ZeroPercents
0%
fromValueWithUnit(float value, int unit)
public static Length fromValueWithUnit(float value, int unit)
Creates and returns an instance of Length type by specified float number and unit
Parameters:
Parameter | Type | Description |
---|---|---|
value | float | >Any float (FP32) number |
unit | int | Any valid unit type |
Returns: Length - New instance of Length type
fromValueWithUnit(double value, int unit)
public static Length fromValueWithUnit(double value, int unit)
Creates and returns an instance of Length type by specified double number and unit
Parameters:
Parameter | Type | Description |
---|---|---|
value | double | Any double (FP64) number, that will be converted to float (FP32) |
unit | int | Any valid unit type |
Returns: Length - New instance of Length type
fromValueWithUnit(int value, int unit)
public static Length fromValueWithUnit(int value, int unit)
Creates and returns an instance of Length type by specified integer number and unit
Parameters:
Parameter | Type | Description |
---|---|---|
value | int | Any integer number |
unit | int | Any valid unit type |
Returns: Length - New instance of Length type
isUnitlessZero()
public final boolean isUnitlessZero()
Determines whether this instance is a unitless zero or not. Unitless zero is default value of this type. Same as IsDefault property.
Returns: boolean
isDefault()
public final boolean isDefault()
Indicates whether this Length instance has a default value \u2014 unitless zero. Same as IsUnitlessZero property.
Returns: boolean
getUnitType()
public final int getUnitType()
Returns a unit type of this Length instance.
Returns: int
isInteger()
public final boolean isInteger()
Indicates whether the numeric value of this Length instance was originally specified and stored as an integer (INT32) number
Returns: boolean
isFloat()
public final boolean isFloat()
Indicates whether the numeric value of this Length instance was originally specified and stored as a float (FP32) number
Returns: boolean
getFloatValue()
public final float getFloatValue()
Returns a float numeric value of the Length instance. Never throws an exception - converts Integer value to Float if necessary.
Returns: float
getIntegerValue()
public final int getIntegerValue()
Returns an integer numeric value of this Length instance, if it is internally stored as an integer, or throws an exception, if it was originally stored as a float number.
Returns: int
isAbsolute()
public final boolean isAbsolute()
Gets if the length is given in absolute units. Such a length may be converted to pixels.
Returns: boolean
isRelative()
public final boolean isRelative()
Gets if the length is given in relative units. Such a length cannot be converted to pixels.
Returns: boolean
isZero()
public final boolean isZero()
Determines whether the numeric value of this length is a zero number
Returns: boolean
isNegative()
public final boolean isNegative()
Determines whether the numeric value of this length is a negative number
Returns: boolean
isPositive()
public final boolean isPositive()
Determines whether the numeric value of this length is a positive number
Returns: boolean
isUnitlessNonZero()
public final boolean isUnitlessNonZero()
The value has unitless type, but is not a zero - positive or negative number
Returns: boolean
toPixel()
public final float toPixel()
Converts the length to a number of pixels, if possible. If the current unit is relative, then an exception will be thrown.
Returns: float - The number of pixels represented by the current length.
to(int unit)
public final float to(int unit)
Converts the length to the given unit, if possible. If the current or given unit is relative, then an exception will be thrown.
Parameters:
Parameter | Type | Description |
---|---|---|
unit | int | The unit to convert to. |
Returns: float - The value in the given unit of the current length.
toStringSpecified(int unit)
public final String toStringSpecified(int unit)
Returns a string representation of this length in specified unit type. Numeric value will be converted in corresponding to unit type change.
Parameters:
Parameter | Type | Description |
---|---|---|
unit | int | Specified unit, to which this instance should be converted before serializing to the string. Should be valid. Cannot be unitless. |
Returns: java.lang.String - String representation
serializeDefault()
public final String serializeDefault()
Returns a string representation of this length in its original native form (as it is stored), without converting length value to some other unit type
Returns: java.lang.String - String instance
equals(Length other)
public final boolean equals(Length other)
Defines whether this value is equal to the other specified length
Parameters:
Parameter | Type | Description |
---|---|---|
other | Length | Other instance of Length type |
Returns: boolean - True if equal, otherwise false
equals(Object obj)
public boolean equals(Object obj)
Determines whether this length is equal to specified object
Parameters:
Parameter | Type | Description |
---|---|---|
obj | java.lang.Object | Other instance of Length type, that is boxed to the System.Object or any other abstract type or interface |
Returns: boolean - True if equal, otherwise false
op_Multiply(Length multiplicand, int factor)
public static Length op_Multiply(Length multiplicand, int factor)
Multiplicates the given Length onto the given factor
Parameters:
Parameter | Type | Description |
---|---|---|
multiplicand | Length | Length - multiplicand |
factor | int | Arbitrary integer - factor |
Returns: Length - A new Length - a product of multiplication
op_Equality(Length left, Length right)
public static boolean op_Equality(Length left, Length right)
Checks the equality of the two given lengths.
Parameters:
Parameter | Type | Description |
---|---|---|
left | Length | The left length operand. |
right | Length | The right length operand. |
Returns: boolean - True if both lengths are equal, otherwise false.
op_Inequality(Length left, Length right)
public static boolean op_Inequality(Length left, Length right)
Checks the inequality of the two given lengths.
Parameters:
Parameter | Type | Description |
---|---|---|
left | Length | The left length operand. |
right | Length | The right length operand. |
Returns: boolean - True if both lengths are not equal, otherwise false.
hashCode()
public int hashCode()
Calculates and returns a hash-code of this Length instance by combining hash-codes of the value and unit type
Returns: int - Integer number
deepClone()
public final Length deepClone()
Returns a full copy of this Length instance
Returns: Length - New separate instance of this Length, that is absolutely identical to this one
getUnitFromName(String unitName)
public static int getUnitFromName(String unitName)
Tries to parse specified unit name and return corresponding value of a Unit enum. Returns LengthUnit.Unitless if cannot find appropriate LengthUnit.
Parameters:
Parameter | Type | Description |
---|---|---|
unitName | java.lang.String | String, that represents a unit name |
Returns: int - Value of Unit enum in any case, LengthUnit.Unitless when cannot find appropriate unit
tryParse(String input, Length[] result)
public static boolean tryParse(String input, Length[] result)
Tries to parse a specified string as a Length value, including its numeric value and unit name
Parameters:
Parameter | Type | Description |
---|---|---|
input | java.lang.String | Input string, that should be parsed |
result | Length[] | Output parameter, that contains a result of parsing. If parsing is unsuccessful, contains a default Length value \u2014 a unitless zero. |
Returns: boolean - True if parsing is successful, false if unsuccessful
parse(String input)
public static Length parse(String input)
Parses and returns specified string as a Length value, including its numeric value and unit name, or throws an exception on failure
Parameters:
Parameter | Type | Description |
---|---|---|
input | java.lang.String | Input string, that should be parsed |
Returns: Length - Valid parsed Length instance