我有以下课程KeyObj
public class KeyObject {
private byte[] P1;
private byte[] P2;
private byte[] P3;
}
我想将此类的对象放入ConcurrentSkipListMap
我对如何编写比较器感到困惑,以便可以进行范围查询。即如果P1
给定那么它返回我p2 and p3
。像下面的东西
KeyObject fromKey = new KeyObject(K1.P1, P2_MIN_VALUE, P3_MIN_VALUE);
KeyObject toKey = new KeyObject(K2.P1, P2_MAX_VALUE, P3_MAX_VALUE);
ConcurrentNavigableMap<KeyObject, Object> subview = table.submap(fromkey, toKey);
for (ConcurrentSkipListMap.Entry<KeyObject, Object> entry : subView.entrySet()) {
...
}
或者
KeyObject fromKey = new KeyObject(K1.P1, K1.P2, P3_MIN_VALUE);
KeyObject toKey = new KeyObject(K2.P2, K2.P2, P3_MAX_VALUE);
ConcurrentNavigableMap<KeyObject, Object> subview = table.submap(fromkey, toKey);
for (ConcurrentSkipListMap.Entry<KeyObject, Object> entry : subView.entrySet()) {
...
}