Package com.pdftools.geometry.units
Class Length
java.lang.Object
com.pdftools.geometry.units.Length
- All Implemented Interfaces:
Comparable<Length>
Class that represents a measurable length. Provides conversion between units, parsing of string representations of lengths, and basic mathematical operations.
The unit used in PDF documents is
, which is also used internally by the invalid reference
Units.POINTLength object to store length values.
For that reason, when converting units to and from the internally used unit, minor numerical differences may occur due to floating-point arithmetic.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionLength(double value, Length.Units unit) Constructs a newly allocatedLengthobject using the specified value and unit. -
Method Summary
Modifier and TypeMethodDescriptionstatic Lengthintdivide(double divisor) doublebooleaninthashCode()static Lengthstatic Lengthmultiply(double multiplicand) static LengthCreates aLengthobject by parsing a String representation of a length with its unit.static Length[]parseArray(String value) Creates an array ofLengthby parsing a String representation of lengths with units.static Length[]parseArray(String value, int size) Creates an array ofLengthby parsing a String representation of lengths with units.doubleto(Length.Units unit) Get the numerical length value of the specified unit.toString()Creates a string representation with an associated suitable metric unit, "m", "cm" or "mm".toString(Length.Units unit) Creates a string representation with the specified unit.
-
Field Details
-
ZERO
-
MAX_VALUE
-
-
Constructor Details
-
Length
Constructs a newly allocatedLengthobject using the specified value and unit.- Parameters:
value- the numerical value.unit- the unit.
-
-
Method Details
-
to
Get the numerical length value of the specified unit.- Parameters:
unit- the unit.- Returns:
-
parse
Creates aLengthobject by parsing a String representation of a length with its unit.- Parameters:
value- Value-unit pair of the form "<value><unit>". Examples: "12.3cm" or "23.9mm". Allowed units are "um", "mm", "cm", "m", "km", "pt", and "in".- Throws:
IllegalArgumentException- if unit given invalueis invalid.
-
toString
Creates a string representation with an associated suitable metric unit, "m", "cm" or "mm". -
toString
Creates a string representation with the specified unit. -
parseArray
Creates an array ofLengthby parsing a String representation of lengths with units.- Parameters:
value- A group of value-unit pairs of the form "<value1><unit1> <value2><unit2>...". Example: "12.3cm 23.9mm 0.25in" etc. Allowed units are "um", "mm", "cm", "m", "km", "pt" and "in".size- Number of value-unit pairs represented by thevalueparameter.- Throws:
IllegalArgumentException- if parametersizedoesn't fit the number of values invalue.IllegalArgumentException- if a unit is invalid.
-
parseArray
Creates an array ofLengthby parsing a String representation of lengths with units.- Parameters:
value- A group of value-unit pairs of the form "<value1><unit1> <value2><unit2>...". Example: "12.3cm 23.9mm 0.25in" etc. Allowed units are "um", "mm", "cm", "m", "km", "pt" and "in".- Throws:
IllegalArgumentException- if a unit is invalid.
-
add
-
subtract
-
multiply
-
divide
-
divide
-
min
-
max
-
abs
-
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareToin interfaceComparable<Length>
-