71 lines
1.8 KiB
Java
71 lines
1.8 KiB
Java
package cn.config.mapping;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Comparator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.TreeMap;
|
|
|
|
/**
|
|
*
|
|
* @author yangsong
|
|
* @date 2014/12/14
|
|
*/
|
|
public class URIMappingCache {
|
|
private static URIMappingCache instance = null;
|
|
|
|
private Map<URIMappingKey,URIMappingValue> mappingStore = new TreeMap<URIMappingKey,URIMappingValue>(new Comparator<URIMappingKey>() {
|
|
public int compare(URIMappingKey o1, URIMappingKey o2) {
|
|
if (o1 == null && o2 == null) return 0;
|
|
if (o1 == null && o2 != null) return 1;
|
|
if (o1 != null && o2 == null) return -1;
|
|
if (o1.getUri() == null && o2.getUri() == null) return 0;
|
|
if (o1.getUri() == null && o2.getUri() != null) return 1;
|
|
if (o1.getUri() != null && o2.getUri() == null) return -1;
|
|
int r = o1.getUri().compareTo(o2.getUri());
|
|
if(r==0){
|
|
if (o1.getHttpMethod() == null && o2.getHttpMethod() == null) return 0;
|
|
if (o1.getHttpMethod() == null && o2.getHttpMethod() != null) return 1;
|
|
if (o1.getHttpMethod() != null && o2.getHttpMethod() == null) return -1;
|
|
r = o1.getHttpMethod().compareTo(o2.getHttpMethod());
|
|
}
|
|
return r;
|
|
}
|
|
});
|
|
|
|
|
|
private URIMappingCache(){
|
|
|
|
}
|
|
|
|
public static synchronized URIMappingCache getInstance(){
|
|
if(instance == null){
|
|
instance = new URIMappingCache();
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
public void put(URIMappingKey key,URIMappingValue value){
|
|
mappingStore.put(key, value);
|
|
}
|
|
|
|
public URIMappingValue get(URIMappingKey key){
|
|
return mappingStore.get(key);
|
|
}
|
|
|
|
public void clear(){
|
|
mappingStore.clear();
|
|
}
|
|
|
|
public List<URIMappingKey> listURIMappingKeys(){
|
|
List<URIMappingKey> keyList = new ArrayList<URIMappingKey>();
|
|
keyList.addAll(mappingStore.keySet());
|
|
return keyList;
|
|
}
|
|
|
|
public Map<URIMappingKey, URIMappingValue> getMappingStore() {
|
|
return mappingStore;
|
|
}
|
|
|
|
}
|