@Override
 NavigableMap<K, V> createSubMap(SortedMap<K, V> sortedMap, K firstExclusive, K lastExclusive) {
   NavigableMap<K, V> map = (NavigableMap<K, V>) sortedMap;
   if (from == Bound.NO_BOUND && to == Bound.INCLUSIVE) {
     return map.headMap(lastInclusive, true);
   } else if (from == Bound.EXCLUSIVE && to == Bound.NO_BOUND) {
     return map.tailMap(firstExclusive, false);
   } else if (from == Bound.EXCLUSIVE && to == Bound.EXCLUSIVE) {
     return map.subMap(firstExclusive, false, lastExclusive, false);
   } else if (from == Bound.EXCLUSIVE && to == Bound.INCLUSIVE) {
     return map.subMap(firstExclusive, false, lastInclusive, true);
   } else if (from == Bound.INCLUSIVE && to == Bound.INCLUSIVE) {
     return map.subMap(firstInclusive, true, lastInclusive, true);
   } else {
     return (NavigableMap<K, V>) super.createSubMap(map, firstExclusive, lastExclusive);
   }
 }
Exemplo n.º 2
0
 private static Map<String, NavigableMap<String, String>> partitioning(
     NavigableMap<String, String> map) {
   assert map != null;
   Map<String, NavigableMap<String, String>> results =
       new TreeMap<String, NavigableMap<String, String>>();
   while (map.isEmpty() == false) {
     String name = map.firstKey();
     int index = name.indexOf('.');
     if (index >= 0) {
       name = name.substring(0, index);
     }
     String first = name + '.';
     String last = name + (char) ('.' + 1);
     NavigableMap<String, String> partition = new TreeMap<String, String>();
     for (Map.Entry<String, String> entry : map.subMap(first, last).entrySet()) {
       String key = entry.getKey();
       partition.put(key.substring(name.length() + 1), entry.getValue());
     }
     results.put(name, partition);
     map.remove(name);
     map.subMap(first, last).clear();
   }
   return results;
 }
Exemplo n.º 3
0
 public NavigableMap<String, String> getJndiEnvironmentParameters() {
   return parameters.subMap("jndi-", false, "jndi.", false);
 }
 public void testSubMap_K_B_K_B() {
   NavigableMap<String, Integer> map = create();
   NavigableMap<String, Integer> subMap = map.subMap("a", true, "b", false);
   assertTrue(subMap instanceof SynchronizedNavigableMap);
   assertSame(mutex, ((SynchronizedNavigableMap<String, Integer>) subMap).mutex);
 }
 public void testSubMap_K_K() {
   NavigableMap<String, Integer> map = create();
   SortedMap<String, Integer> subMap = map.subMap("a", "b");
   assertTrue(subMap instanceof SynchronizedSortedMap);
   assertSame(mutex, ((SynchronizedSortedMap<String, Integer>) subMap).mutex);
 }