org.foray.ps
Class PsNumber

java.lang.Object
  extended by org.foray.ps.PsNumber
All Implemented Interfaces:
Cloneable, Comparable<PsNumber>, PsObject, PsObjectSimple
Direct Known Subclasses:
PsInteger, PsReal

public abstract class PsNumber
extends Object
implements PsObjectSimple, Cloneable, Comparable<PsNumber>

Superclass for numeric Postscript data types.

See Also:
PsInteger, PsReal

Constructor Summary
PsNumber(BigDecimal value)
          Constructor.
 
Method Summary
 PsNumber add(PsNumber amount)
          Adds a given amount to the value of this object, returning either this object with its value adjusted, or, if this object is unable to represent the value properly, a new object which can.
abstract  PsNumber clone()
           
 int compareTo(PsNumber object)
           
 PsNumber divide(PsNumber amount)
          Divides this number by a given object, returning either this object with its value adjusted, or, if this object is unable to represent the value properly, a new object which can.
 boolean equals(Object object)
           
 double getDoubleValue()
          Return the value of this numeric item cast as a double.
 float getFloatValue()
          Return the value of this numeric item cast as a float.
 BigDecimal getValue()
          Return the encapsulated value.
protected static boolean isAlphabetic(byte input)
          Tests whether the input byte is alphabetic (A-Z and a-z).
 boolean isComparable(PsObject object)
          Test the comparability of two PSObjects.
protected static boolean isMember(byte[] testSet, byte input)
          Tests whether byte input is a member of set testSet.
protected static boolean isNumeral(byte input)
          Tests whether the input byte is a numeral.
 PsNumber multiply(PsNumber amount)
          Multiplies a given number by this object, returning either this object with its value adjusted, or, if this object is unable to represent the value properly, a new object which can.
 PsNumber negate()
          Returns the negative of this number.
 void round()
          Rounds the value.
 PsNumber subtract(PsNumber amount)
          Subtracts a given amount from the value of this object, returning either this object with its value adjusted, or, if this object is unable to represent the value properly, a new object which can.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.foray.ps.PsObject
duplicate, getTypeName, isComposite, isExecutable
 

Constructor Detail

PsNumber

public PsNumber(BigDecimal value)
Constructor.

Parameters:
value - The encapsulated value for this object.
Method Detail

clone

public abstract PsNumber clone()
Overrides:
clone in class Object

getDoubleValue

public double getDoubleValue()
Return the value of this numeric item cast as a double.

Returns:
The value of this number as a double.

getFloatValue

public float getFloatValue()
Return the value of this numeric item cast as a float.

Returns:
The value of this number as a float.

round

public void round()
Rounds the value.


isNumeral

protected static boolean isNumeral(byte input)
Tests whether the input byte is a numeral.

Parameters:
input - The input byte.
Returns:
True if the input byte represents an ASCII numeral, false otherwise.

isAlphabetic

protected static boolean isAlphabetic(byte input)
Tests whether the input byte is alphabetic (A-Z and a-z).

Parameters:
input - The input byte.
Returns:
True if the input byte represents an character in the range A-Z or a-z, false otherwise.

isMember

protected static boolean isMember(byte[] testSet,
                                  byte input)
Tests whether byte input is a member of set testSet.

Parameters:
testSet - A byte array containing the set to be tested.
input - The byte to be tested.
Returns:
True if input is a member of testSet, otherwise false.

isComparable

public boolean isComparable(PsObject object)
Description copied from interface: PsObject
Test the comparability of two PSObjects. Used in the eq, ne, lt, etc. operators.

Specified by:
isComparable in interface PsObject
Parameters:
object - The object that should be tested for comparability.
Returns:
True if this is comparable to object, false otherwise.

equals

public boolean equals(Object object)
Overrides:
equals in class Object

compareTo

public int compareTo(PsNumber object)
Specified by:
compareTo in interface Comparable<PsNumber>

add

public PsNumber add(PsNumber amount)
Adds a given amount to the value of this object, returning either this object with its value adjusted, or, if this object is unable to represent the value properly, a new object which can.

Parameters:
amount - The amount which should be added to the value of this number.
Returns:
A PSNumber that contains the new value.

subtract

public PsNumber subtract(PsNumber amount)
Subtracts a given amount from the value of this object, returning either this object with its value adjusted, or, if this object is unable to represent the value properly, a new object which can.

Parameters:
amount - The amount which should be subtracted from the value of this number.
Returns:
A PSNumber that contains the new value.

multiply

public PsNumber multiply(PsNumber amount)
Multiplies a given number by this object, returning either this object with its value adjusted, or, if this object is unable to represent the value properly, a new object which can.

Parameters:
amount - The amount which should be multiplied by the value of this number.
Returns:
A PSNumber that contains the new value.

divide

public PsNumber divide(PsNumber amount)
Divides this number by a given object, returning either this object with its value adjusted, or, if this object is unable to represent the value properly, a new object which can.

Parameters:
amount - The amount which should be divided into the value of this number.
Returns:
A PSNumber that contains the new value.

negate

public PsNumber negate()
Returns the negative of this number.

Returns:
The negative of this number.

getValue

public BigDecimal getValue()
Return the encapsulated value.

Returns:
The encapsulated value.


Copyright © 2017. All rights reserved.