當前位置: 首頁>>代碼示例>>Java>>正文


Java SortedMap.subMap方法代碼示例

本文整理匯總了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;
}
 
開發者ID:P1sec,項目名稱:SigFW,代碼行數:12,代碼來源:DiameterFirewallConfig.java

示例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;
}
 
開發者ID:P1sec,項目名稱:SigFW,代碼行數:33,代碼來源:DiameterFirewallConfig.java

示例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;
}
 
開發者ID:P1sec,項目名稱:SigFW,代碼行數:33,代碼來源:SS7FirewallConfig.java

示例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();
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:16,代碼來源:DerivedCollectionGenerators.java

示例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());
}
 
開發者ID:MottoX,項目名稱:SkipList,代碼行數:28,代碼來源:SkipListMapTest.java

示例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);
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:10,代碼來源:ScanUtils.java


注:本文中的java.util.SortedMap.subMap方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。