|
|
@@ -17,15 +17,17 @@
|
|
|
package com.jfinal.plugin.activerecord;
|
|
|
|
|
|
import java.util.Collection;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.HashSet;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
+import java.util.TreeMap;
|
|
|
+import java.util.TreeSet;
|
|
|
|
|
|
-@SuppressWarnings({"rawtypes", "unchecked"})
|
|
|
+/**
|
|
|
+ * CaseInsensitiveContainerFactory.
|
|
|
+ */
|
|
|
public class CaseInsensitiveContainerFactory implements IContainerFactory {
|
|
|
|
|
|
- private static boolean toLowerCase = false;
|
|
|
+ private static Boolean toLowerCase = null;
|
|
|
|
|
|
public CaseInsensitiveContainerFactory() {
|
|
|
}
|
|
|
@@ -35,22 +37,23 @@ public class CaseInsensitiveContainerFactory implements IContainerFactory {
|
|
|
}
|
|
|
|
|
|
public Map<String, Object> getAttrsMap() {
|
|
|
- return new CaseInsensitiveMap();
|
|
|
+ return new CaseInsensitiveMap<Object>();
|
|
|
}
|
|
|
|
|
|
public Map<String, Object> getColumnsMap() {
|
|
|
- return new CaseInsensitiveMap();
|
|
|
+ return new CaseInsensitiveMap<Object>();
|
|
|
}
|
|
|
|
|
|
public Set<String> getModifyFlagSet() {
|
|
|
return new CaseInsensitiveSet();
|
|
|
}
|
|
|
|
|
|
- private static Object convertCase(Object key) {
|
|
|
- if (key instanceof String) {
|
|
|
- return toLowerCase ? ((String)key).toLowerCase() : ((String)key).toUpperCase();
|
|
|
+ private static String convertCase(String key) {
|
|
|
+ if (toLowerCase != null) {
|
|
|
+ return toLowerCase ? key.toLowerCase() : key.toUpperCase();
|
|
|
+ } else {
|
|
|
+ return key;
|
|
|
}
|
|
|
- return key;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -60,25 +63,21 @@ public class CaseInsensitiveContainerFactory implements IContainerFactory {
|
|
|
* 3:外部类CaseInsensitiveContainerFactory 需要 implements Serializable 才能被序列化
|
|
|
* 4:可以使用静态内部类来实现内部类的序列化,而非让外部类实现 implements Serializable
|
|
|
*/
|
|
|
- public static class CaseInsensitiveSet extends HashSet {
|
|
|
-
|
|
|
- private static final long serialVersionUID = 102410961064096233L;
|
|
|
+ public static class CaseInsensitiveSet extends TreeSet<String> {
|
|
|
|
|
|
- public boolean add(Object e) {
|
|
|
- return super.add(convertCase(e));
|
|
|
- }
|
|
|
+ private static final long serialVersionUID = 6236541338642353211L;
|
|
|
|
|
|
- public boolean remove(Object e) {
|
|
|
- return super.remove(convertCase(e));
|
|
|
+ public CaseInsensitiveSet() {
|
|
|
+ super(String.CASE_INSENSITIVE_ORDER);
|
|
|
}
|
|
|
|
|
|
- public boolean contains(Object e) {
|
|
|
- return super.contains(convertCase(e));
|
|
|
+ public boolean add(String e) {
|
|
|
+ return super.add(convertCase(e));
|
|
|
}
|
|
|
|
|
|
- public boolean addAll(Collection c) {
|
|
|
+ public boolean addAll(Collection<? extends String> c) {
|
|
|
boolean modified = false;
|
|
|
- for (Object o : c) {
|
|
|
+ for (String o : c) {
|
|
|
if (super.add(convertCase(o))) {
|
|
|
modified = true;
|
|
|
}
|
|
|
@@ -87,31 +86,23 @@ public class CaseInsensitiveContainerFactory implements IContainerFactory {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static class CaseInsensitiveMap extends HashMap {
|
|
|
-
|
|
|
- private static final long serialVersionUID = 6843981594457576677L;
|
|
|
+ public static class CaseInsensitiveMap<V> extends TreeMap<String, V> {
|
|
|
|
|
|
- public Object get(Object key) {
|
|
|
- return super.get(convertCase(key));
|
|
|
- }
|
|
|
+ private static final long serialVersionUID = 7482853823611007217L;
|
|
|
|
|
|
- public boolean containsKey(Object key) {
|
|
|
- return super.containsKey(convertCase(key));
|
|
|
+ public CaseInsensitiveMap() {
|
|
|
+ super(String.CASE_INSENSITIVE_ORDER);
|
|
|
}
|
|
|
|
|
|
- public Object put(Object key, Object value) {
|
|
|
+ public V put(String key, V value) {
|
|
|
return super.put(convertCase(key), value);
|
|
|
}
|
|
|
|
|
|
- public void putAll(Map m) {
|
|
|
- for (Map.Entry e : (Set<Map.Entry>)(m.entrySet())) {
|
|
|
+ public void putAll(Map<? extends String, ? extends V> map) {
|
|
|
+ for (Map.Entry<? extends String, ? extends V> e : map.entrySet()) {
|
|
|
super.put(convertCase(e.getKey()), e.getValue());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- public Object remove(Object key) {
|
|
|
- return super.remove(convertCase(key));
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|