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


Java TreeMap.headMap方法代碼示例

本文整理匯總了Java中java.util.TreeMap.headMap方法的典型用法代碼示例。如果您正苦於以下問題:Java TreeMap.headMap方法的具體用法?Java TreeMap.headMap怎麽用?Java TreeMap.headMap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.TreeMap的用法示例。


在下文中一共展示了TreeMap.headMap方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testHeadMapContents

import java.util.TreeMap; //導入方法依賴的package包/類
/**
 * headMap returns map with keys in requested range
 */
public void testHeadMapContents() {
    TreeMap map = map5();
    NavigableMap sm = map.headMap(four, false);
    assertTrue(sm.containsKey(one));
    assertTrue(sm.containsKey(two));
    assertTrue(sm.containsKey(three));
    assertFalse(sm.containsKey(four));
    assertFalse(sm.containsKey(five));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(one, k);
    k = (Integer)(i.next());
    assertEquals(two, k);
    k = (Integer)(i.next());
    assertEquals(three, k);
    assertFalse(i.hasNext());
    sm.clear();
    assertTrue(sm.isEmpty());
    assertEquals(2, map.size());
    assertEquals(four, map.firstKey());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:TreeMapTest.java

示例2: findPath2

import java.util.TreeMap; //導入方法依賴的package包/類
private ASTPath findPath2 (List<ASTItem> path, int offset) {
    TreeMap<Integer,ASTItem> childrenMap = getChildrenMap ();
    SortedMap<Integer,ASTItem> headMap = childrenMap.headMap (new Integer (offset + 1));
    if (headMap.isEmpty ())
        return ASTPath.create (path);
    Integer key = headMap.lastKey ();
    ASTItem item = childrenMap.get (key);
    ASTPath path2 =  item.findPath (path, offset);
    if (path2 == null)
        return ASTPath.create (path);
    return path2;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:13,代碼來源:ASTItem.java

示例3: getHeadMap

import java.util.TreeMap; //導入方法依賴的package包/類
public void getHeadMap(TreeMap<String, String> maps, String firstKey,boolean isInclusive) {
    SortedMap<String,String> subMaps =  maps.headMap(firstKey, isInclusive);
    Iterator iterator = subMaps.entrySet().iterator();
    System.out.println(firstKey + "以前" + "所有的Map如下");
    while (iterator.hasNext()) {
        Map.Entry<String, String> entry = (Map.Entry<String, String>) iterator.next();
        System.out.print("key = " + entry.getKey());
        System.out.println(" value = " + entry.getValue());
    }
}
 
開發者ID:byhieg,項目名稱:JavaTutorial,代碼行數:11,代碼來源:TreeMapExample.java

示例4: getTailMap

import java.util.TreeMap; //導入方法依賴的package包/類
public void getTailMap(TreeMap<String, String> maps, String firstKey,boolean isInclusive) {
    SortedMap<String,String> subMaps =  maps.headMap(firstKey, isInclusive);
    Iterator iterator = subMaps.entrySet().iterator();
    System.out.println(firstKey + "以後" + "所有的Map如下");
    while (iterator.hasNext()) {
        Map.Entry<String, String> entry = (Map.Entry<String, String>) iterator.next();
        System.out.print("key = " + entry.getKey());
        System.out.println(" value = " + entry.getValue());
    }
}
 
開發者ID:byhieg,項目名稱:JavaTutorial,代碼行數:11,代碼來源:TreeMapExample.java

示例5: validate

import java.util.TreeMap; //導入方法依賴的package包/類
static Map<String, Object> validate(int version, Map<String, TreeMap<Integer, SettingsDescription>> settings,
        Map<String, String> importedSettings, boolean useDefaultValues) {

    Map<String, Object> validatedSettings = new HashMap<>();
    for (Map.Entry<String, TreeMap<Integer, SettingsDescription>> versionedSetting : settings.entrySet()) {

        // Get the setting description with the highest version lower than or equal to the
        // supplied content version.
        TreeMap<Integer, SettingsDescription> versions = versionedSetting.getValue();
        SortedMap<Integer, SettingsDescription> headMap = versions.headMap(version + 1);

        // Skip this setting if it was introduced after 'version'
        if (headMap.isEmpty()) {
            continue;
        }

        Integer settingVersion = headMap.lastKey();
        SettingsDescription desc = versions.get(settingVersion);

        // Skip this setting if it is no longer used in 'version'
        if (desc == null) {
            continue;
        }

        String key = versionedSetting.getKey();

        boolean useDefaultValue;
        if (!importedSettings.containsKey(key)) {
            Timber.v("Key \"%s\" wasn't found in the imported file.%s",
                    key,
                    (useDefaultValues) ? " Using default value." : "");

            useDefaultValue = useDefaultValues;
        } else {
            String prettyValue = importedSettings.get(key);
            try {
                Object internalValue = desc.fromPrettyString(prettyValue);
                validatedSettings.put(key, internalValue);
                useDefaultValue = false;
            } catch (InvalidSettingValueException e) {
                Timber.v("Key \"%s\" has invalid value \"%s\" in imported file. %s",
                        key,
                        prettyValue,
                        (useDefaultValues) ? "Using default value." : "Skipping.");

                useDefaultValue = useDefaultValues;
            }
        }

        if (useDefaultValue) {
            Object defaultValue = desc.getDefaultValue();
            validatedSettings.put(key, defaultValue);
        }
    }

    return validatedSettings;
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:58,代碼來源:Settings.java


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