} else if (constructors.size() == 1) { ConstructorAccess constructorAccess = constructors.get(0); Class<?> arg1Type = constructorAccess.parameterTypes()[0]; if (arg1Type.isInstance(value)) { return (T) constructorAccess.create(value); } else { return (T) constructorAccess.create(coerce(arg1Type, value)); Class<?> arg1Type = c.parameterTypes()[0]; if (arg1Type.isInstance(value)) { return (T) c.create(value); Class<?> arg1Type = c.parameterTypes()[0]; if (arg1Type.isAssignableFrom(value.getClass())) { return (T) c.create(value);
this.queue = ClassMeta.classMeta(queueClass).noArgConstructor().create(); } else { final ConstructorAccess<Object> constructor = classMeta.declaredConstructor(int.class); this.queue = (BlockingQueue<Object>) constructor.create(size); } else { final ConstructorAccess<? extends BlockingQueue> constructorAccess = classMeta.noArgConstructor(); this.queue = (BlockingQueue<Object>) constructorAccess.create();
public <T> ConstructorAccess<T> declaredConstructor(Class<? extends Object> singleArg) { for (ConstructorAccess constructorAccess : constructorAccessSet) { if (constructorAccess.parameterTypes().length==1) { if (constructorAccess.parameterTypes()[0].isAssignableFrom(singleArg)) { return constructorAccess; } } } return null; }
public static <V, WRAP> List<WRAP> wrap(Class<WRAP> wrapper, Collection<V> collection ) { if (collection.size()==0) { return Collections.EMPTY_LIST; } List<WRAP> list = new ArrayList<>( collection.size () ); ClassMeta<WRAP> cls = ClassMeta.classMeta(wrapper); ConstructorAccess<WRAP> declaredConstructor = cls.declaredConstructor(collection.iterator().next().getClass()); for (V v : collection) { WRAP wrap = declaredConstructor.create ( v ); list.add ( wrap ); } return list; }
public <T> ConstructorAccess<T> declaredConstructor(Class<? extends Object> singleArg) { for (ConstructorAccess constructorAccess : constructorAccessSet) { if (constructorAccess.parameterTypes().length==1) { if (constructorAccess.parameterTypes()[0].isAssignableFrom(singleArg)) { return constructorAccess; } } } return null; }
} else if (constructors.size() == 1) { ConstructorAccess constructorAccess = constructors.get(0); Class<?> arg1Type = constructorAccess.parameterTypes()[0]; if (arg1Type.isInstance(value)) { return (T) constructorAccess.create(value); } else { return (T) constructorAccess.create(coerce(arg1Type, value)); Class<?> arg1Type = c.parameterTypes()[0]; if (arg1Type.isInstance(value)) { return (T) c.create(value); Class<?> arg1Type = c.parameterTypes()[0]; if (arg1Type.isAssignableFrom(value.getClass())) { return (T) c.create(value);
public static <V, WRAP> List<WRAP> wrap(Class<WRAP> wrapper, Collection<V> collection ) { if (collection.size()==0) { return Collections.EMPTY_LIST; } List<WRAP> list = new ArrayList<>( collection.size () ); ClassMeta<WRAP> cls = ClassMeta.classMeta(wrapper); ConstructorAccess<WRAP> declaredConstructor = cls.declaredConstructor(collection.iterator().next().getClass()); for (V v : collection) { WRAP wrap = declaredConstructor.create ( v ); list.add ( wrap ); } return list; }
public List<ConstructorAccess> oneArgumentConstructors() { List <ConstructorAccess> constructors = new ArrayList<>(); for (ConstructorAccess constructorAccess : constructorAccessSet) { if (constructorAccess.parameterTypes().length==1) { constructors.add(constructorAccess); } } return constructors; }
} else if (constructors.size() == 1) { ConstructorAccess constructorAccess = constructors.get(0); Class<?> arg1Type = constructorAccess.parameterTypes()[0]; if (arg1Type.isInstance(value)) { return (T) constructorAccess.create(value); } else { return (T) constructorAccess.create(coerce(arg1Type, value)); Class<?> arg1Type = c.parameterTypes()[0]; if (arg1Type.isInstance(value)) { return (T) c.create(value); Class<?> arg1Type = c.parameterTypes()[0]; if (arg1Type.isAssignableFrom(value.getClass())) { return (T) c.create(value);
public static <T> T newInstance( Class<T> clazz, Object arg ) { T newInstance = null; ClassMeta <T> cls = ClassMeta.classMeta(clazz); try { /* See if there is a no arg constructor. */ ConstructorAccess<T> declaredConstructor = cls.declaredConstructor(arg.getClass()); if (declaredConstructor !=null ) { /* If there was a no argument constructor, then use it. */ newInstance = declaredConstructor.create(arg); } } catch ( Exception ex ) { handle( ex ); } return newInstance; }
public List<ConstructorAccess> oneArgumentConstructors() { List <ConstructorAccess> constructors = new ArrayList<>(); for (ConstructorAccess constructorAccess : constructorAccessSet) { if (constructorAccess.parameterTypes().length==1) { constructors.add(constructorAccess); } } return constructors; }
} else if (constructors.size() == 1) { ConstructorAccess constructorAccess = constructors.get(0); Class<?> arg1Type = constructorAccess.parameterTypes()[0]; if (arg1Type.isInstance(value)) { return (T) constructorAccess.create(value); } else { return (T) constructorAccess.create(coerce(arg1Type, value)); Class<?> arg1Type = c.parameterTypes()[0]; if (arg1Type.isInstance(value)) { return (T) c.create(value); Class<?> arg1Type = c.parameterTypes()[0]; if (arg1Type.isAssignableFrom(value.getClass())) { return (T) c.create(value);
public static <T> T newInstance( Class<T> clazz, Object arg ) { T newInstance = null; ClassMeta <T> cls = ClassMeta.classMeta(clazz); try { /* See if there is a no arg constructor. */ ConstructorAccess<T> declaredConstructor = cls.declaredConstructor(arg.getClass()); if (declaredConstructor !=null ) { /* If there was a no argument constructor, then use it. */ newInstance = declaredConstructor.create(arg); } } catch ( Exception ex ) { handle( ex ); } return newInstance; }
private <T> ConstructorAccess<T> lookupConstructorMeta(int size, List<Object> convertedArguments, ClassMeta<T> classMeta, ConstructorAccess<T> constructorToMatch, boolean[] flag, boolean loose) { /* Iterate through the constructors and see if one matches the arguments passed after coercion. */ loop: for ( ConstructorAccess constructor : classMeta.constructors() ) { /* Get the parameters on the constructor and see if the size matches what was passed. */ Class[] parameterTypes = constructor.parameterTypes(); if ( parameterTypes.length == size ) { /* Iterate through each parameter and see if it can be converted. */ for ( int index = 0; index < size; index++ ) { /* The match and convert does the bulk of the work. */ if ( !matchAndConvertArgs( convertedArguments, constructor, parameterTypes, index, flag, loose ) ) continue loop; } constructorToMatch = constructor; } } return constructorToMatch; }
return constructorToMatch.create( finalArgs ); } else { return (T) Exceptions.die(Object.class, "Unable to convert list", convertedArguments, "into", clazz); for (Class<?> c : constructorToMatch.parameterTypes()) { buf.puts("constructor type ", c); buf.add(Lists.list(constructorToMatch.parameterTypes())).addLine();
this.queue = ClassMeta.classMeta(queueClass).noArgConstructor().create(); } else { final ConstructorAccess<Object> constructor = classMeta.declaredConstructor(int.class); this.queue = (BlockingQueue<Object>) constructor.create(size); } else { final ConstructorAccess<? extends BlockingQueue> constructorAccess = classMeta.noArgConstructor(); this.queue = (BlockingQueue<Object>) constructorAccess.create();
private <T> ConstructorAccess<T> lookupConstructorMeta(int size, List<Object> convertedArguments, ClassMeta<T> classMeta, ConstructorAccess<T> constructorToMatch, boolean[] flag, boolean loose) { /* Iterate through the constructors and see if one matches the arguments passed after coercion. */ loop: for ( ConstructorAccess constructor : classMeta.constructors() ) { /* Get the parameters on the constructor and see if the size matches what was passed. */ Class[] parameterTypes = constructor.parameterTypes(); if ( parameterTypes.length == size ) { /* Iterate through each parameter and see if it can be converted. */ for ( int index = 0; index < size; index++ ) { /* The match and convert does the bulk of the work. */ if ( !matchAndConvertArgs( convertedArguments, constructor, parameterTypes, index, flag, loose ) ) continue loop; } constructorToMatch = constructor; } } return constructorToMatch; }
return constructorToMatch.create( finalArgs ); } else { return (T) Exceptions.die(Object.class, "Unable to convert list", convertedArguments, "into", clazz); for (Class<?> c : constructorToMatch.parameterTypes()) { buf.puts("constructor type ", c); buf.add(Lists.list(constructorToMatch.parameterTypes())).addLine();
this.queue = ClassMeta.classMeta(queueClass).noArgConstructor().create(); } else { final ConstructorAccess<Object> constructor = classMeta.declaredConstructor(int.class); this.queue = (BlockingQueue<Object>) constructor.create(size); } else { final ConstructorAccess<? extends BlockingQueue> constructorAccess = classMeta.noArgConstructor(); this.queue = (BlockingQueue<Object>) constructorAccess.create();
private <T> ConstructorAccess<T> lookupConstructorMeta(int size, List<Object> convertedArguments, ClassMeta<T> classMeta, ConstructorAccess<T> constructorToMatch, boolean[] flag, boolean loose) { /* Iterate through the constructors and see if one matches the arguments passed after coercion. */ loop: for ( ConstructorAccess constructor : classMeta.constructors() ) { /* Get the parameters on the constructor and see if the size matches what was passed. */ Class[] parameterTypes = constructor.parameterTypes(); if ( parameterTypes.length == size ) { /* Iterate through each parameter and see if it can be converted. */ for ( int index = 0; index < size; index++ ) { /* The match and convert does the bulk of the work. */ if ( !matchAndConvertArgs( convertedArguments, constructor, parameterTypes, index, flag, loose ) ) continue loop; } constructorToMatch = constructor; } } return constructorToMatch; }