public class NaturalNumber extends java.lang.Number implements java.lang.Comparable<NaturalNumber>, IStringRepresentation, ILongRepresentation, IIntegerRepresentation
Integer
and Long
.
It allows to treat such values in a more neutral way without being fixed on a specific
java standard type.Constructor and Description |
---|
NaturalNumber(int value) |
NaturalNumber(long value) |
NaturalNumber(java.lang.String value)
Parses the string argument as a signed decimal
long . |
Modifier and Type | Method and Description |
---|---|
java.lang.Integer |
asInteger()
Returns the integer representation of the implementing object.
|
java.lang.Long |
asLong()
Returns the long representation of the implementing object.
|
java.lang.String |
asString()
Returns the string representation of the implementing object.
|
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) |
public NaturalNumber(long value)
public NaturalNumber(int value)
public NaturalNumber(java.lang.String value)
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.
value
- a String
containing the long
representation to be parsedjava.lang.NumberFormatException
- if the string does not contain a
parsable long
.public static NaturalNumber valueOf(long value)
public static NaturalNumber valueOf(int value)
public static NaturalNumber parse(java.lang.String value)
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.
value
- a String
containing the long
representation to be parsedlong
represented by the argument in
decimal.java.lang.NumberFormatException
- if the string does not contain a
parsable long
.public double doubleValue()
doubleValue
in class java.lang.Number
public float floatValue()
floatValue
in class java.lang.Number
public int intValue()
intValue
in class java.lang.Number
public long longValue()
longValue
in class java.lang.Number
public java.lang.String asString()
IStringRepresentation
asString
in interface IStringRepresentation
public java.lang.Long asLong()
ILongRepresentation
asLong
in interface ILongRepresentation
public java.lang.Integer asInteger()
IIntegerRepresentation
asInteger
in interface IIntegerRepresentation
public boolean isPositive()
public boolean isNegative()
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int compareTo(NaturalNumber other)
NaturalNumber
objects numerically.compareTo
in interface java.lang.Comparable<NaturalNumber>
other
- the NaturalNumber
to be compared.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).public java.lang.String toString()
toString
in class java.lang.Object
protected java.lang.Long getNumberValue()