org.apache.fop.fo.expr
Class Numeric


public class Numeric

Represents a "numeric" value as defined by the XSL FO Specification. This consists of one or more kinds of value specifications, from absolute numbers (units power of 0) to lengths (unit power of 1), relative lengths (ems), percentage lengths. A Numeric can be constructed from other Property types representing Numbers or Length-type values. Numeric provides methods to return Number and Length values based on its current value. It supports basic arithmetic operations involving Numerics.


Field Summary
 final static intABS_LENGTH
           
 final static intPC_LENGTH
           
 final static intTCOL_LENGTH
           

Constructor Summary
Numeric(Number num)
          Construct a Numeric object from a Number.
Numeric(Length l)
          Construct a Numeric object from a Length.
Numeric(PercentLength pclen)
          Construct a Numeric object from a PercentLength.
Numeric(TableColLength tclen)
          Construct a Numeric object from a TableColLength.

Method Summary
 Numericabs()
          Return the absolute value of this Numeric.
 Numericadd(Numeric op)
          Add the operand from the current value and return a new Numeric representing the result.
 DoubleasDouble()
           
 LengthasLength()
          Return the current value as a Length if possible.
 NumberasNumber()
          Return the current value as a Number if possible.
 Numericdivide(Numeric op)
          Divide the the current value by the operand and return a new Numeric representing the result.
 Numericmax(Numeric op)
          Return a Numeric which is the maximum of the current value and the operand.
 Numericmin(Numeric op)
          Return a Numeric which is the minimum of the current value and the operand.
 Numericmultiply(Numeric op)
          Multiply the the current value by the operand and return a new Numeric representing the result.
 Numericsubtract(Numeric op)
          Subtract the operand from the current value and return a new Numeric representing the result.

Field Detail

ABS_LENGTH

public final static int ABS_LENGTH

PC_LENGTH

public final static int PC_LENGTH

TCOL_LENGTH

public final static int TCOL_LENGTH
Constructor Detail

Numeric

public Numeric(Number num)
Construct a Numeric object from a Number.
Parameters:
num - The number.

Numeric

public Numeric(Length l)
Construct a Numeric object from a Length.
Parameters:
l - The Length.

Numeric

public Numeric(PercentLength pclen)
Construct a Numeric object from a PercentLength.
Parameters:
pclen - The PercentLength.

Numeric

public Numeric(TableColLength tclen)
Construct a Numeric object from a TableColLength.
Parameters:
tclen - The TableColLength.
Method Detail

abs

public Numeric abs()
Return the absolute value of this Numeric.
Returns: A new Numeric object representing the absolute value.

add

public Numeric add(Numeric op)
throws PropertyException
Add the operand from the current value and return a new Numeric representing the result.
Parameters:
op - The value to add.
Returns: A Numeric representing the result.
Throws:
PropertyException - If the dimension of the operand is different from the dimension of this Numeric.

asDouble

public Double asDouble()

asLength

public Length asLength()
Return the current value as a Length if possible. This constructs a new Length or Length subclass based on the current value type of the Numeric. If the stored value has a unit dimension other than 1, null is returned.

asNumber

public Number asNumber()
Return the current value as a Number if possible. Calls asDouble().

divide

public Numeric divide(Numeric op)
throws PropertyException
Divide the the current value by the operand and return a new Numeric representing the result.
Parameters:
op - The divisor.
Returns: A Numeric representing the result.
Throws:
PropertyException - If both Numerics have "mixed" type.

max

public Numeric max(Numeric op)
throws PropertyException
Return a Numeric which is the maximum of the current value and the operand.
Throws:
PropertyException - If the dimensions or value types of the object and the operand are different.

min

public Numeric min(Numeric op)
throws PropertyException
Return a Numeric which is the minimum of the current value and the operand.
Throws:
PropertyException - If the dimensions or value types of the object and the operand are different.

multiply

public Numeric multiply(Numeric op)
throws PropertyException
Multiply the the current value by the operand and return a new Numeric representing the result.
Parameters:
op - The multiplier.
Returns: A Numeric representing the result.
Throws:
PropertyException - If both Numerics have "mixed" type.

subtract

public Numeric subtract(Numeric op)
throws PropertyException
Subtract the operand from the current value and return a new Numeric representing the result.
Parameters:
op - The value to subtract.
Returns: A Numeric representing the result.
Throws:
PropertyException - If the dimension of the operand is different from the dimension of this Numeric.

Association Links

to Class org.apache.fop.datatypes.PercentBase