|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectnet.sf.cglib.KeyFactory
public abstract class KeyFactory
Generates classes to handle multi-valued keys, for use in things such as Maps and Sets.
Code for equals and hashCode methods follow the
the rules laid out in Effective Java by Joshua Bloch.
To generate a KeyFactory, you need to supply an interface which
describes the structure of the key. The interface should have a
single method named newInstance, which returns an
Object. The arguments array can be
anything--Objects, primitive values, or single or
multi-dimension arrays of either.
Once you have made a KeyFactory, you generate a new key by calling
the newInstance method defined by your interface.
This example should print true followed by false:
import net.sf.cglib.KeyFactory;
public class KeySample {
private interface MyFactory {
public Object newInstance(int a, char[] b, String c);
}
public static void main(String[] args) {
MyFactory f = (MyFactory)KeyFactory.create(MyFactory.class, null);
Object key1 = f.newInstance(20, new char[]{ 'a', 'b' }, "hello");
Object key2 = f.newInstance(20, new char[]{ 'a', 'b' }, "hello");
Object key3 = f.newInstance(20, new char[]{ 'a', '_' }, "hello");
System.out.println(key1.equals(key2));
System.out.println(key2.equals(key3));
}
}
Note:
hashCode equality between two keys key1 and key2 is guaranteed if
key1.equals(key2) and the keys were produced by the same factory.
| Method Summary | |
|---|---|
static KeyFactory |
create(java.lang.Class keyInterface,
java.lang.ClassLoader loader)
|
abstract java.lang.Object[] |
getArgs()
Returns the list of objects that were used to create the key. |
int |
hashCode()
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static KeyFactory create(java.lang.Class keyInterface,
java.lang.ClassLoader loader)
public int hashCode()
hashCode in class java.lang.Objectpublic abstract java.lang.Object[] getArgs()
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||