JADE v6.1

com.dautelle.math.numbers
Class Integer32

java.lang.Object
  extended byjava.lang.Number
      extended bycom.dautelle.math.numbers.RealtimeNumber
          extended bycom.dautelle.math.numbers.Integer32
All Implemented Interfaces:
java.lang.Comparable, Operable, Realtime, Representable, java.io.Serializable

public final class Integer32
extends RealtimeNumber
implements java.lang.Comparable

This class represents a 32 bits signed integer.

This class implements the Operable interface for modular arithmetic (ref. setModulus(com.dautelle.math.numbers.Integer32)).

Version:
5.1, August 27, 2003
Author:
Jean-Marie Dautelle
See Also:
Serialized Form

Nested Class Summary
static class Integer32.Value
          This inner class represents a mutable image of an immutable Integer32.
 
Nested classes inherited from class com.dautelle.math.numbers.RealtimeNumber
RealtimeNumber.Factory
 
Field Summary
static Integer32 MAX_PRIME
          The 32 bits integer representing zero.
static Integer32 ONE
          The 32 bits integer one.
static Integer32 ZERO
          The 32 bits integer representing zero.
 
Method Summary
 Integer32 abs()
          Returns the absolute value of this number.
 Integer32 add(Integer32 that)
          Returns the sum of this number with the one specified.
 java.lang.StringBuffer appendTo(java.lang.StringBuffer sb)
          Appends the decimal text representation of this number to the StringBuffer argument.
 int compareTo(Integer32 that)
          Compares two 32 bits integer numerically.
 int compareTo(java.lang.Object that)
           
 Integer32 divide(Integer32 that)
          Returns this number divided by the one specified.
 double doubleValue()
          Returns the value of this number as a double.
 boolean equals(java.lang.Object that)
          Compares this number against the specified object.
 float floatValue()
          Returns the value of this number as a float.
 int hashCode()
          Returns the hash code for this number.
 int intValue()
          Returns the value of this number as an int.
 long longValue()
          Returns the value of this number as a long.
 Integer32 mod(Integer32 m)
          Returns this number modulo the specified number.
 Integer32 multiply(Integer32 that)
          Returns the product of this number with the one specified.
 Integer32 negate()
          Returns the negation of this number.
 Operable opposite()
          Returns the additive inverse of this object.
 Operable plus(Operable that)
          Returns the sum of this object with the one specified.
 Operable reciprocal()
          Returns the multiplicative inverse of this object.
static void setModulus(Integer32 modulus)
          Sets the context local modulus for modular arithmetic (used by Operable operations only).
 Integer32 subtract(Integer32 that)
          Returns the difference between this number and the one specified.
 Operable times(Operable that)
          Returns the product of this object with the one specified.
 java.lang.String toString()
          Returns the decimal text representation of this number.
 void toXml(XmlElement xml)
          Sets the attributes and content of the XML element corresponding to this object.
static Integer32 valueOf(java.lang.CharSequence chars)
          Returns the 32 bits integer for the specified character sequence.
static Integer32 valueOf(int intValue)
          Returns the 32 bits integer of specified int value.
static Integer32 valueOf(XmlElement xml)
          XML factory method.
 
Methods inherited from class com.dautelle.math.numbers.RealtimeNumber
clone, export, isLocalObject, isPoolObject, pow, recycle, toHeap
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static final Integer32 ZERO
The 32 bits integer representing zero.


ONE

public static final Integer32 ONE
The 32 bits integer one.


MAX_PRIME

public static final Integer32 MAX_PRIME
The 32 bits integer representing zero.

Method Detail

valueOf

public static Integer32 valueOf(int intValue)
Returns the 32 bits integer of specified int value.

Parameters:
intValue - the int value for this 32 bits integer.
Returns:
the corresponding number.
See Also:
intValue()

valueOf

public static Integer32 valueOf(java.lang.CharSequence chars)
Returns the 32 bits integer for the specified character sequence.

Parameters:
chars - the character sequence.
Returns:
the corresponding number.

valueOf

public static Integer32 valueOf(XmlElement xml)
XML factory method.

