2013-03-25 77 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