本文整理汇总了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());
}
示例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;
}
示例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());
}
}
示例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());
}
}
示例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;
}