public FieldMetadata (Field field) { this.field = field; int index = (ClassReflection.isAssignableFrom(ObjectMap.class, field.getType()) || ClassReflection.isAssignableFrom(Map.class, field.getType())) ? 1 : 0; this.elementType = field.getElementType(index); } }
private Constructor findConstructor (Class<T> type) { try { return ClassReflection.getConstructor(type, (Class[])null); } catch (Exception ex1) { try { Constructor constructor = ClassReflection.getDeclaredConstructor(type, (Class[])null); constructor.setAccessible(true); return constructor; } catch (ReflectionException ex2) { return null; } } }
/** Creates a new array with {@link #items} of the specified type. * @param ordered If false, methods that remove elements may change the order of other elements in the array, which avoids a * memory copy. * @param capacity Any elements added beyond this will cause the backing array to be grown. */ public Array (boolean ordered, int capacity, Class arrayType) { this.ordered = ordered; items = (T[])ArrayReflection.newInstance(arrayType, capacity); }
/** Returns the value of the field on the supplied object. */ public Object get (Object obj) throws ReflectionException { try { return field.get(obj); } catch (IllegalArgumentException e) { throw new ReflectionException("Object is not an instance of " + getDeclaringClass(), e); } catch (IllegalAccessException e) { throw new ReflectionException("Illegal access to field: " + getName(), e); } }
/** Invokes the underlying method on the supplied object with the supplied parameters. */ public Object invoke (Object obj, Object... args) throws ReflectionException { try { return method.invoke(obj, args); } catch (IllegalArgumentException e) { throw new ReflectionException("Illegal argument(s) supplied to method: " + getName(), e); } catch (IllegalAccessException e) { throw new ReflectionException("Illegal access to method: " + getName(), e); } catch (InvocationTargetException e) { throw new ReflectionException("Exception occurred in method: " + getName(), e); } }
/** Returns a {@link Constructor} that represents the public constructor for the supplied class which takes the supplied * parameter types. */ static public Constructor getConstructor (Class c, Class... parameterTypes) throws ReflectionException { try { return new Constructor(c.getConstructor(parameterTypes)); } catch (SecurityException e) { throw new ReflectionException("Security violation occurred while getting constructor for class: '" + c.getName() + "'.", e); } catch (NoSuchMethodException e) { throw new ReflectionException("Constructor not found for class: " + c.getName(), e); } }
/** Returns a {@link Method} that represents the public member method for the supplied class which takes the supplied parameter * types. */ static public Method getMethod (Class c, String name, Class... parameterTypes) throws ReflectionException { try { return new Method(c.getMethod(name, parameterTypes)); } catch (SecurityException e) { throw new ReflectionException("Security violation while getting method: " + name + ", for class: " + c.getName(), e); } catch (NoSuchMethodException e) { throw new ReflectionException("Method not found: " + name + ", for class: " + c.getName(), e); } }
/** Returns a {@link Field} that represents the specified public member field for the supplied class. */ static public Field getField (Class c, String name) throws ReflectionException { try { return new Field(c.getField(name)); } catch (SecurityException e) { throw new ReflectionException("Security violation while getting field: " + name + ", for class: " + c.getName(), e); } catch (NoSuchFieldException e) { throw new ReflectionException("Field not found: " + name + ", for class: " + c.getName(), e); } }
public FieldMetadata (Field field) { this.field = field; int index = (ClassReflection.isAssignableFrom(ObjectMap.class, field.getType()) || ClassReflection.isAssignableFrom(Map.class, field.getType())) ? 1 : 0; this.elementType = field.getElementType(index); } }
/** Creates a new Queue which can hold the specified number of values without needing to resize backing array. This creates * backing array of the specified type via reflection, which is necessary only when accessing the backing array directly. */ public Queue (int initialSize, Class<T> type) { // noinspection unchecked this.values = (T[])ArrayReflection.newInstance(type, initialSize); }
private Constructor findConstructor (Class<T> type) { try { return ClassReflection.getConstructor(type, (Class[])null); } catch (Exception ex1) { try { Constructor constructor = ClassReflection.getDeclaredConstructor(type, (Class[])null); constructor.setAccessible(true); return constructor; } catch (ReflectionException ex2) { return null; } } }
/** Returns a {@link Constructor} that represents the constructor for the supplied class which takes the supplied parameter * types. */ static public Constructor getDeclaredConstructor (Class c, Class... parameterTypes) throws ReflectionException { try { return new Constructor(c.getDeclaredConstructor(parameterTypes)); } catch (SecurityException e) { throw new ReflectionException("Security violation while getting constructor for class: " + c.getName(), e); } catch (NoSuchMethodException e) { throw new ReflectionException("Constructor not found for class: " + c.getName(), e); } }
/** Returns a {@link Method} that represents the method declared by the supplied class which takes the supplied parameter types. */ static public Method getDeclaredMethod (Class c, String name, Class... parameterTypes) throws ReflectionException { try { return new Method(c.getDeclaredMethod(name, parameterTypes)); } catch (SecurityException e) { throw new ReflectionException("Security violation while getting method: " + name + ", for class: " + c.getName(), e); } catch (NoSuchMethodException e) { throw new ReflectionException("Method not found: " + name + ", for class: " + c.getName(), e); } }
/** Returns a {@link Field} that represents the specified declared field for the supplied class. */ static public Field getDeclaredField (Class c, String name) throws ReflectionException { try { return new Field(c.getDeclaredField(name)); } catch (SecurityException e) { throw new ReflectionException("Security violation while getting field: " + name + ", for class: " + c.getName(), e); } catch (NoSuchFieldException e) { throw new ReflectionException("Field not found: " + name + ", for class: " + c.getName(), e); } }
public ObjectChannel (int id, int strideSize, int size, Class<T> type) { super(id, ArrayReflection.newInstance(type, size * strideSize), strideSize); componentType = type; this.data = (T[])super.data; }
public ObjectChannel (int id, int strideSize, int size, Class<T> type) { super(id, ArrayReflection.newInstance(type, size * strideSize), strideSize); componentType = type; this.data = (T[])super.data; }
/** Creates a new array with {@link #items} of the specified type. * @param ordered If false, methods that remove elements may change the order of other elements in the array, which avoids a * memory copy. * @param capacity Any elements added beyond this will cause the backing array to be grown. */ public Array (boolean ordered, int capacity, Class arrayType) { this.ordered = ordered; items = (T[])ArrayReflection.newInstance(arrayType, capacity); }
/** Creates a new map with {@link #keys} and {@link #values} of the specified type. * @param ordered If false, methods that remove elements may change the order of other elements in the arrays, which avoids a * memory copy. * @param capacity Any elements added beyond this will cause the backing arrays to be grown. */ public ArrayMap (boolean ordered, int capacity, Class keyArrayType, Class valueArrayType) { this.ordered = ordered; keys = (K[])ArrayReflection.newInstance(keyArrayType, capacity); values = (V[])ArrayReflection.newInstance(valueArrayType, capacity); }
/** Creates a new map with {@link #keys} and {@link #values} of the specified type. * @param ordered If false, methods that remove elements may change the order of other elements in the arrays, which avoids a * memory copy. * @param capacity Any elements added beyond this will cause the backing arrays to be grown. */ public ArrayMap (boolean ordered, int capacity, Class keyArrayType, Class valueArrayType) { this.ordered = ordered; keys = (K[])ArrayReflection.newInstance(keyArrayType, capacity); values = (V[])ArrayReflection.newInstance(valueArrayType, capacity); }
/** Creates a new Queue which can hold the specified number of values without needing to resize backing array. This creates * backing array of the specified type via reflection, which is necessary only when accessing the backing array directly. */ public Queue (int initialSize, Class<T> type) { // noinspection unchecked this.values = (T[])ArrayReflection.newInstance(type, initialSize); }