List<Map<String, String>> itemList = ArrayList.newInstance();

List<Map<String, String>> itemList = new ArrayList<Map<String, String>>();

위 두개는 동일


Map<String, String> itemMap = HashMap.newInstance();

Map<String, String> itemMap = new HashMap<String, String>();

위 두개는 동일


[ArrayList.java]

public class ArrayList {


public static <V> java.util.ArrayList<V> newInstance() {

return new java.util.ArrayList<V>();

}

}


[Body]

private static List<Map<String, String>> getItemList() throws Exception {

// item_code.txt 파일에 있는 품번 목록을 가져온다.

List<Map<String, String>> itemList = ArrayList.newInstance();

File file = new File("C:/mydata/image_test/item_code.txt");

BufferedReader br = new BufferedReader(new FileReader(file));

String str = "";

while((str = br.readLine()) != null) {

Map<String, String> itemMap = HashMap.newInstance();

itemMap.put("item", str);

itemList.add(itemMap);

}

if(br != null)

br.close();

System.out.println("LIST_SIZE : " + itemList.size());

return itemList;

}



[HashMap.java]

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;

public class HashMap {

public static <K, V> java.util.HashMap<K, V> newInstance() {
return new java.util.HashMap<K, V>();
}
public static Map<String, String> toMap(String className, Object obj) {
Map<String, String> map = newInstance();
try {
Class<?> clsObj = Class.forName(className);
for(Method method : clsObj.getMethods()) {
if(method.getName().startsWith("get") &&
method.toString().indexOf("static") < 0 &&
method.toString().indexOf("final") < 0) {
map.put(method.getName().toString().replace("get", ""), method.invoke(obj).toString());
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return map;
}
public static void setObjcet(String className, Object obj, Map<String, String> paramMap) {
try {
Class<?> clsObj = Class.forName(className);
for(Method method : clsObj.getMethods()) {
if(method.getName().startsWith("set")) {
//System.out.println("Method Name : " + method.getName());
//System.out.println();
method.invoke(obj, paramMap.get(method.getName().replace("set", "")));
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}


+ Recent posts