rice.pastry
Class Id.Distance

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

public static class Id.Distance
extends 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(Object obj)
          Equality operator.
 int hashCode()
          Hash codes.
 Id.Distance shift(int cnt, int fill)
          Shift operator. shift(-1,0) multiplies value of this by two, shift(1,0) divides by 2
 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
 Id.Distance shiftDistance(int cnt, int fill)
          Shift operator. shift(-1,0) multiplies value of this by two, shift(1,0) divides by 2
 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 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(Object obj)
Equality operator.

Overrides:
equals in class 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 Object
Returns:
a hash code.

toString

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

Overrides:
toString in class 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


Copyright © 2010. All Rights Reserved.