|
|
@@ -0,0 +1,432 @@
|
|
|
+package com.fourj.foframework.web.parameter;
|
|
|
+
|
|
|
+import java.io.Serializable;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Hash table and linked list implementation of the Map interface,
|
|
|
+ * with predictable iteration order.
|
|
|
+ * This replaces FoMapList.
|
|
|
+ *
|
|
|
+ * @author fourj1315
|
|
|
+ * @since 2024. 07. 04
|
|
|
+ */
|
|
|
+public class FoMapList extends LinkedHashMap<Object, Object> implements Serializable {
|
|
|
+ private static final long serialVersionUID = 496702765517420534L;
|
|
|
+
|
|
|
+ private int fieldIndex;
|
|
|
+ private HashMap<String, Integer> entityKey;
|
|
|
+ private String name;
|
|
|
+
|
|
|
+ public FoMapList() {
|
|
|
+ fieldIndex = 0;
|
|
|
+ entityKey = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public FoMapList(String name) {
|
|
|
+ fieldIndex = 0;
|
|
|
+ entityKey = null;
|
|
|
+ this.name = name;
|
|
|
+ }
|
|
|
+
|
|
|
+ public FoMapList(int initialCapacity, float loadFactor) {
|
|
|
+ super(initialCapacity, loadFactor);
|
|
|
+ fieldIndex = 0;
|
|
|
+ entityKey = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public FoMapList(int initialCapacity) {
|
|
|
+ super(initialCapacity);
|
|
|
+ fieldIndex = 0;
|
|
|
+ entityKey = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public FoMapList(Map<?, ?> m) {
|
|
|
+ super(m);
|
|
|
+ fieldIndex = 0;
|
|
|
+ entityKey = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public void add(Object key, Object value) {
|
|
|
+ if (!super.containsKey(key)) {
|
|
|
+ List<Object> arrayList = new ArrayList<Object>();
|
|
|
+ arrayList.add(value);
|
|
|
+ super.put(key, arrayList);
|
|
|
+ } else {
|
|
|
+ List<Object> arrayList = (ArrayList<Object>)super.get(key);
|
|
|
+ arrayList.add(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public void addString(Object key, String value) {
|
|
|
+ if (!super.containsKey(key)) {
|
|
|
+ List<String> arrayList = new ArrayList<String>();
|
|
|
+ arrayList.add(value);
|
|
|
+ super.put(key, arrayList);
|
|
|
+ } else {
|
|
|
+ List<String> arrayList = (ArrayList<String>)super.get(key);
|
|
|
+ arrayList.add(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public void addInt(Object key, int value) {
|
|
|
+ Integer valueInt = new Integer(value);
|
|
|
+
|
|
|
+ if (!super.containsKey(key)) {
|
|
|
+ List<Integer> arrayList = new ArrayList<Integer>();
|
|
|
+ arrayList.add(valueInt);
|
|
|
+ super.put(key, arrayList);
|
|
|
+ } else {
|
|
|
+ List<Integer> arrayList = (ArrayList<Integer>)super.get(key);
|
|
|
+ arrayList.add(valueInt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public void addDouble(Object key, double value) {
|
|
|
+ Double valueDouble = new Double(value);
|
|
|
+
|
|
|
+ if (!super.containsKey(key)) {
|
|
|
+ List<Double> arrayList = new ArrayList<Double>();
|
|
|
+ arrayList.add(valueDouble);
|
|
|
+ super.put(key, arrayList);
|
|
|
+ } else {
|
|
|
+ List<Double> arrayList = (ArrayList<Double>)super.get(key);
|
|
|
+ arrayList.add(valueDouble);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public void addFloat(Object key, float value) {
|
|
|
+ Float valueFloat = new Float(value);
|
|
|
+
|
|
|
+ if (!super.containsKey(key)) {
|
|
|
+ List<Float> arrayList = new ArrayList<Float>();
|
|
|
+ arrayList.add(valueFloat);
|
|
|
+ super.put(key, arrayList);
|
|
|
+ } else {
|
|
|
+ List<Float> arrayList = (ArrayList<Float>)super.get(key);
|
|
|
+ arrayList.add(valueFloat);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public void addLong(Object key, long value) {
|
|
|
+ Long valueLong = new Long(value);
|
|
|
+
|
|
|
+ if (!super.containsKey(key)) {
|
|
|
+ List<Long> arrayList = new ArrayList<Long>();
|
|
|
+ arrayList.add(valueLong);
|
|
|
+ super.put(key, arrayList);
|
|
|
+ } else {
|
|
|
+ List<Long> arrayList = (ArrayList<Long>)super.get(key);
|
|
|
+ arrayList.add(valueLong);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public void addShort(Object key, short value) {
|
|
|
+ Short valueShort = new Short(value);
|
|
|
+
|
|
|
+ if (!super.containsKey(key)) {
|
|
|
+ List<Short> arrayList = new ArrayList<Short>();
|
|
|
+ arrayList.add(valueShort);
|
|
|
+ super.put(key, arrayList);
|
|
|
+ } else {
|
|
|
+ List<Short> arrayList = (ArrayList<Short>)super.get(key);
|
|
|
+ arrayList.add(valueShort);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public void addBoolean(Object key, boolean value) {
|
|
|
+ Boolean valueBoolean = new Boolean(value);
|
|
|
+
|
|
|
+ if (!super.containsKey(key)) {
|
|
|
+ List<Boolean> arrayList = new ArrayList<Boolean>();
|
|
|
+ arrayList.add(valueBoolean);
|
|
|
+ super.put(key, arrayList);
|
|
|
+ } else {
|
|
|
+ List<Boolean> arrayList = (ArrayList<Boolean>)super.get(key);
|
|
|
+ arrayList.add(valueBoolean);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public void addBigDecimal(Object key, BigDecimal value) {
|
|
|
+ if (!super.containsKey(key)) {
|
|
|
+ List<BigDecimal> arrayList = new ArrayList<BigDecimal>();
|
|
|
+ arrayList.add(value);
|
|
|
+ super.put(key, arrayList);
|
|
|
+ } else {
|
|
|
+ List<BigDecimal> arrayList = (ArrayList<BigDecimal>)super.get(key);
|
|
|
+ arrayList.add(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addFoMap(FoMap map) {
|
|
|
+ Set<?> tempSet = map.keySet();
|
|
|
+
|
|
|
+ for (Iterator<?> iterator = tempSet.iterator(); iterator.hasNext();) {
|
|
|
+ Object key = iterator.next();
|
|
|
+
|
|
|
+ if (containsKey(key)) {
|
|
|
+ int field_size = ((ArrayList<?>)get(key)).size();
|
|
|
+ if (field_size != fieldIndex) {
|
|
|
+ for (int inx = field_size; inx < fieldIndex; inx++) {
|
|
|
+ add(key, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ add(key, map.get(key));
|
|
|
+ } else {
|
|
|
+ for (int inx = 0; inx < fieldIndex; inx++) {
|
|
|
+ add(key, null);
|
|
|
+ }
|
|
|
+ add(key, map.get(key));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fieldIndex++;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addFoMap(String dataName, FoMap map) {
|
|
|
+ int entitySize = 0;
|
|
|
+
|
|
|
+ if (entityKey == null) {
|
|
|
+ entityKey = new HashMap<String, Integer>(5);
|
|
|
+ } else {
|
|
|
+ if (entityKey.containsKey(dataName)) {
|
|
|
+ entitySize = ((Integer)entityKey.get(dataName)).intValue();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<?> tempSet = map.keySet();
|
|
|
+ for (Iterator<?> iterator = tempSet.iterator(); iterator.hasNext();) {
|
|
|
+ Object key = iterator.next();
|
|
|
+ String dataKey = dataName + "." + key;
|
|
|
+ if (containsKey(dataKey)) {
|
|
|
+ int fieldSize = ((ArrayList<?>)get(dataKey)).size();
|
|
|
+ if (fieldSize != entitySize) {
|
|
|
+ for (int inx = fieldSize; inx < entitySize; inx++) {
|
|
|
+ add(dataKey, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ add(dataKey, map.get(key));
|
|
|
+ } else {
|
|
|
+ for (int inx = 0; inx < entitySize; inx++) {
|
|
|
+ add(dataKey, null);
|
|
|
+ }
|
|
|
+ add(dataKey, map.get(key));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ entityKey.put(dataName, new Integer(entitySize + 1));
|
|
|
+ }
|
|
|
+
|
|
|
+ public Object get(Object key, int index) {
|
|
|
+ return getObject(key, index);
|
|
|
+ }
|
|
|
+
|
|
|
+ public BigDecimal getBigDecimal(Object key, int index) {
|
|
|
+ Object obj = getObject(key, index);
|
|
|
+
|
|
|
+ if (obj == null)
|
|
|
+ return new BigDecimal(0.0D);
|
|
|
+ else
|
|
|
+ return (BigDecimal)obj;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean getBoolean(Object key, int index) {
|
|
|
+ Object obj = getObject(key, index);
|
|
|
+
|
|
|
+ if (obj == null) return false;
|
|
|
+
|
|
|
+ Class<? extends Object> classType = obj.getClass();
|
|
|
+ if (classType == java.lang.Boolean.class) return ((Boolean)obj).booleanValue();
|
|
|
+ if (classType == java.lang.String.class) return Boolean.parseBoolean(obj.toString());
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getDouble(Object key, int index) {
|
|
|
+ Object obj = getObject(key, index);
|
|
|
+
|
|
|
+ if (obj == null) return 0.0D;
|
|
|
+
|
|
|
+ Class<? extends Object> classType = obj.getClass();
|
|
|
+ if (classType == java.lang.Double.class) return ((Double)obj).doubleValue();
|
|
|
+ if (classType == java.lang.Float.class) return (double)((Float)obj).floatValue();
|
|
|
+ if (classType == java.lang.String.class || classType == java.math.BigDecimal.class) {
|
|
|
+ try {
|
|
|
+ return Double.parseDouble(obj.toString());
|
|
|
+ } catch (NumberFormatException nfe) {
|
|
|
+ System.out.println("FoMapList value of the key(" + key + ") type(double) does not match : It's type is not double");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0.0D;
|
|
|
+ }
|
|
|
+
|
|
|
+ public float getFloat(Object key, int index) {
|
|
|
+ Object obj = getObject(key, index);
|
|
|
+
|
|
|
+ if (obj == null) return 0.0F;
|
|
|
+
|
|
|
+ Class<? extends Object> classType = obj.getClass();
|
|
|
+ if (classType == java.lang.Float.class) return ((Float)obj).floatValue();
|
|
|
+ if (classType == java.lang.String.class || classType == java.math.BigDecimal.class) {
|
|
|
+ try {
|
|
|
+ return Float.parseFloat(obj.toString());
|
|
|
+ } catch (NumberFormatException nfe) {
|
|
|
+ System.out.println("FoMapList value of the key(" + key + ") type(float) does not match : It's type is not float");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0.0F;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getInt(Object key, int index) {
|
|
|
+ Object obj = getObject(key, index);
|
|
|
+
|
|
|
+ if (obj == null) return 0;
|
|
|
+
|
|
|
+ Class<? extends Object> classType = obj.getClass();
|
|
|
+ if (classType == java.lang.Integer.class) return ((Integer)obj).intValue();
|
|
|
+ if (classType == java.lang.Short.class) return ((Short)obj).shortValue();
|
|
|
+ if (classType == java.lang.String.class || classType == java.math.BigDecimal.class) {
|
|
|
+ try {
|
|
|
+ return Integer.parseInt(obj.toString());
|
|
|
+ } catch (NumberFormatException nfe) {
|
|
|
+ System.out.println("FoMapList value of the key(" + key + ") type(int) does not match : It's type is not int");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public long getLong(Object key, int index) {
|
|
|
+ Object obj = getObject(key, index);
|
|
|
+
|
|
|
+ if (obj == null) return 0L;
|
|
|
+
|
|
|
+ Class<? extends Object> classType = obj.getClass();
|
|
|
+ if (classType == java.lang.Long.class) return ((Long)obj).longValue();
|
|
|
+ if (classType == java.lang.Integer.class) return (long)((Integer)obj).intValue();
|
|
|
+ if (classType == java.lang.Short.class) return (long)((Short)obj).shortValue();
|
|
|
+ if (classType == java.lang.String.class || classType == java.math.BigDecimal.class) {
|
|
|
+ try {
|
|
|
+ return Long.parseLong(obj.toString());
|
|
|
+ } catch (NumberFormatException nfe) {
|
|
|
+ System.out.println("FoMapList value of the key(" + key + ") type(long) does not match : It's type is not long");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+
|
|
|
+ public FoMap getFoMap(int index) {
|
|
|
+ FoMap map = new FoMap();
|
|
|
+ Set<?> tempSet = super.keySet();
|
|
|
+ String key;
|
|
|
+ Object obj;
|
|
|
+
|
|
|
+ for (Iterator<?> iterator = tempSet.iterator(); iterator.hasNext(); map.put(key, obj)) {
|
|
|
+ key = iterator.next().toString();
|
|
|
+ obj = getObject(key, index);
|
|
|
+ }
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ public FoMap getFoMap(String dataName, int index) {
|
|
|
+ FoMap map = new FoMap(dataName);
|
|
|
+ String prefix = dataName + ".";
|
|
|
+ Set<?> tempSet = super.keySet();
|
|
|
+
|
|
|
+ for (Iterator<?> iterator = tempSet.iterator(); iterator.hasNext();) {
|
|
|
+ String key = iterator.next().toString();
|
|
|
+ int key_index = key.indexOf(".");
|
|
|
+ String realKey = key.substring(key_index + 1);
|
|
|
+ if (key.startsWith(prefix)) {
|
|
|
+ Object obj = getObject(key, index);
|
|
|
+ map.put(realKey, obj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Object getObject(Object key, int index) {
|
|
|
+ Object obj = null;
|
|
|
+ List<?> arrayList = (ArrayList<?>)super.get(key);
|
|
|
+
|
|
|
+ if (arrayList == null) return null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (index >= arrayList.size()) return null;
|
|
|
+ obj = arrayList.get(index);
|
|
|
+ } catch (IndexOutOfBoundsException iobe) {
|
|
|
+ System.out.println("FoMapList index(" + index + ") in FoMapList(" + name + ") is out of Bounds.");
|
|
|
+ }
|
|
|
+
|
|
|
+ return obj;
|
|
|
+ }
|
|
|
+
|
|
|
+ public short getShort(Object key, int index) {
|
|
|
+ Object obj = getObject(key, index);
|
|
|
+
|
|
|
+ if (obj == null) return 0;
|
|
|
+
|
|
|
+ Class<? extends Object> classType = obj.getClass();
|
|
|
+ if (classType == java.lang.Short.class) return ((Short)obj).shortValue();
|
|
|
+ if (classType == java.lang.String.class || classType == java.math.BigDecimal.class) {
|
|
|
+ try {
|
|
|
+ return Short.parseShort(obj.toString());
|
|
|
+ } catch (NumberFormatException nfe) {
|
|
|
+ System.out.println("FoMapList value of key(" + key + ")" + " type(short) does not match : It's type is not short");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getString(Object key, int index) {
|
|
|
+ Object obj = getObject(key, index);
|
|
|
+ if (obj == null) {
|
|
|
+ return "";
|
|
|
+ } else {
|
|
|
+ return obj.toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public int keySize(Object key) {
|
|
|
+ if (super.containsKey(key)) {
|
|
|
+ return ((ArrayList<?>)super.get(key)).size();
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Object remove(Object key, int index) {
|
|
|
+ if (super.containsKey(key)) {
|
|
|
+ return ((ArrayList<?>)super.get(key)).remove(index);
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public int size() {
|
|
|
+ Set<?> tempSet = super.keySet();
|
|
|
+ Iterator<?> iterator = tempSet.iterator();
|
|
|
+ if (iterator.hasNext()) {
|
|
|
+ String key = iterator.next().toString();
|
|
|
+ return ((ArrayList<?>)super.get(key)).size();
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|