Package net.sf.cglib.core
Class KeyFactory
- java.lang.Object
-
- net.sf.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 forequals
andhashCode
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 namednewInstance
, which returns anObject
. 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 thenewInstance
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 keyskey1
andkey2
is only guaranteed ifkey1.equals(key2)
and the keys were produced by the same factory.- Version:
- $Id: KeyFactory.java,v 1.26 2006/03/05 02:43:19 herbyderby Exp $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
KeyFactory.Generator
-
Field Summary
Fields Modifier and Type Field Description private static Signature
APPEND_STRING
static Customizer
CLASS_BY_NAME
private static Signature
EQUALS
private static Signature
GET_CLASS
private static Signature
GET_NAME
private static Signature
GET_SORT
static HashCodeCustomizer
HASH_ASM_TYPE
Type.hashCode()
is very expensive as it traverses full descriptor to calculate hash code.private static Signature
HASH_CODE
private static org.objectweb.asm.Type
KEY_FACTORY
static Customizer
OBJECT_BY_CLASS
Deprecated.this customizer might result in unexpected class leak since key object still holds a strong reference to the Object and class.private static int[]
PRIMES
static FieldTypeCustomizer
STORE_CLASS_AS_STRING
private static Signature
TO_STRING
-
Constructor Summary
Constructors Modifier Constructor Description protected
KeyFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static KeyFactory
create(java.lang.Class keyInterface)
static KeyFactory
create(java.lang.ClassLoader loader, java.lang.Class keyInterface, Customizer customizer)
static KeyFactory
create(java.lang.ClassLoader loader, java.lang.Class keyInterface, KeyFactoryCustomizer customizer, java.util.List<KeyFactoryCustomizer> next)
static KeyFactory
create(java.lang.Class keyInterface, Customizer customizer)
static KeyFactory
create(java.lang.Class keyInterface, KeyFactoryCustomizer first, java.util.List<KeyFactoryCustomizer> next)
-
-
-
Field Detail
-
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 org.objectweb.asm.Type KEY_FACTORY
-
GET_SORT
private static final Signature GET_SORT
-
PRIMES
private static final int[] PRIMES
-
CLASS_BY_NAME
public static final Customizer CLASS_BY_NAME
-
STORE_CLASS_AS_STRING
public static final FieldTypeCustomizer STORE_CLASS_AS_STRING
-
HASH_ASM_TYPE
public static final HashCodeCustomizer HASH_ASM_TYPE
Type.hashCode()
is very expensive as it traverses full descriptor to calculate hash code. This customizer usesType.getSort()
as a hash code.
-
OBJECT_BY_CLASS
@Deprecated public static final Customizer OBJECT_BY_CLASS
Deprecated.this customizer might result in unexpected class leak since key object still holds a strong reference to the Object and class. It is recommended to have pre-processing method that would strip Objects and represent Classes as Strings
-
-
Method Detail
-
create
public static KeyFactory create(java.lang.Class keyInterface)
-
create
public static KeyFactory create(java.lang.Class keyInterface, Customizer customizer)
-
create
public static KeyFactory create(java.lang.Class keyInterface, KeyFactoryCustomizer first, java.util.List<KeyFactoryCustomizer> next)
-
create
public static KeyFactory create(java.lang.ClassLoader loader, java.lang.Class keyInterface, Customizer customizer)
-
create
public static KeyFactory create(java.lang.ClassLoader loader, java.lang.Class keyInterface, KeyFactoryCustomizer customizer, java.util.List<KeyFactoryCustomizer> next)
-
-