JSci.maths
Class MathInteger

java.lang.Object
  extended by JSci.maths.MathInteger
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable, Ring.Member, AbelianGroup.Member, Member

public final class MathInteger
extends java.lang.Object
implements java.lang.Comparable, Ring.Member

The MathInteger class encapsulates integer numbers.

Version:
1.0
Author:
Mark Hale
See Also:
IntegerRing, Serialized Form

Constructor Summary
MathInteger(int num)
          Constructs an integer number.
MathInteger(java.lang.String s)
          Constructs the integer number represented by a string.
 
Method Summary
 AbelianGroup.Member add(AbelianGroup.Member n)
          Returns the addition of this number and another.
 MathInteger add(MathInteger n)
          Returns the addition of this integer number and another.
 int compareTo(java.lang.Object obj)
          Compares two integer numbers.
 boolean equals(java.lang.Object obj)
          Compares two integer numbers for equality.
 boolean isEven()
          Returns true if this number is even.
 boolean isOdd()
          Returns true if this number is odd.
 MathInteger multiply(MathInteger n)
          Returns the multiplication of this integer number and another.
 Ring.Member multiply(Ring.Member n)
          Returns the multiplication of this number and another.
 AbelianGroup.Member negate()
          Returns the negative of this number.
 MathInteger pow(MathInteger n)
          Returns this integer number raised to the power of another.
 AbelianGroup.Member subtract(AbelianGroup.Member n)
          Returns the subtraction of this number and another.
 MathInteger subtract(MathInteger n)
          Returns the subtraction of this integer number and another.
 java.lang.String toString()
          Returns a string representing the value of this integer number.
 int value()
          Returns the integer value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MathInteger

public MathInteger(int num)
Constructs an integer number.


MathInteger

public MathInteger(java.lang.String s)
            throws java.lang.NumberFormatException
Constructs the integer number represented by a string.

Parameters:
s - a string representing an integer number.
Throws:
java.lang.NumberFormatException - if the string does not contain a parsable number.
Method Detail

equals

public boolean equals(java.lang.Object obj)
Compares two integer numbers for equality.

Overrides:
equals in class java.lang.Object
Parameters:
obj - an integer number.

compareTo

public int compareTo(java.lang.Object obj)
              throws java.lang.IllegalArgumentException
Compares two integer numbers.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
obj - an integer number.
Returns:
a negative value if this<obj, zero if this==obj, and a positive value if this>obj.
Throws:
java.lang.IllegalArgumentException

toString

public java.lang.String toString()
Returns a string representing the value of this integer number.

Overrides:
toString in class java.lang.Object

value

public int value()
Returns the integer value.


isEven

public boolean isEven()
Returns true if this number is even.


isOdd

public boolean isOdd()
Returns true if this number is odd.


negate

public AbelianGroup.Member negate()
Returns the negative of this number.

Specified by:
negate in interface AbelianGroup.Member

add

public AbelianGroup.Member add(AbelianGroup.Member n)
Returns the addition of this number and another.

Specified by:
add in interface AbelianGroup.Member
Parameters:
n - a group member

add

public MathInteger add(MathInteger n)
Returns the addition of this integer number and another.


subtract

public AbelianGroup.Member subtract(AbelianGroup.Member n)
Returns the subtraction of this number and another.

Specified by:
subtract in interface AbelianGroup.Member
Parameters:
n - a group member

subtract

public MathInteger subtract(MathInteger n)
Returns the subtraction of this integer number and another.

Parameters:
n - an integer number.

multiply

public Ring.Member multiply(Ring.Member n)
Returns the multiplication of this number and another.

Specified by:
multiply in interface Ring.Member
Parameters:
n - a ring member

multiply

public MathInteger multiply(MathInteger n)
Returns the multiplication of this integer number and another.

Parameters:
n - an integer number.

pow

public MathInteger pow(MathInteger n)
Returns this integer number raised to the power of another.

Parameters:
n - an integer number.