|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.netflix.util.HashCode
public class HashCode
Helper class for computing hash codes.
The idea here is that objects that define "equals" to mean that a number of member variables are equal needs a hash code that is computed from those same member variables.
Example:
class MyClass {
...
private int membVar1;
private OtherClass membVar2;
private float membVar3;
...
// MyClass objects are equal iff they have the same content.
public boolean equals(Object obj) {
if (obj == this) {
return true;
} else if (obj == null || obj.getClass() != getClass()) {
return false;
}
MyClass cObj = (MyClass)obj;
return (membVar1 == cObj.membVar1)
&& HashCode.equalObjects(membVar2, cObj.membVar2)
&& (membVar3 == bVar3);
}
// The hash code needs to align with the
// definition of equals.
public int hashCode() {
HashCode h = new HashCode();
h.addValue(membVar1);
h.addValue(membVar2);
h.addValue(membVar2);
return h.hashCode();
}
...
}
| Constructor Summary | |
|---|---|
HashCode()
Create a new HashCode object |
|
| Method Summary | |
|---|---|
int |
addValue(boolean b)
Augment the current computed hash code with the value b. |
int |
addValue(boolean[] array)
Augment the current computed hash code with the value array. |
int |
addValue(byte i)
Augment the current computed hash code with the value i. |
int |
addValue(byte[] array)
Augment the current computed hash code with the value i. |
int |
addValue(char i)
Augment the current computed hash code with the value i. |
int |
addValue(char[] array)
Augment the current computed hash code with the value array. |
int |
addValue(double f)
Augment the current computed hash code with the value f. |
int |
addValue(double[] array)
Augment the current computed hash code with the value array. |
int |
addValue(float f)
Augment the current computed hash code with the value f. |
int |
addValue(float[] array)
Augment the current computed hash code with the value array. |
int |
addValue(int i)
Augment the current computed hash code with the value i. |
int |
addValue(int[] array)
Augment the current computed hash code with the value array. |
int |
addValue(java.lang.Object obj)
Augment the current computed hash code with the value obj. |
int |
addValue(java.lang.Object[] array)
Augment the current computed hash code with the value array. |
int |
addValue(short i)
Augment the current computed hash code with the value i. |
int |
addValue(short[] array)
Augment the current computed hash code with the value array. |
static boolean |
equalObjects(java.lang.Object o1,
java.lang.Object o2)
Utility function to make it easy to compare two, possibly null, objects. |
boolean |
equals(java.lang.Object obj)
|
int |
hashCode()
Get the currently computed hash code value. |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public HashCode()
| Method Detail |
|---|
public int addValue(java.lang.Object obj)
obj - value being added
public int addValue(boolean b)
b - value being added
public int addValue(byte i)
i - value being added
public int addValue(char i)
i - value being added
public int addValue(short i)
i - value being added
public int addValue(int i)
i - value being added
public int addValue(float f)
f - value being added
public int addValue(double f)
f - value being added
public int addValue(java.lang.Object[] array)
array - value being added
public int addValue(boolean[] array)
array - value being added
public int addValue(byte[] array)
array - value being added
public int addValue(char[] array)
array - value being added
public int addValue(short[] array)
array - value being added
public int addValue(int[] array)
array - value being added
public int addValue(float[] array)
array - value being added
public int addValue(double[] array)
array - value being added
public static boolean equalObjects(java.lang.Object o1,
java.lang.Object o2)
o1 - first objecto2 - second object
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||