org.pfsw.text
Class NaturalNumber

java.lang.Object
  extended by java.lang.Number
      extended by org.pfsw.text.NaturalNumber
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<NaturalNumber>, org.pfsw.bif.conversion.IIntegerRepresentation, org.pfsw.bif.conversion.ILongRepresentation, org.pfsw.bif.text.IStringRepresentation

public class NaturalNumber
extends java.lang.Number
implements java.lang.Comparable<NaturalNumber>, org.pfsw.bif.text.IStringRepresentation, org.pfsw.bif.conversion.ILongRepresentation, org.pfsw.bif.conversion.IIntegerRepresentation

A natural number is an abstraction of the two types Integer and Long. It allows to treat such values in a more neutral way without being fixed on a specific java standard type.

See Also:
Serialized Form

Constructor Summary
NaturalNumber(int value)
           
NaturalNumber(long value)
           
NaturalNumber(java.lang.String value)
          Parses the string argument as a signed decimal long.
 
Method Summary
 java.lang.Integer asInteger()
           
 java.lang.Long asLong()
           
 java.lang.String asString()
           
 int compareTo(NaturalNumber other)
          Compares two NaturalNumber objects numerically.
 double doubleValue()
           
 boolean equals(java.lang.Object obj)
           
 float floatValue()
           
protected  java.lang.Long getNumberValue()
           
 int hashCode()
           
 int intValue()
           
 boolean isNegative()
          Returns true if this number is less than 0.
 boolean isPositive()
          Returns true if this number is greater than 0.
 long longValue()
           
static NaturalNumber parse(java.lang.String value)
          Parses the string argument as a signed decimal long.
 java.lang.String toString()
           
static NaturalNumber valueOf(int value)
           
static NaturalNumber valueOf(long value)
           
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NaturalNumber

public NaturalNumber(long value)

NaturalNumber

public NaturalNumber(int value)

NaturalNumber

public NaturalNumber(java.lang.String value)
Parses the string argument as a signed decimal long. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' (\u002D') to indicate a negative value.

Note that neither the character L ('\u004C') nor l ('\u006C') is permitted to appear at the end of the string as a type indicator, as would be permitted in Java programming language source code.

Parameters:
value - a String containing the long representation to be parsed
Throws:
java.lang.NumberFormatException - if the string does not contain a parsable long.
Method Detail

valueOf

public static NaturalNumber valueOf(long value)

valueOf

public static NaturalNumber valueOf(int value)

parse

public static NaturalNumber parse(java.lang.String value)
Parses the string argument as a signed decimal long. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' (\u002D') to indicate a negative value.

Note that neither the character L ('\u004C') nor l ('\u006C') is permitted to appear at the end of the string as a type indicator, as would be permitted in Java programming language source code.

Parameters:
value - a String containing the long representation to be parsed
Returns:
the long represented by the argument in decimal.
Throws:
java.lang.NumberFormatException - if the string does not contain a parsable long.

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

asString

public java.lang.String asString()
Specified by:
asString in interface org.pfsw.bif.text.IStringRepresentation

asLong

public java.lang.Long asLong()
Specified by:
asLong in interface org.pfsw.bif.conversion.ILongRepresentation

asInteger

public java.lang.Integer asInteger()
Specified by:
asInteger in interface org.pfsw.bif.conversion.IIntegerRepresentation

isPositive

public boolean isPositive()
Returns true if this number is greater than 0.


isNegative

public boolean isNegative()
Returns true if this number is less than 0.


hashCode

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

equals

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

compareTo

public int compareTo(NaturalNumber other)
Compares two NaturalNumber objects numerically.

Specified by:
compareTo in interface java.lang.Comparable<NaturalNumber>
Parameters:
other - the NaturalNumber to be compared.
Returns:
the value 0 if this NaturalNumber is equal to the argument NaturalNumber; a value less than 0 if this NaturalNumber is numerically less than the argument NaturalNumber; and a value greater than 0 if this NaturalNumber is numerically greater than the argument NaturalNumber (signed comparison).

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getNumberValue

protected java.lang.Long getNumberValue()