本文整理汇总了Java中java.util.SortedMap.subMap方法的典型用法代码示例。如果您正苦于以下问题:Java SortedMap.subMap方法的具体用法?Java SortedMap.subMap怎么用?Java SortedMap.subMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.SortedMap
的用法示例。
在下文中一共展示了SortedMap.subMap方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filterPrefix
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* Returns sub map from SortedMap, where keys match the prefix
*/
private static <V> SortedMap<String, V> filterPrefix(SortedMap<String,V> baseMap, String prefix) {
if(prefix.length() > 0) {
char nextLetter = (char)(prefix.charAt(prefix.length() -1) + 1);
String end = prefix.substring(0, prefix.length()-1) + nextLetter;
return baseMap.subMap(prefix, end);
}
return baseMap;
}
示例2: simpleWildcardCheck
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* Returns true if value is found in SortedMap, including also simple wildcard *
*/
private static <V> boolean simpleWildcardCheck(SortedMap<String,V> baseMap, String value) {
if (value == null) {
return false;
}
if (baseMap.get(value) != null) {
//System.out.println("======= " + value);
return true;
} else if (value.length() > 0){
String v = value;
v = v.substring(0, v.length() - 1);
while (v.length() > 0) {
char nextLetter = (char)(v.charAt(v.length() -1) + 1);
String end = v.substring(0, v.length()-1) + nextLetter;
SortedMap<String, V> b = baseMap.subMap(v, end);
for (String key : b.keySet()) {
if ((key.length() == v.length() + 1) && key.endsWith("*")) {
//System.out.println("======= " + key);
return true;
}
}
v = v.substring(0, v.length() - 1);
}
}
return false;
}
示例3: simpleWildcardKeyFind
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* Returns Key if value is found in SortedMap, including also simple wildcard *
*/
public static <V> String simpleWildcardKeyFind(SortedMap<String,V> baseMap, String value) {
if (value == null) {
return null;
}
if (baseMap.get(value) != null) {
//System.out.println("======= " + value);
return value;
} else if (value.length() > 0){
String v = value;
v = v.substring(0, v.length() - 1);
while (v.length() > 0) {
char nextLetter = (char)(v.charAt(v.length() -1) + 1);
String end = v.substring(0, v.length()-1) + nextLetter;
SortedMap<String, V> b = baseMap.subMap(v, end);
for (String key : b.keySet()) {
if ((key.length() == v.length() + 1) && key.endsWith("*")) {
//System.out.println("======= " + key);
return key;
}
}
v = v.substring(0, v.length() - 1);
}
}
return null;
}
示例4: createSubMap
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* Calls the smallest subMap overload that filters out the extreme values. This method is
* overridden in NavigableMapTestSuiteBuilder.
*/
SortedMap<K, V> createSubMap(SortedMap<K, V> map, K firstExclusive, K lastExclusive) {
if (from == Bound.NO_BOUND && to == Bound.EXCLUSIVE) {
return map.headMap(lastExclusive);
} else if (from == Bound.INCLUSIVE && to == Bound.NO_BOUND) {
return map.tailMap(firstInclusive);
} else if (from == Bound.INCLUSIVE && to == Bound.EXCLUSIVE) {
return map.subMap(firstInclusive, lastExclusive);
} else {
throw new IllegalArgumentException();
}
}
示例5: testSubMap
import java.util.SortedMap; //导入方法依赖的package包/类
@Test
public void testSubMap() throws Exception {
map.put(2, "2");
map.put(-5, "-5");
map.put(12, "12");
map.put(-22, "-22");
map.put(7, "7");
map.put(10, "10");
map.put(11, "11");
map.put(32, "32");
SortedMap<Integer, String> subMap = map.subMap(2, 11);
Assert.assertEquals(3, subMap.size());
Assert.assertTrue(subMap.containsKey(2));
Assert.assertTrue(subMap.containsKey(7));
Assert.assertTrue(subMap.containsKey(10));
Assert.assertEquals(2, (int) subMap.firstKey());
Assert.assertEquals(10, (int) subMap.lastKey());
SortedMap<Integer, String> subSubMap = subMap.subMap(3, 10);
Assert.assertEquals(1, subSubMap.size());
Assert.assertTrue(subMap.containsKey(7));
Assert.assertEquals(7, (int) subSubMap.firstKey());
Assert.assertEquals(7, (int) subSubMap.lastKey());
}
示例6: subMap
import java.util.SortedMap; //导入方法依赖的package包/类
private static SortedMap<IMKey, RegionEntry> subMap(final SortedMap<IMKey, RegionEntry> map,
final IMKey from, final boolean f, final IMKey to, final boolean t) {
if (map instanceof NavigableMap) {
return ((NavigableMap<IMKey, RegionEntry>) map).subMap(from, f, to, t);
} else {
/* TODO: need to check and use include from/to key as well, if specified */
return map.subMap(from, to);
}
}