Rice Pastry API

rice.pastry
Class Id.Distance

java.lang.Object
  extended by rice.pastry.Id.Distance
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Id.Distance>, Id.Distance
Enclosing class:
Id

public static class Id.Distance
extends java.lang.Object
implements Id.Distance

A class for representing and manipulating the distance between two Ids on the circle.

Version:
$Id: Id.java 4654 2009-01-08 16:33:07Z jeffh $
Author:
amislove
See Also:
Serialized Form

Constructor Summary
Id.Distance()
          Constructor.
Id.Distance(byte[] diff)
          Constructor.
Id.Distance(int[] diff)
          Constructor.
 
Method Summary
 void blit(byte[] target)
          Blits the distance into a target array.
 void blit(byte[] target, int offset)
          Blits the distance into a target array, starting at the given offset.
 int compareTo(Id.Distance obj)
          Comparison operator.
 byte[] copy()
          Copy the distance into a freshly generated array.
 boolean equals(java.lang.Object obj)
          Equality operator.
 int hashCode()
          Hash codes.
 Id.Distance shift(int cnt, int fill)
          Shift operator.
 Id.Distance shift(int cnt, int fill, boolean roundUp)
          Shift operator.
 Id.Distance shiftDistance(int cnt, int fill)
          Shift operator.
 java.lang.String toString()
          Returns a string representation of the distance The string is a byte string from most to least significant.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Id.Distance

public Id.Distance()
Constructor.


Id.Distance

public Id.Distance(byte[] diff)
Constructor.

Parameters:
diff - The different, as a byte array

Id.Distance

public Id.Distance(int[] diff)
Constructor.

Parameters:
diff - The difference, as an int array
Method Detail

blit

public void blit(byte[] target)
Blits the distance into a target array.

Parameters:
target - an array of length at least IdBitLength/8 for the distance to be stored in.

blit

public void blit(byte[] target,
                 int offset)
Blits the distance into a target array, starting at the given offset.

Parameters:
offset - The offset to start at
target - an array of length at least IdBitLength/8 for the distance to be stored in.

copy

public byte[] copy()
Copy the distance into a freshly generated array.

Returns:
a fresh copy of the distance material

compareTo

public int compareTo(Id.Distance obj)
Comparison operator. The comparison that occurs is an absolute magnitude comparison.

Specified by:
compareTo in interface java.lang.Comparable<Id.Distance>
Parameters:
obj - the Distance to compare with.
Returns:
negative if this < obj, 0 if they are equal and positive if this > obj.

equals

public boolean equals(java.lang.Object obj)
Equality operator.

Overrides:
equals in class java.lang.Object
Parameters:
obj - another Distance.
Returns:
true if they are the same, false otherwise.

shift

public Id.Distance shift(int cnt,
                         int fill)
Shift operator. shift(-1,0) multiplies value of this by two, shift(1,0) divides by 2

Parameters:
cnt - the number of bits to shift, negative shifts left, positive shifts right
fill - value of bit shifted in (0 if fill == 0, 1 otherwise)
Returns:
this

shift

public Id.Distance shift(int cnt,
                         int fill,
                         boolean roundUp)
Shift operator. shift(-1,0) multiplies value of this by two, shift(1,0) divides by 2

Parameters:
cnt - the number of bits to shift, negative shifts left, positive shifts right
fill - value of bit shifted in (0 if fill == 0, 1 otherwise)
roundUp - if true, round up the results after right shifting
Returns:
this

hashCode

public int hashCode()
Hash codes.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code.

toString

public java.lang.String toString()
Returns a string representation of the distance The string is a byte string from most to least significant.

Overrides:
toString in class java.lang.Object
Returns:
The string representation of this distance

shiftDistance

public Id.Distance shiftDistance(int cnt,
                                 int fill)
Shift operator. shift(-1,0) multiplies value of this by two, shift(1,0) divides by 2

Specified by:
shiftDistance in interface Id.Distance
Parameters:
cnt - the number of bits to shift, negative shifts left, positive shifts right
fill - value of bit shifted in (0 if fill == 0, 1 otherwise)
Returns:
this

Rice Pastry API

Copyright © 2001-2005 - Rice Pastry.


Imprint-Dataprotection