package com.quickhot.utilities; import java.util.ArrayList; import java.util.concurrent.ConcurrentHashMap; public final class TriKey{ private X x; private Y y; private Z z; private ConcurrentHashMap > xList = new ConcurrentHashMap<>(); private ConcurrentHashMap > yList = new ConcurrentHashMap<>(); private ConcurrentHashMap > zList = new ConcurrentHashMap<>(); public void put(X x,Y y,Z z,V v){ ArrayList avialable = get(x,y,z); if (null != avialable){ xList.get(x).removeAll(avialable); yList.get(y).removeAll(avialable); zList.get(z).removeAll(avialable); } if (xList.containsKey(x)){ xList.get(x).add(v); } else { ArrayList xArrList = new ArrayList<>(); xArrList.add(v); xList.put(x,xArrList); } if (yList.containsKey(y)){ yList.get(y).add(v); } else { ArrayList yArrList = new ArrayList<>(); yArrList.add(v); yList.put(y,yArrList); } if (zList.containsKey(z)){ zList.get(z).add(v); } else { ArrayList zArrList = new ArrayList<>(); zArrList.add(v); zList.put(z,zArrList); } } public ArrayList get(X x, Y y, Z z){ ArrayList xs = xList.get(x); ArrayList ys = yList.get(y); ArrayList zs = zList.get(z); if(null==xs || null==ys || null==zs) return null; ArrayList result = new ArrayList<>(xs); result.retainAll(ys); result.retainAll(zs); return result; } }
使用方法
public void run(ApplicationArguments args) throws Exception {
TriKey testTriKey = new TriKey();
testTriKey.put(0,0,0,"坐标000");
testTriKey.put(0,0,0,"第二坐标000");
testTriKey.put(0,0,1d,"坐标001");
testTriKey.put(0,"b",0,"坐标010");
testTriKey.put(0,"b",0,"坐标010b");
testTriKey.put(0,1,1,"坐标011");
testTriKey.put(1,0,0,100);
ArrayList value = testTriKey.get(0, "b", 0);
logger.info(value.toString());
ArrayList value1 = testTriKey.get(0, 1, 1);
logger.info(value1.toString());
ArrayList value2 = testTriKey.get(0, 0, 0);
logger.info(value2.toString());
}



