org.openanzo.glitter.util
Class PolymorphicNumber

java.lang.Object
  extended by java.lang.Number
      extended by org.openanzo.glitter.util.PolymorphicNumber
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<PolymorphicNumber>

public final class PolymorphicNumber
extends java.lang.Number
implements java.lang.Comparable<PolymorphicNumber>

A PolymorphicNumber handles math operations on numeric types that may require type promotion and coercion.

Author:
lee
See Also:
Serialized Form

Field Summary
static PolymorphicNumber ZERO
          Constant 0.
 
Constructor Summary
PolymorphicNumber(java.lang.Number n)
          Create a PolymorphicNumber from a Java Number.
PolymorphicNumber(TriplePatternComponent tpc)
          Create a PolymorphicNumber from the numeric value of a Glitter term.
 
Method Summary
 PolymorphicNumber add(PolymorphicNumber other)
          Polymorphic addition.
 TypedLiteral asTypedLiteral()
          Get the value of this number in its narrowest form wrapped as a TypedLiteral
 java.math.BigDecimal bigDecimalValue()
           
 java.math.BigInteger bigIntegerValue()
           
 int compareTo(PolymorphicNumber other)
           
 PolymorphicNumber divide(PolymorphicNumber other)
          Polymorphic division.
 double doubleValue()
           
 boolean equals(java.lang.Object o)
           
 float floatValue()
           
 int hashCode()
           
 int intValue()
           
 long longValue()
           
 PolymorphicNumber mod(PolymorphicNumber other)
          Polymorphic remainder operator..
 PolymorphicNumber multiply(PolymorphicNumber other)
          Polymorphic multiplication.
 java.lang.Number narrowestValue()
          Get the value of this number in narrowest (most specific) representation for its type.
 PolymorphicNumber negate()
          Polymorphic numeric negation.
 PolymorphicNumber subtract(PolymorphicNumber other)
          Polymorphic subtraction.
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZERO

public static PolymorphicNumber ZERO
Constant 0.

Constructor Detail

PolymorphicNumber

public PolymorphicNumber(java.lang.Number n)
Create a PolymorphicNumber from a Java Number.

Parameters:
n - Number to create from

PolymorphicNumber

public PolymorphicNumber(TriplePatternComponent tpc)
Create a PolymorphicNumber from the numeric value of a Glitter term.

Parameters:
tpc - TriplePatternComponent to create from
Method Detail

narrowestValue

public java.lang.Number narrowestValue()
Get the value of this number in narrowest (most specific) representation for its type.

Returns:
The value of this number in narrowest (most specific) representation for its type.

asTypedLiteral

public TypedLiteral asTypedLiteral()
Get the value of this number in its narrowest form wrapped as a TypedLiteral

Returns:
The value of this number in its narrowest form wrapped as a TypedLiteral.

add

public PolymorphicNumber add(PolymorphicNumber other)
Polymorphic addition.

Parameters:
other - PolymorphicNumber to add to this PolymorphicNumber
Returns:
PolymorphicNumber that is the product of adding this PolymorphicNumber and the other PolymorphicNumber

subtract

public PolymorphicNumber subtract(PolymorphicNumber other)
Polymorphic subtraction.

Parameters:
other - PolymorphicNumber to subtract from this PolymorphicNumber
Returns:
PolymorphicNumber that is the product of subtracting this PolymorphicNumber and the other PolymorphicNumber

multiply

public PolymorphicNumber multiply(PolymorphicNumber other)
Polymorphic multiplication.

Parameters:
other - PolymorphicNumber to multiply with this PolymorphicNumber
Returns:
PolymorphicNumber that is the product of multiplying this PolymorphicNumber and the other PolymorphicNumber

divide

public PolymorphicNumber divide(PolymorphicNumber other)
Polymorphic division.

Parameters:
other - PolymorphicNumber to divide from this PolymorphicNumber
Returns:
PolymorphicNumber that is the product of dividing this PolymorphicNumber and the other PolymorphicNumber

mod

public PolymorphicNumber mod(PolymorphicNumber other)
Polymorphic remainder operator..

Parameters:
other - PolymorphicNumber to mod from this PolymorphicNumber
Returns:
PolymorphicNumber that is the product of mod this PolymorphicNumber and the other PolymorphicNumber

negate

public PolymorphicNumber negate()
Polymorphic numeric negation.

Returns:
PolymorphicNumber that is the negation of this PolymorphicNumber

compareTo

public int compareTo(PolymorphicNumber other)
Specified by:
compareTo in interface java.lang.Comparable<PolymorphicNumber>

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

bigIntegerValue

public java.math.BigInteger bigIntegerValue()
Returns:
A representation of this number as a BigInteger

bigDecimalValue

public java.math.BigDecimal bigDecimalValue()
Returns:
A representation of this number as a BigDecimal.

doubleValue

public double doubleValue()
Specified by:
doubleValue in class java.lang.Number

floatValue

public float floatValue()
Specified by:
floatValue in class java.lang.Number

intValue

public int intValue()
Specified by:
intValue in class java.lang.Number

longValue

public long longValue()
Specified by:
longValue in class java.lang.Number


Copyright © 2007 Cambridge Semantics Inc.. All Rights Reserved.