- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不明白怎么办NavigableMap.floorEntry()
和ceiling Entry()
工作。
Oracle 只是简单地写了 ceilingEntry(key) :
Returns a key-value mapping associated with the least key greater than or equal to the given key, or null if there is no such key.
通过实验,我了解到如果我定义 NavigableMap
使用整数键 ( NavigableMap<Integer, Anything>
), floorEntry(keyArg)
和ceilingEntry(keyArg)
始终返回具有给定参数 (keyArg)*
的条目
我明白 - 它的工作原理类似于 floor and ceiling functions in math :这些函数返回最接近的整数(如果给定的不是整数参数),给定整数参数,它们总是返回这个给定论据。
我认为(基于数学中的下限/条目定义)下面的代码片段将返回 "integer"
1.0
, 2.0
等
双2.0
不是整数。但是ceilingEntry(keyArg)
对于整数键没有用,如果它也不适用于双键(也返回其参数键)那么它是如何使用的,它的用途和工作用例是什么?
NavigableMap<Double, String> m = new TreeMap<>();
m.put(1.3, "hey");
m.put(1.5, "hey2");
m.put(1.62, "hey3"); // not this
m.put(1.6, "hey3"); // argument given to ceilingEntry
m.put(1.68, "hey3"); // not this
m.put(1.7, "hey4"); // not this
m.put(2.0, "hey4"); // not this
m.put(1.0, "hey4");
m.put(3d, "hey4"); // not this
m.put(0d, "hey4");
// WHAT THEN ???
System.out.println(m.ceilingEntry(1.6)); // OUTPUT: 1.6=hey3
// I guess, to get something different from argument
//I shall give something not equal to any key as argument
System.out.println(m.ceilingEntry(1.601)); // 1.62=hey3
我明白了。无论键类型是什么,如果映射中已经存在这样的键,ceilingEntry 将简单地返回其参数。
仅当给定参数不存在于映射中(作为键)时,它才会返回任何不同的内容。在这种情况下,ceilingEntry将返回映射中最接近的键(在ceilingEntry的情况下 - 按升序搜索(朝向正无穷大))。
所以它与纯数学完全不同 floor/ceiling
- java 不寻找最接近的整数,java 正在寻找最接近的现有 key 。 Java 并不关心这个最接近的键是整数还是 0.000786
(最接近 0.000785
或 0.7
等参数)
最佳答案
floorEntry()
和 ceilingEntry()
的工作方式类似于 Math.floor()
和 Math.ceiling()
按以下方式:
数学:
Integers:
1
2 <-- floor(2.5) = 2
<-- Key: 2.5
3 <-- ceil(2.5) = 3
4
同样,NavigableMap:
Entries:
Alice
Barry <-- floor(Bert) = Barry
<-- Key: Bert
Constance <-- ceil(Bert) = Constance
Dan
关于java - NavigableMap.ceiling Entry() 到底是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48507424/
我正在尝试使用自定义比较器实现 NavigableMap,该比较器基于值而不是键进行比较。我对 java 和编码非常了解,所以如果我的术语不正确或代码很糟糕,请原谅我!我尝试找到类似的问题来尝试复制解
java.util.Collections 目前提供以下实用方法来创建 synchronized各种集合接口(interface)的包装器: synchronizedCollection(Collec
我希望能够根据文件输入 map 的日期对文件进行排序。键是日期,值是在相应日期添加的 n 个文件的列表。但是,我需要能够一次将一个文件添加到列表中 - 但我陷入了语法困境。如何从 Map.put()
在 Java 中,NavigableMap 有一个方法 subMap(),它返回 map 部分的 View ,其键范围从 fromKey 到到 key 。在文档中,它说返回的 map 受此 map 支
这是 my previous question 的后续问题. 我正在尝试实现 NavigableMap定义为NavigableMap 。我需要这张 map 作为我的缓存。每 5 分钟我刷新一次 Nav
有什么理由使用SortedMap而不是 NavigableMap ,除了JVM版本? (NavigableMap 从 1.6 开始才出现;SortedMap 从 1.2 开始出现) 我正在尝试找到具有
在 Java 1.6 中,NavigableMap (和 NavigableSet )接口(interface)被引入和 TreeMap已更新以实现新界面。在其他方面,NavigableMap 可用于
我不明白怎么办NavigableMap.floorEntry()和ceiling Entry()工作。 Oracle 只是简单地写了 ceilingEntry(key) : Returns a key
我有一个具有以下格式的 NavigableMap: NavigableMap mymap = new ConcurrentSkipListMap (); //.......some operati
我需要有效的ImmutableNavigableListMultimap哪里HasOffset看起来像: interface HasOffset { public int getOffset()
我是 Java 初学者。我有一个方法如下: public void time_filter(Long t1, Long t2){ NavigableMap time_map = new Tr
我需要将可导航 map 转换为二维字符串数组。下面给出的是来自 answer 的代码回答我之前的一个问题。 NavigableMap map = new TreeMap(); map.
如果我有一个已经形成的NavigableMap。 floorEntry() 操作执行所需的时间是多少?是 O(1) 还是 O(logn)? 例如: 如果我有一个具有 n 个间隔的 NavigableM
关于 Java TreeMap 方法(或 NavigableMap 接口(interface)): public SortedMap headMap(K toKey) public Navigable
有什么方法可以在 Java 中循环 NavigableMap 吗?我想访问 NavigableMap 中的所有项目。 最佳答案 与循环任何集合的方式相同,使用迭代器或 for-each 循环。 Nav
java.util.Collections 有几个 unmodifiable 方法,它们通过将集合包装在禁止突变操作的装饰器中来提供不可修改的 Collection View 。 Java 6 添加了
LinkedHashMap public class LinkedHashMap extends HashMap implements Map 1、 Map接口的哈希表和链接列表实现,具
您能解释一下这段代码吗? TreeMap myMap = new TreeMap(); myMap.put("a", 50); myMap.put("b", 60);
我已经实现了几次 NavigableMap,但它似乎总是比应该做的多一些。虽然它是一个非常大的接口(interface),但诸如 java.util.AbstractMap 和 Guava 的 For
我正在寻找一种缓存设施,可以在预定义的间隔到期时删除旧条目(如 Guava Cache),但内部使用 NavigableMap 接口(interface)。 有类似的事情吗? 最佳答案 我不相信有类似
我是一名优秀的程序员,十分优秀!