La copia del código es la siguiente:
paquete com.java.db;
import java.lang.reflect.constructor;
import java.lang.reflect.field;
import java.lang.reflect.invocationTargetException;
import java.lang.reflect.method;
import java.util.arrayList;
importar java.util.arrays;
import java.util.iterator;
import java.util.list;
import java.util.map;
import com.java.entity.bookshelf;
import com.java.util.getMetadatacloumname;
clase pública getNewinstances <t> {
Clase [] cl = {};
Objeto [] ob = {};
/**
* Establecido en vacío después de cada uso, de lo contrario se acumulará
*/
public void setNullToArrays () {
this.cl = new class [] {};
this.ob = nuevo objeto [] {};
}
/**
* Copiar la matriz de objetos
*
* @param obj
* El valor real requerido en el método de construcción
* @devolver
*/
objeto público [] getObjectArrays (object obj) {
ob = arrays.copyOf (ob, ob.length + 1);
ob [ob.length - 1] = obj;
regresar ob;
}
/**
* Copiar matriz de clase
*
* @param Cla
* Clase para agregar
*
* @devolver
*/
@SupessWarnings ("sin control")
clase pública [] getClassArrays (clase <?> Cla) {
if (CLA! = NULL) {
cl = arrays.copyOf (cl, cl.length + 1);
cl [cl.length - 1] = Cla;
regresar cl;
}demás{
regresar cl;
}
}
/**
* Obtenga una instancia de la clase
*
* @param clazz
* Clase para ser instanciadas
* @return clase después de la instancia
* @throws instantiationException
* @throws ilegalAccessException
* @throws ilegalargumentException
* @throws SecurityException
* @throws invocationTargetException
* @throws nosuchmethodexception
*/
@SupessWarnings ("sin control")
Objeto público GetClassNewinstance (clase <?> Clazz)
lanza instanciariationException, ilegalaccessexception,
IlegalargumentException, SecurityException,
InvocationTargetException, nosuchmethodexception {
Objeto oj = nulo;
Contrario = clazz.getDeClaredConstructors (); // Obtener el constructor
Clase [] Cla = Cons [1] .getParametertypes ();
System.out.println ("propina al usuario si debe agregar el tamaño del parámetro del constructor de campo:"+cla.length);
para (int i = 0; i <cla.length; i ++) {
Cadena classStr = Cla [i] .ToString ();
// System.out.println ("Tipo de argumento:"+classStr);
if (classstr.equals ("class java.lang.string")) {
GetClassArrays (String.Class);
} else if (classstr.equals ("int")) {
getClassArrays (int.class);
} else if (classstr.equals ("double")) {
getClassArrays (doble.class);
} else if (classstr.equals ("boolean")) {
GetClassArrays (boolean.class);
} else if (classstr.equals ("float")) {
GetClassArrays (float.class);
} else if (classstr.equals ("class java.lang.integer")) {
getClassArrays (integer.class);
} else if (classstr.equals ("class java.lang.float")) {
GetClassArrays (float.class);
}
}
oj = clazz.newinstance (); // Devuelve la construcción de instancia específica del objeto actual en bdoperater
regresar OJ;
}
/**
* Obtener clases de instancias específicas a través de constructores
* @param clazz
* @devolver
* @throws ilegalargumentException
* @throws SecurityException
* @throws instantiationException
* @throws ilegalAccessException
* @throws invocationTargetException
* @throws nosuchmethodexception
*/
Objeto público getobjcon (clase <?> Clazz) arroja ilegalargumentException, seguridad -expresión, instanteríaxception, ilegalaccessexception, invocationTargetException, nosuchmethodexception {
Objero obj = nulo;
obj = this.getClassNewinstance (Clazz);
regresar obj;
}
/**
* Obtenga una instancia del objeto
* @param clazz
* @devolver
* @throws instantiationException
* @throws ilegalAccessException
*/
objeto público getNewinstance (class clazz) lanza instanciaciónxception, ilegalaccessexception {
Objero obj = nulo;
obj = clazz.newinstance ();
regresar obj;
}
/**
* Obtenga todas las propiedades de la clase basadas en la reflexión
* @param clase de clazz que necesita ser recuperada
* @Return Atribute Collection
* @throws SecurityException
* @throws ilegalargumentException
* @throws instantiationException
* @throws ilegalAccessException
* @throws invocationTargetException
* @throws nosuchmethodexception
*/
Campo público [] getFielsDarray (clase <Sect> Clazz) arroja SecurityException, ilegalargumentException, instanticiationException, ilegalAccessException, invocationTargetException, nosuchmethodexception {
Campo [] campos = nulo;
campos = clazz.getDeclaredfields ();
campos de retorno;
}
/**
* Obtener atributos de formato de establecimiento de acuerdo con la cadena
* @Param STR Propiedad que debe formatearse
* @devolver
*/
public String GetSetterStr (String Str) {
String info = null;
String strValue = str.substring (0,1) .ToUpperCase ();
info = "set"+strValue+str.substring (1, str.length ());
Información de retorno;
}
/**
* Restaurar setxx a xx
* @param str
* @devolver
*/
Public String SetSetStr (String Str) {
String info = null;
Cadena strValue = str.substring (3, str.length ());
String Lower = strValue.sUstring (0) .tolowercase (). Subcadena (0,1);
info = Lower+str.substring (4, str.length ());
Información de retorno;
}
/**
* Obtenga el método en la clase
* @param Clazz requerido Clase para obtener el método
* @devolver
*/
Método público [] getMethodsArray (class clazz) {
Método [] métodos = clazz.getMethods ();
Métodos de retorno;
}
/**
* Instanciar el constructor de acuerdo con la lista <s map>
* @param listmap
* @param clazz
* @param Nombre de la base de datos de TableName
* @devolver
* @throws nosuchmethodexception
* @throws invocationTargetException
* @throws SecurityException
* @throws ilegalargumentException
* @throws ilegalAccessException
* @throws instantiationException
*/
@SupessWarnings ({"sin control"})
Lista pública <ject> getListByMap (List <Map <String, Object >> ListMap, Class Clazz, String TableName) lanza InstanciationException, ilegalAccessException, ilegalargumentException, SecurityException, InvocationTargetException, NosuchMethodexception {
List <S Object> listLast = new ArrayList <Sectus> ();
List <String> metalist = getMetadataCloumname.getCloUmnamElist (TableName);
Iterador <map <string, object >> it = listMap.iterator ();
while (it.hasnext ()) {
Map <string, object> map = it.next ();
Iterador <String> iitt = metalist.iterator ();
while (iitt.hasnext ()) {
String info = iitt.next ();
this.getObjectArrays (map.get (info));
}
System.out.println ("Reflexión de llamadas:"+this.cl.length+""+this.ob.length);
Object toBJ = this.getClassNewinStance (Clazz) .getClass (). GetConstructor (this.cl) .newinstance (this.ob);
listLast.Add (tOBJ);
this.setNullToArrays ();
}
devolver listlast;
}
public static void main (string [] args) {
GetNewinStances ge = new GetNewinStances ();
System.out.println (ge.getSetterStr ("Namespace") == "SetNamesPace");
System.out.println ("1a" == "1a");
System.out.println (GE.SetSetStr ("setnamespace"));
}
}