public class Length extends Object implements com.groupdocs.editor.htmlcss.css.datatypes.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:
Modifier and Type | Class and Description |
---|---|
static class |
Length.Unit
All supported length units
|
Modifier and Type | Field and Description |
---|---|
static Length |
FiftyPercents
50%
|
static Length |
OneHundredPercents
100%
|
static Length |
UnitlessZero
Unitless integer zero - default value, the same as default parameterless
constructor
|
static Length |
ZeroPercents
0%
|
Constructor and Description |
---|
Length() |
Modifier and Type | Method and Description |
---|---|
Length |
deepClone()
Returns a full copy of this Length instance
|
boolean |
equals(Length other)
Defines whether this value is equal to the other specified length
|
boolean |
equals(Object obj)
Determines whether this length is equal to specified object
|
static Length |
fromValueWithUnit(double value,
byte unit)
Creates and returns an instance of Length type by specified double number
and unit
|
static Length |
fromValueWithUnit(float value,
byte unit)
Creates and returns an instance of Length type by specified float number
and unit
|
static Length |
fromValueWithUnit(int value,
byte unit)
Creates and returns an instance of Length type by specified integer
number and unit
|
float |
getFloatValue()
Returns a float numeric value of the Length instance.
|
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.
|
static byte |
getUnitFromName(String unitName)
Tries to parse specified unit name and return corresponding value of a
Unit enum.
|
byte |
getUnitType()
Returns a unit type of this Length instance.
|
int |
hashCode()
Calculates and returns a hash-code of this Length instance by combining
hash-codes of the value and unit type
|
boolean |
isAbsolute()
Gets if the length is given in absolute units.
|
boolean |
isDefault()
Indicates whether this Length instance has a default value — unitless
zero.
|
boolean |
isFloat()
Indicates whether the numeric value of this Length instance was
originally specified and stored as a float (FP32) number
|
boolean |
isInteger()
Indicates whether the numeric value of this Length instance was
originally specified and stored as an integer (INT32) number
|
boolean |
isNegative()
Determines whether the numeric value of this length is a negative number
|
boolean |
isPositive()
Determines whether the numeric value of this length is a positive number
|
boolean |
isRelative()
Gets if the length is given in relative units.
|
boolean |
isUnitlessNonZero()
The value has unitless type, but is not a zero - positive or negative
number
|
boolean |
isUnitlessZero()
Determines whether this instance is a unitless zero or not.
|
boolean |
isZero()
Determines whether the numeric value of this length is a zero number
|
static boolean |
op_Equality(Length left,
Length right)
Checks the equality of the two given lengths.
|
static boolean |
op_Inequality(Length left,
Length right)
Checks the inequality of the two given lengths.
|
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
|
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
|
float |
to(byte unit)
Converts the length to the given unit, if possible.
|
float |
toPixel()
Converts the length to a number of pixels, if possible.
|
String |
toStringSpecified(byte unit)
Returns a string representation of this length in specified unit type.
|
static boolean |
tryParse(String input,
Length[] result)
Tries to parse a specified string as a Length value, including its
numeric value and unit name
|
public static final Length FiftyPercents
50%
public static final Length OneHundredPercents
100%
public static final Length UnitlessZero
Unitless integer zero - default value, the same as default parameterless constructor
public static final Length ZeroPercents
0%
public final Length deepClone()
Returns a full copy of this Length instance
public final boolean equals(Length other)
Defines whether this value is equal to the other specified length
other
- Other instance of Length typepublic boolean equals(Object obj)
Determines whether this length is equal to specified object
equals
in interface com.aspose.ms.System.IEquatable<com.groupdocs.editor.htmlcss.css.datatypes.ICssDataType>
equals
in class Object
obj
- Other instance of Length type, that is boxed to the
System.Object or any other abstract type or interfacepublic static Length fromValueWithUnit(double value, byte unit)
Creates and returns an instance of Length type by specified double number and unit
value
- Any double (FP64) number, that will be converted to float
(FP32)unit
- Any valid unit typepublic static Length fromValueWithUnit(float value, byte unit)
Creates and returns an instance of Length type by specified float number and unit
value
- >Any float (FP32) numberunit
- Any valid unit typepublic static Length fromValueWithUnit(int value, byte unit)
Creates and returns an instance of Length type by specified integer number and unit
value
- Any integer numberunit
- Any valid unit typepublic final float getFloatValue()
Returns a float numeric value of the Length instance. Never throws an exception - converts Integer value to Float if necessary.
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.
com.aspose.ms.System.InvalidOperationException
public static byte getUnitFromName(String unitName)
Tries to parse specified unit name and return corresponding value of a Unit enum. Returns Unit.Unitless if cannot find appropriate unit.
unitName
- String, that represents a unit namepublic final byte getUnitType()
Returns a unit type of this Length instance.
public int hashCode()
Calculates and returns a hash-code of this Length instance by combining hash-codes of the value and unit type
public final boolean isAbsolute()
Gets if the length is given in absolute units. Such a length may be converted to pixels.
public final boolean isDefault()
Indicates whether this Length instance has a default value — unitless zero. Same as IsUnitlessZero property.
isDefault
in interface com.groupdocs.editor.htmlcss.css.datatypes.ICssDataType
public final boolean isFloat()
Indicates whether the numeric value of this Length instance was originally specified and stored as a float (FP32) number
public final boolean isInteger()
Indicates whether the numeric value of this Length instance was originally specified and stored as an integer (INT32) number
public final boolean isNegative()
Determines whether the numeric value of this length is a negative number
public final boolean isPositive()
Determines whether the numeric value of this length is a positive number
public final boolean isRelative()
Gets if the length is given in relative units. Such a length cannot be converted to pixels.
public final boolean isUnitlessNonZero()
The value has unitless type, but is not a zero - positive or negative number
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.
public final boolean isZero()
Determines whether the numeric value of this length is a zero number
public static boolean op_Equality(Length left, Length right)
Checks the equality of the two given lengths.
left
- The left length operand.right
- The right length operand.public static boolean op_Inequality(Length left, Length right)
Checks the inequality of the two given lengths.
left
- The left length operand.right
- The right length operand.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
input
- Input string, that should be parsedIllegalArgumentException
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
serializeDefault
in interface com.groupdocs.editor.htmlcss.css.datatypes.ICssDataType
public final float to(byte unit)
Converts the length to the given unit, if possible. If the current or given unit is relative, then an exception will be thrown.
unit
- The unit to convert to.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.
public final String toStringSpecified(byte unit)
Returns a string representation of this length in specified unit type. Numeric value will be converted in corresponding to unit type change.
unit
- Specified unit, to which this instance should be converted
before serializing to the string. Should be valid. Cannot be unitless.IllegalArgumentException
- Value is not definedcom.aspose.ms.System.ArgumentOutOfRangeException
- Unitless value is prohibitedpublic static boolean tryParse(String input, Length[] result)
Tries to parse a specified string as a Length value, including its numeric value and unit name
input
- Input string, that should be parsedresult
- Output parameter, that contains a result of parsing. If
parsing is unsuccessful, contains a default Length value — a unitless
zero.