java.lang.Comparable<Length>
public class Length extends java.lang.Object implements java.lang.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 Units.POINT
, which is also used internally by the Length
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.
Modifier and Type | Class | Description |
---|---|---|
static class |
Length.Units |
Constructor | Description |
---|---|
Length(double value,
Length.Units unit) |
Constructs a newly allocated
Length object using the specified value and unit. |
Modifier and Type | Method | Description |
---|---|---|
static Length |
abs(Length length) |
|
Length |
add(Length addend) |
|
int |
compareTo(Length o) |
|
Length |
divide(double divisor) |
|
double |
divide(Length divisor) |
|
boolean |
equals(java.lang.Object obj) |
|
int |
hashCode() |
|
static Length |
max(Length lhs,
Length rhs) |
|
static Length |
min(Length lhs,
Length rhs) |
|
Length |
multiply(double multiplicand) |
|
static Length |
parse(java.lang.String value) |
Creates a
Length object by parsing a String representation of a length with its unit. |
static Length[] |
parseArray(java.lang.String value) |
Creates an array of
Length by parsing a String representation of lengths with units. |
static Length[] |
parseArray(java.lang.String value,
int size) |
Creates an array of
Length by parsing a String representation of lengths with units. |
Length |
subtract(Length subtrahend) |
|
double |
to(Length.Units unit) |
Get the numerical length value of the specified unit.
|
java.lang.String |
toString() |
Creates a string representation with an associated suitable metric unit, "m", "cm" or "mm".
|
java.lang.String |
toString(Length.Units unit) |
Creates a string representation with the specified unit.
|
public Length(double value, Length.Units unit)
Length
object using the specified value and unit.value
- the numerical value.unit
- the unit.public double to(Length.Units unit)
unit
- the unit.public static Length parse(java.lang.String value)
Length
object by parsing a String representation of a length with its unit.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".java.lang.IllegalArgumentException
- if unit given in value
is invalid.public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(Length.Units unit)
public static Length[] parseArray(java.lang.String value, int size)
Length
by parsing a String representation of lengths with units.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 the value
parameter.java.lang.IllegalArgumentException
- if parameter size
doesn't fit the number of values in value
.java.lang.IllegalArgumentException
- if a unit is invalid.public static Length[] parseArray(java.lang.String value)
Length
by parsing a String representation of lengths with units.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".java.lang.IllegalArgumentException
- if a unit is invalid.public Length multiply(double multiplicand)
public Length divide(double divisor)
public double divide(Length divisor)
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object