|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Number
net.tomp2p.peers.Number160
public final class Number160
This class represents a 160 bit number. This class is preferred over BigInteger as we always have 160bit, and thus, methods can be optimized.
Field Summary | |
---|---|
static int |
BITS
|
static int |
BYTE_ARRAY_SIZE
|
static int |
INT_ARRAY_SIZE
|
static Number160 |
MAX_VALUE
|
static Number160 |
ONE
|
static Number160 |
ZERO
|
Constructor Summary | |
---|---|
Number160()
Create a Key with value 0. |
|
Number160(byte[] val)
Creates a new Key using the byte array. |
|
Number160(byte[] val,
int offset,
int length)
Creates a new Key using the byte array. |
|
Number160(int... val)
Create an instance with an integer array. |
|
Number160(int val)
Creates a Key with the integer value |
|
Number160(long val)
|
|
Number160(Random random)
Creates a new Key with random values in it. |
|
Number160(ShortString shortString)
|
|
Number160(String val)
Create a Key from a string. |
Method Summary | |
---|---|
int |
bitLength()
Calculates the number of bits used to represent this number. |
int |
compareTo(Number160 o)
|
static Number160 |
createHash(int integerValue)
Create a new Number160 from the integer, which fills all the 160bits. |
static Number160 |
createHash(long longValue)
Create a new Number160 from the long, which fills all the 160bit. |
static Number160 |
createHash(String string)
Create a new Number160 using SHA1 on the string. |
double |
doubleValue()
|
boolean |
equals(Object obj)
|
float |
floatValue()
|
int |
hashCode()
|
int |
intValue()
|
boolean |
isZero()
Checks if this number is zero |
long |
longValue()
|
Number160 |
shiftLeft(int nr)
Shift left the 160bit number. |
Number160 |
shiftRight(int nr)
Shift right the 160bit number. |
byte[] |
toByteArray()
Returns a byte array, which is always of size 20. |
int |
toByteArray(byte[] me,
int offset)
Fills the byte array with this number |
int[] |
toIntArray()
Returns a copy of the backing array, which is always of size 5. |
String |
toString()
|
String |
toString(boolean removeLeadingZero)
Shows the content in a human readable manner |
long |
unsignedInt(int pos)
For debugging... |
Number160 |
xor(Number160 key)
Xor operation. |
Methods inherited from class java.lang.Number |
---|
byteValue, shortValue |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int BITS
public static final Number160 MAX_VALUE
public static final int INT_ARRAY_SIZE
public static final int BYTE_ARRAY_SIZE
public static final Number160 ZERO
public static final Number160 ONE
Constructor Detail |
---|
public Number160()
public Number160(ShortString shortString)
public Number160(int... val)
val
- The value to copy to the backing array. Since this class stores 160bit numbers, the array needs to be
of size 5 or smaller.public Number160(String val)
val
- The characters allowed are [0-9a-f], which is in hexadecimalpublic Number160(int val)
val
- integer valuepublic Number160(long val)
public Number160(byte[] val)
val
- public Number160(byte[] val, int offset, int length)
val
- offset
- The offset where to startpublic Number160(Random random)
random
- The object to create pseudo random numbers. For testing and debugging, the seed in the random class
can be set to make the random values repeatable.Method Detail |
---|
public Number160 xor(Number160 key)
key
- The second operand for the xor operation
public Number160 shiftRight(int nr)
nr
- The number of bits to be shifted
public Number160 shiftLeft(int nr)
nr
- The number of bits to be shifted
public int[] toIntArray()
public int toByteArray(byte[] me, int offset)
me
- public byte[] toByteArray()
public String toString(boolean removeLeadingZero)
removeLeadingZero
- Indicates of leading zeros should be removed
public boolean isZero()
public int bitLength()
public String toString()
toString
in class Object
public double doubleValue()
doubleValue
in class Number
public float floatValue()
floatValue
in class Number
public int intValue()
intValue
in class Number
public long unsignedInt(int pos)
pos
-
public long longValue()
longValue
in class Number
public int compareTo(Number160 o)
compareTo
in interface Comparable<Number160>
public boolean equals(Object obj)
equals
in class Object
public int hashCode()
hashCode
in class Object
public static Number160 createHash(int integerValue)
integerValue
- The value to hash from
public static Number160 createHash(long longValue)
longValue
- The value to hash from
public static Number160 createHash(String string)
string
- The value to hash from
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |