org.logicalcobwebs.cglib.core
Class KeyFactory
java.lang.Object
org.logicalcobwebs.cglib.core.KeyFactory
public abstract class KeyFactory
- extends java.lang.Object
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. For example:
private interface IntStringKey {
public Object newInstance(int i, String s);
}
Once you have made a KeyFactory
, you generate a new key by calling
the newInstance
method defined by your interface.
IntStringKey factory = (IntStringKey)KeyFactory.create(IntStringKey.class);
Object key1 = factory.newInstance(4, "Hello");
Object key2 = factory.newInstance(4, "World");
Note:
hashCode
equality between two keys key1
and key2
is only guaranteed if
key1.equals(key2)
and the keys were produced by the same factory.
- Version:
- $Id: KeyFactory.java,v 1.1 2003/12/12 19:28:11 billhorsman Exp $
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
GET_NAME
private static final Signature GET_NAME
GET_CLASS
private static final Signature GET_CLASS
HASH_CODE
private static final Signature HASH_CODE
EQUALS
private static final Signature EQUALS
TO_STRING
private static final Signature TO_STRING
APPEND_STRING
private static final Signature APPEND_STRING
KEY_FACTORY
private static final Type KEY_FACTORY
PRIMES
private static final int[] PRIMES
CLASS_BY_NAME
public static final Customizer CLASS_BY_NAME
OBJECT_BY_CLASS
public static final Customizer OBJECT_BY_CLASS
KeyFactory
protected KeyFactory()
create
public static KeyFactory create(java.lang.Class keyInterface)
create
public static KeyFactory create(java.lang.Class keyInterface,
Customizer customizer)