类 KeyFactory
java.lang.Object
cn.taketoday.bytecode.core.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. 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.
- 作者:
- Harry Yang
-
嵌套类概要
嵌套类 -
字段概要
字段修饰符和类型字段说明static final Customizerstatic final HashCodeCustomizerType.hashCode()is very expensive as it traverses full descriptor to calculate hash code. -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static <T> Tstatic <T> Tcreate(Class<T> keyInterface, Customizer customizer) static <T> Tcreate(Class<T> keyInterface, KeyFactoryCustomizer first, List<KeyFactoryCustomizer> next) static <T> Tcreate(ClassLoader loader, Class<T> keyInterface, Customizer customizer) static <T> Tcreate(ClassLoader loader, Class<T> keyInterface, KeyFactoryCustomizer customizer, List<KeyFactoryCustomizer> next)
-
字段详细资料
-
CLASS_BY_NAME
-
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.
-
-
构造器详细资料
-
KeyFactory
protected KeyFactory()
-
-
方法详细资料
-
create
-
create
-
create
public static <T> T create(Class<T> keyInterface, KeyFactoryCustomizer first, List<KeyFactoryCustomizer> next) -
create
-
create
public static <T> T create(ClassLoader loader, Class<T> keyInterface, KeyFactoryCustomizer customizer, List<KeyFactoryCustomizer> next)
-