|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--viceroy.HashValue
Represents the result value of a hash-function on some object. Note: This class is immutable.
| Field Summary | |
static int |
DEFAULT_PRECISION_BITS
The default number of precision bits in this HashValue's value |
protected static org.apache.log4j.Logger |
logger
Logger for debug |
static HashValue |
MAX
Represents a MAX HashValue, i.e. |
static HashValue |
MIN
Represents a MIN HashValue, i.e. |
protected static java.math.BigDecimal |
ONE_DECIMAL
Represents a BigDecimal of the value 1.0 |
private int |
precisionBits
The Defualt precision bits |
private static java.util.Random |
random
A random number |
private java.math.BigDecimal |
value
The actual value held |
private static java.math.BigDecimal |
ZERO_DECIMAL
Represents a BigDecimal of the value 0.0 |
| Constructor Summary | |
|
HashValue()
creates a new HashValue with a random value (uniform distribution) with the default number of bits. |
|
HashValue(HashValue old,
int precisionBitsToAdd,
HashValue min)
Creates a new HashValue, which is based on the given one, making it more precise, according to the given parameter. |
|
HashValue(int _precisionBits)
Creates a new HashValue with a random value (uniform distribution) with the requested number of bits. |
|
HashValue(java.lang.String val)
Creates a HashValue from a given string |
|
HashValue(java.lang.String val,
int _precisionBits)
Creates a HashValue from a given string and precision bits. |
private |
HashValue(java.lang.String val,
java.lang.String name)
|
| Method Summary | |
java.math.BigDecimal |
absoluteDistance(HashValue other)
Gets the absolute distance between this and other. |
java.math.BigDecimal |
clockwiseDistance(HashValue other)
Calculates the clock-wise distance from this HashValue to the given value. |
int |
compareTo(java.lang.Object o)
Compares this object with the specified object for order. |
boolean |
equals(java.lang.Object obj)
Checks if a given object equals to me. |
private static java.math.BigDecimal |
getRandomInRange(int _precisionBits)
Gets a random in the specific range |
int |
hashCode()
uses the value's hashcode to return a hashcode |
boolean |
isInStretch(HashValue begin,
HashValue end)
Checks if this HashValue is between begin and end. |
boolean |
isInStretchExclusive(HashValue begin,
HashValue end)
Checks if this HashValue is between begin and end, clock-wise and exclusive. |
boolean |
isInStretchExclusiveNonCyclic(HashValue begin,
HashValue end)
Checks if this HashValue is in the Sretch (begin,end) but only if begin < end. |
boolean |
isInStretchNonCyclic(HashValue begin,
HashValue end)
Checks if this HashValue is in the Sretch (begin,end] but only if begin < end. |
static int |
log10(double x)
Returns the log10 of a given number NOTE<\B> This method returns a floor rounding!!! |
static int |
log2(double x)
Returns the log2 of a given number NOTE<\B> This method returns a floor rounding!!! |
static void |
main(java.lang.String[] args)
The main for that class |
static int |
numDecimalDigits(java.math.BigInteger num)
Returns the number of decimal digits of a given BigInteger |
static int |
numDecimalDigitsAfterPoint(java.math.BigDecimal num)
Returns the number of decimal digits after the point of a given BigInteger |
static void |
testHashValue()
Unit testing |
java.lang.String |
toString()
to string |
java.math.BigDecimal |
value()
Return the value of the HashValue |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected static org.apache.log4j.Logger logger
private static java.util.Random random
protected static final java.math.BigDecimal ONE_DECIMAL
private static final java.math.BigDecimal ZERO_DECIMAL
public static final HashValue MIN
public static final HashValue MAX
private java.math.BigDecimal value
public static final int DEFAULT_PRECISION_BITS
private int precisionBits
| Constructor Detail |
public HashValue()
java.lang.ArithmeticException - bitLength < 2.DEFAULT_PRECISION_BITSpublic HashValue(int _precisionBits)
java.lang.ArithmeticException - bitLength < 2.
public HashValue(HashValue old,
int precisionBitsToAdd,
HashValue min)
old - the value to base onprecisionBitsToAdd - the number of precision bits to addmin - the value that the new hash value should be bigger than.
Usually it is the peer predecessor's id
java.lang.IllegalArgumentException - if numBitsToAdd is negative
public HashValue(java.lang.String val,
int _precisionBits)
val - The value that the hash would be_precisionBits - The precision bits it would use
private HashValue(java.lang.String val,
java.lang.String name)
public HashValue(java.lang.String val)
val - The given value to create the HashValue| Method Detail |
private static java.math.BigDecimal getRandomInRange(int _precisionBits)
_precisionBits -
public java.math.BigDecimal clockwiseDistance(HashValue other)
other - the given HashValue, to which we calculate the distance to.
public java.math.BigDecimal absoluteDistance(HashValue other)
other - the given HashValue, to which we calculate the distance to.
public java.math.BigDecimal value()
public boolean isInStretch(HashValue begin,
HashValue end)
begin - the start of the range to check (stretch)end - the end of the range to check (stretch)
public boolean isInStretchNonCyclic(HashValue begin,
HashValue end)
begin - the start of the range to check (stretch)end - the end of the range to check (stretch)
public boolean isInStretchExclusive(HashValue begin,
HashValue end)
begin - the start of the range to check (stretch)end - the end of the range to check (stretch)
public boolean isInStretchExclusiveNonCyclic(HashValue begin,
HashValue end)
begin - the start of the range to check (stretch)end - the end of the range to check (stretch)
public int hashCode()
hashCode in class java.lang.Objectpublic int compareTo(java.lang.Object o)
The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception iff y.compareTo(x) throws an exception.)
The implementor must also ensure that the relation is transitive: (x.compareTo(y)>0 && y.compareTo(z)>0) implies x.compareTo(z)>0.
Finally, the implementer must ensure that x.compareTo(y)==0 implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z.
It is strongly recommended, but not strictly required that (x.compareTo(y)==0) == (x.equals(y)). Generally speaking, any class that implements the Comparable interface and violates this condition should clearly indicate this fact. The recommended language is "Note: this class has a natural ordering that is inconsistent with equals."
compareTo in interface java.lang.Comparableo - the Object to be compared.
java.lang.ClassCastException - if the specified object's type prevents it
from being compared to this Object.public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectobj - The object to compare with
public java.lang.String toString()
toString in class java.lang.Objectpublic static int log2(double x)
x - The number to be logged
public static int log10(double x)
x - The number to be logged
public static int numDecimalDigits(java.math.BigInteger num)
num - the given integer
public static int numDecimalDigitsAfterPoint(java.math.BigDecimal num)
num - the given integer
public static void testHashValue()
public static void main(java.lang.String[] args)
args -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||