|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectplanet.commonapi.Id
planet.chord.ChordId
public class ChordId
Spedific Chord Id implementation.
Field Summary | |
---|---|
protected static int |
bitsKey
Sets the number of bits used in last building of MAX. |
protected static Id |
MAX
Maximum value for the ChordId implementation. |
protected static int |
MAX_ARRAY_SIZE
Chord specific constant: Maximum size of array that contains entire identification. |
static int |
MAX_BITS
Chord specific constant: Maximum number of bits for any Id. |
static int |
MIN_BITS
Chord specific constant: Number of bits saved at any array position. |
protected static int |
MODULE
Chord specific constant: Each array position contains a maximum representation of MODULE bits. |
static int[] |
ONE_CHORD
Chord specific constant: The value of one (1) of internal value of Id. |
static int[] |
TWO_CHORD
Chord specific constant: The value of two (2) of internal value of Id. |
Constructor Summary | |
---|---|
ChordId()
Generates an Id initialized to zero. |
|
ChordId(java.math.BigInteger value)
This constructor translate the BigInteger value to the correct Id. |
|
ChordId(byte[] data)
Generates an Id from data in byte array format. |
|
ChordId(double data)
This constructor is nonapplicable to the Chord overlay. |
|
ChordId(int data)
This constructor is nonapplicable to the Chord overlay. |
|
ChordId(int[] data)
Generates an Id from data in int array format. |
|
ChordId(java.util.Random random)
Build a new ChordId based with the random number generator random. |
|
ChordId(java.lang.String material)
This constructor generate a BigInteger with the number inside of material, and then, translate it to the correct Id. |
|
ChordId(java.lang.String sid,
java.lang.String algorithm)
Builds a new Id from an arbitray string applying a one-way hashing algorithm such as SHA or MD5. |
Method Summary | |
---|---|
Id |
add(Id offset)
Returns an Id corresponding to this Id plus a given offset |
boolean |
between(Id ccw,
Id cw)
Checks if this Id is between two given ids ccw (inclusive) and cw (exclusive) on the circle |
void |
blit(byte[] target)
|
boolean |
clockwise(Id nid)
Checks to see if the Id nid is clockwise or counterclockwise from this, on the ring. |
int |
compareTo(java.lang.Object obj)
Comparison operator for Ids. |
byte[] |
copy()
|
static Id |
divide(long numberOfNodes)
Divides the maximum domain of the node Id in numberOfNodes, to offers the offset between two consecutive nodes. |
Id |
divideOn(long divisor)
This method returns the arithmetical result of this division: thisId/divisor |
boolean |
equals(java.lang.Object obj)
|
int |
getDigit(int i,
int b)
Gets the ith digit in base 2^b. i = 0 is the least significant digit. |
static Id |
getMaximum()
This method returns the maximum value for a ChordId that is possible to build, according the number of bits for key actually in use. |
java.lang.Object |
getValue()
Return the int[] with the value of this Id. |
int |
hashCode()
Hash codes for Ids. |
protected void |
parseBigInteger(java.math.BigInteger value)
Translate the BigInteger value to an Id, partitioning it to fragments of 32 bits. |
void |
setValue(java.lang.Object newValue)
Sets the new value with the int[] that appears at newValue. |
Id |
shift(int cnt,
int fill)
Shift operator. shift(-1,0) multiplies value of this by two, shift(1,0) divides by 2 |
Id |
shift(int cnt,
int fill,
boolean roundUp)
Shift operator. shift(-1,0) multiplies value of this by two, shift(1,0) divides by 2 |
Id |
subtract(Id offset)
Returns an Id corresponding to this Id minus a given distance |
Id |
subtractWithCarry(Id offset)
|
byte[] |
toByteArray()
Returns the byte array representation of this Id |
java.lang.String |
toString()
Returns a string representation of the Id in base 16. |
java.lang.String |
toStringFull()
Returns a string representing the full length of this Id. |
java.lang.String |
toStringHexFull()
Returns the complete represntation of this Id, in hex. |
Methods inherited from class planet.commonapi.Id |
---|
betweenE, Ebetween, setValue |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int MAX_BITS
public static final int MIN_BITS
public static final int[] ONE_CHORD
public static final int[] TWO_CHORD
protected static final int MODULE
protected static final int MAX_ARRAY_SIZE
protected static int bitsKey
protected static Id MAX
Constructor Detail |
---|
public ChordId()
public ChordId(int data) throws InitializationException
data
- int value
InitializationException
- always that this constructor
is used.public ChordId(double data) throws InitializationException
data
- double value
InitializationException
- always that this constructor
is used.public ChordId(byte[] data)
data
- The array with the desired values of the new Id.public ChordId(int[] data)
data
- The array with the desired values of the new Id.public ChordId(java.lang.String material)
material
- String representation of any desired Id.public ChordId(java.math.BigInteger value)
value
- BigInteger representation of the
any desired Id.public ChordId(java.lang.String sid, java.lang.String algorithm) throws InitializationException
sid
- An arbitray string.algorithm
- one-way hashing algorithm such as "SHA" or "MD5".
InitializationException
public ChordId(java.util.Random random) throws InitializationException
random
- A java.util.Random instance to build a ChordId with a random internal value.
InitializationException
- if any error occurs during the initialization.Method Detail |
---|
protected void parseBigInteger(java.math.BigInteger value)
public Id add(Id offset)
add
in class Id
offset
- the offset to add
public Id subtractWithCarry(Id offset)
public Id subtract(Id offset)
Id
subtract
in class Id
offset
- the distance to subtract
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public void blit(byte[] target)
public byte[] copy()
public int compareTo(java.lang.Object obj)
compareTo
in interface java.lang.Comparable
obj
- the Id to compare with.
public byte[] toByteArray()
toByteArray
in class Id
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toStringHexFull()
public java.lang.String toStringFull()
Id
toStringFull
in class Id
public java.lang.String toString()
toString
in class java.lang.Object
public int getDigit(int i, int b)
i
- which digit to get.b
- which power of 2 is the base to get it in.
public Id shift(int cnt, int fill)
shift
in class Id
cnt
- the number of bits to shift, negative shifts left, positive shifts rightfill
- value of bit shifted in (0 if fill == 0, 1 otherwise)
public Id shift(int cnt, int fill, boolean roundUp)
cnt
- the number of bits to shift, negative shifts left, positive shifts rightfill
- value of bit shifted in (0 if fill == 0, 1 otherwise)roundUp
- if true, round up the results after right shifting
public boolean between(Id ccw, Id cw)
Id
between
in class Id
ccw
- the counterclockwise idcw
- the clockwise id
public boolean clockwise(Id nid)
clockwise
in class Id
nid
- The Id we are comparing to
public java.lang.Object getValue()
getValue
in class Id
Id.getValue()
public void setValue(java.lang.Object newValue)
setValue
in class Id
newValue
- New value as int[] representation.Id.setValue(java.lang.Object)
public static Id getMaximum()
Id.getMaximum()
public static Id divide(long numberOfNodes)
numberOfNodes
- Number of nodes in the network.
Id.divide(long)
public Id divideOn(long divisor)
divideOn
in class Id
divisor
- The number of parts to divide this Id.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |