com.silentgo.orm.common.CaseInsensitiveHashMap Maven / Gradle / Ivy
package com.silentgo.orm.common;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
/**
* Project : silentgo
* com.silentgo.orm.common
*
* @author teddyzhu
*
* Created by teddyzhu on 16/9/21.
*/
public class CaseInsensitiveHashMap extends LinkedHashMap {
private final Map lowerCaseMap = new HashMap<>();
@Override
public boolean containsKey(Object key) {
Object realKey = lowerCaseMap.get(key.toString().toLowerCase(Locale.ENGLISH));
return super.containsKey(realKey);
}
@Override
public Object get(Object key) {
Object realKey = lowerCaseMap.get(key.toString().toLowerCase(Locale.ENGLISH));
return super.get(realKey);
}
@Override
public Object put(String key, Object value) {
Object oldKey = lowerCaseMap.put(key.toLowerCase(Locale.ENGLISH), key);
Object oldValue = super.remove(oldKey);
super.put(key, value);
return oldValue;
}
@Override
public void putAll(Map extends String, ?> m) {
for (Map.Entry extends String, ?> entry : m.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
this.put(key, value);
}
}
@Override
public Object remove(Object key) {
Object realKey = lowerCaseMap.remove(key.toString().toLowerCase(Locale.ENGLISH));
return super.remove(realKey);
}
}