Parameters:
xml - the XML element describing the 32 bits integer to return (e.g.<math:Integer32 value="0"/>).
Returns:
a new number as described by the specified xml element.

negate

public Integer32 negate()
Returns the negation of this number.

Returns:
-this.

add

public Integer32 add(Integer32 that)
Returns the sum of this number with the one specified.

Parameters:
that - the number to be added.
Returns:
this + that.

subtract

public Integer32 subtract(Integer32 that)
Returns the difference between this number and the one specified.

Parameters:
that - the number to be subtracted.
Returns:
this - that.

multiply

public Integer32 multiply(Integer32 that)
Returns the product of this number with the one specified.

Parameters:
that - the multiplier.
Returns:
this * that.

divide

public Integer32 divide(Integer32 that)
Returns this number divided by the one specified.

Parameters:
that - the divisor.
Returns:
this / that.

mod

public Integer32 mod(Integer32 m)
Returns this number modulo the specified number. This method always returns a positive number.

Parameters:
m - the modulus.
Returns:
this mod m
Throws:
java.lang.ArithmeticException - if !m.isPositive()

abs

public Integer32 abs()
Returns the absolute value of this number.

Returns:
abs(this).

appendTo

public java.lang.StringBuffer appendTo(java.lang.StringBuffer sb)
Appends the decimal text representation of this number to the StringBuffer argument.

Parameters:
sb - the StrinBuffer to append.
Returns:
the specified StrinBuffer.

toString

public java.lang.String toString()
Returns the decimal text representation of this number.

Returns:
the text representation of this number.

equals

public boolean equals(java.lang.Object that)
Compares this number against the specified object.

Parameters:
that - the object to compare with.
Returns:
true if the objects are the same; false otherwise.

hashCode

public int hashCode()
Returns the hash code for this number.

Returns:
the hash code value.

intValue

public int intValue()
Returns the value of this number as an int.

Returns:
the int value.

longValue

public long longValue()
Returns the value of this number as a long.

Returns:
the long value.

floatValue

public float floatValue()
Returns the value of this number as a float.

Returns:
the float value.

doubleValue

public double doubleValue()
Returns the value of this number as a double.

Returns:
the double value.

compareTo

public int compareTo(Integer32 that)
Compares two 32 bits integer numerically.

Parameters:
that - the number to compare with.
Returns:
-1, 0 or 1 as this numberis numerically less than, equal to, or greater than that.

compareTo

public int compareTo(java.lang.Object that)
Specified by:
compareTo in interface java.lang.Comparable

toXml

public void toXml(XmlElement xml)
Description copied from interface: Representable
Sets the attributes and content of the XML element corresponding to this object.

Specified by:
toXml in interface Representable
Parameters:
xml - the XML element to set according to this object's desired XML representation.

setModulus

public static void setModulus(Integer32 modulus)
Sets the context local modulus for modular arithmetic (used by Operable operations only). If the modulus is not set the reciprocal() operation raises IllegalStateException.

Parameters:
modulus - the new modulus or null to unset the modulus.
Throws:
java.lang.IllegalArgumentException - if modulus <= 0
See Also:
LocalContext, plus, opposite, times, reciprocal

plus

public Operable plus(Operable that)
Description copied from interface: Operable
Returns the sum of this object with the one specified.

Specified by:
plus in interface Operable
Parameters:
that - the object to be added.
Returns:
this + that.

opposite

public Operable opposite()
Description copied from interface: Operable
Returns the additive inverse of this object. It is the object such as this.plus(this.opposite()) == ZERO, with ZERO being the additive identity.

Specified by:
opposite in interface Operable
Returns:
-this.

times

public Operable times(Operable that)
Description copied from interface: Operable
Returns the product of this object with the one specified.

Specified by:
times in interface Operable
Parameters:
that - the object multiplier.
Returns:
this * that.

reciprocal

public Operable reciprocal()
Description copied from interface: Operable
Returns the multiplicative inverse of this object. It it the object such as this.times(this.reciprocal()) == ONE , with ONE being the multiplicative identity.

Specified by:
reciprocal in interface Operable
Returns:
ONE / this.

JADE v6.1

Copyright © 2004 Jean-Marie Dautelle.