@Component
public class DataStore{
private Map<String,Datum> dataMap = new ConcurrentHashMap<>(1024);
public void put(String key,Datum value){
dataMap.put(key,value);
}
public Datum remove(String key){
return dataMap.remove(key);
}
public Set<String> keys(){
return dataMap.keySet();
}
public Datum get(String key){
return dataMap.get(key);
}
public boolean contains(String key){
return dataMap.containsKey(key);
}
public Map<String,Datum> batchGet(List<String> keys){
Map<String,Datum> map = new HashMap<>(128);
for(String key:keys){
Datum datum = dataMap.get(key);
if(datum == null){continue;}
map.put(key,datum);
}
return map;
}
public int getInstanceCount(){
int count = 0;
for(Map.Entry<String,Datum> entry:dataMap.entrySet()){
try{
Datum instancesDatum = entry.getValue();
if(instanceDatum.value instanceof Instances){
count+=((Instances)instancesDatum.value).getInstanceList().size();
}
}catch(Exception e){}
return count;
}
}
public Map<String,Datum> getDataMap(){
return dataMap;
}
}
|