2013-03-25 44 views
0

我有下面的类KeyObjConcurrentSkipListMap和多列比较

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()) { 
... 
} 

OR

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()) { 
... 
} 

回答

0

使用相当或比较接口和定义方法的CompareTo或方式比较他们希望他们的行为。

Ajay