Package net.imglib2.loops
Class ClassCopyProvider<T>
- java.lang.Object
-
- net.imglib2.loops.ClassCopyProvider<T>
-
public class ClassCopyProvider<T> extends java.lang.ObjectHelper to create multiple copies of a class.The copies of the class have individual copies of the byte code. The JIT compiler optimizes the class copies individually, which can increase performance.
-
-
Constructor Summary
Constructors Constructor Description ClassCopyProvider(java.lang.Class<? extends T> clazz, java.lang.Class<T> interfaceOfClazz, java.lang.Class<?>... constructorSignature)Create a ClassCopyProvider to make copy a a given class.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.Class<?>[]assumeConstructorSignature(java.lang.Class<?> clazz)private java.lang.Class<? extends T>classForKey(java.lang.Object key)private static booleanhasDefaultConstructor(java.lang.Class<?> clazz)booleanmatches(java.lang.Object... parameters)Returns true if the given list of objects, matches the constructor signature provided toClassCopyProvider(Class, Class, Class[]).TnewInstanceForKey(java.lang.Object key, java.lang.Object... parameters)Returns an instance of a copy of the original class, that has been provided to the constructor.
-
-
-
Field Detail
-
map
private final java.util.Map<java.lang.Object,java.lang.Class<? extends T>> map
-
copier
private final ClassCopier<T> copier
-
signature
private final java.lang.Class<?>[] signature
-
-
Constructor Detail
-
ClassCopyProvider
public ClassCopyProvider(java.lang.Class<? extends T> clazz, java.lang.Class<T> interfaceOfClazz, java.lang.Class<?>... constructorSignature)
Create a ClassCopyProvider to make copy a a given class.- Parameters:
clazz- Class to be copied.interfaceOfClazz- Interface that's implemented by the clazz. A class copies can only be used through this interface.constructorSignature- Constructor signature to be used when creating a new instance withnewInstanceForKey(java.lang.Object, java.lang.Object...)
-
-
Method Detail
-
assumeConstructorSignature
private static java.lang.Class<?>[] assumeConstructorSignature(java.lang.Class<?> clazz)
-
hasDefaultConstructor
private static boolean hasDefaultConstructor(java.lang.Class<?> clazz)
-
classForKey
private java.lang.Class<? extends T> classForKey(java.lang.Object key)
-
matches
public boolean matches(java.lang.Object... parameters)
Returns true if the given list of objects, matches the constructor signature provided toClassCopyProvider(Class, Class, Class[]).
-
newInstanceForKey
public T newInstanceForKey(java.lang.Object key, java.lang.Object... parameters)
Returns an instance of a copy of the original class, that has been provided to the constructor.Note: The returned object isn't an instance of the original class.
Class.isInstance(Object)and "instanceof" will return false. And ClassCastException might occur if this is ignored.The returned instance has a copy of the byte code of the original class. This byte code is independently optimised by the JIT compiler. The JIT compiler will optimise the byte code, if it's only used in a specific use case. If used wisely a performance increase is the consequence.
- Parameters:
key- Instances created with the same key, share their byte code.parameters- Parameters that are passed to the constructor.
-
-