org.jopendocument.dom
Class Length

java.lang.Object
  extended by org.jopendocument.dom.Length
All Implemented Interfaces:
Comparable<Length>

@Immutable
public class Length
extends Object
implements Comparable<Length>

An OpenDocument length.

Note: for performance reason, this class has a natural ordering that is inconsistent with equals(Object).

Author:
Sylvain

Field Summary
static Length ZERO
          The empty length.
 
Constructor Summary
Length(Number amount, LengthUnit unit)
           
 
Method Summary
 Length add(Length other)
           
static Length CM(Number amount)
           
static Length CM(String amount)
           
 int compareTo(Length o)
          Compare two lengths.
 Length convertTo(LengthUnit destUnit)
          Convert this into an instance with the same length but with the passed unit.
 Length convertToDecimal()
           
static Length create(Number amount, LengthUnit unit)
           
static Length create(String amount, LengthUnit unit)
           
 Number divide(Length other)
           
 Number divide(Length other, MathContext mc)
           
 boolean equals(Object obj)
          Indicates whether some other object has the exact same amount and unit as this.
 String format()
          Format this length.
 String format(LengthUnit unit)
          Optionally convert and then format this.
 Number getAmount()
           
 BigDecimal getDecimalAmount()
           
static Length getNone()
          The lack of length, e.g. sheets in spreadsheets have no length of their own.
static MathContext getPreciseContext()
          The default context, always more accurate than getStandardContext().
static MathContext getStandardContext()
          The context used in roundDecimalAmount().
 LengthUnit getUnit()
          The unit.
 int hashCode()
           
static Length INCH(Number amount)
           
 boolean isDefined()
           
 boolean isNone()
           
 boolean isZero()
          Whether this is an empty length.
static Length MM(Number amount)
           
static Length MM(String amount)
           
 Length multiply(Number m)
           
 Length negate()
           
 Length roundDecimalAmount()
           
 Length roundDecimalAmount(MathContext mc)
           
 int signum()
           
 Length subtract(Length other)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static final Length ZERO
The empty length.

Constructor Detail

Length

public Length(Number amount,
              LengthUnit unit)
Method Detail

getNone

public static final Length getNone()
The lack of length, e.g. sheets in spreadsheets have no length of their own.

Returns:
the nothing length, not null.
See Also:
isNone()

getStandardContext

public static final MathContext getStandardContext()
The context used in roundDecimalAmount().

Returns:
the standard context.
See Also:
getPreciseContext()

getPreciseContext

public static final MathContext getPreciseContext()
The default context, always more accurate than getStandardContext().

Returns:
the default context.

create

public static final Length create(String amount,
                                  LengthUnit unit)

create

public static final Length create(Number amount,
                                  LengthUnit unit)

MM

public static final Length MM(Number amount)

MM

public static final Length MM(String amount)

CM

public static final Length CM(Number amount)

CM

public static final Length CM(String amount)

INCH

public static final Length INCH(Number amount)

isNone

public final boolean isNone()

isDefined

public final boolean isDefined()

isZero

public final boolean isZero()
Whether this is an empty length.

Returns:
true if the amount is 0.
See Also:
ZERO

getAmount

public final Number getAmount()

getDecimalAmount

public final BigDecimal getDecimalAmount()

getUnit

public final LengthUnit getUnit()
The unit.

Returns:
the unit, null if and only if this is getNone().

convertToDecimal

public final Length convertToDecimal()

convertTo

public final Length convertTo(LengthUnit destUnit)
Convert this into an instance with the same length but with the passed unit.

Parameters:
destUnit - the unit of the result.
Returns:
the same length in another unit.

format

public final String format(LengthUnit unit)
Optionally convert and then format this.

Parameters:
unit - the unit to format to, null meaning don't convert.
Returns:
the string value.
See Also:
format()

format

public final String format()
Format this length.

Returns:
the string value, null if and only if this is getNone().

roundDecimalAmount

public final Length roundDecimalAmount()

roundDecimalAmount

public final Length roundDecimalAmount(MathContext mc)

add

public final Length add(Length other)

subtract

public final Length subtract(Length other)

negate

public final Length negate()

multiply

public final Length multiply(Number m)

divide

public final Number divide(Length other)

divide

public final Number divide(Length other,
                           MathContext mc)

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Indicates whether some other object has the exact same amount and unit as this. If you want to compare the value use compareTo(Length). E.g. CM((float)0) is not equal to CM(0) and MM(0) is not CM(0).

Overrides:
equals in class Object
Parameters:
obj - another length.
Returns:
true if obj is equal to this.

signum

public final int signum()

compareTo

public int compareTo(Length o)
              throws IllegalArgumentException
Compare two lengths.

Specified by:
compareTo in interface Comparable<Length>
Parameters:
o - the other length.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Throws:
IllegalArgumentException - if this or o isNone().

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2010 jOpenDocument All Rights Reserved.