我评估我的项目从使用迁移乔达时间到java.time包中的Java 8.在Joda-Time,我大量使用了这门Interval课程.我在java.time中找不到这样的东西.
有类似的课吗?
我不知道这是否可行,但我正在尝试制作一个Hashtable,其中Interval是一个具有2个整数/长值,开始和结束的类,我想做这样的事情:
Hashtable<Interval, WhateverObject> test = new Hashtable<Interval, WhateverObject>();
test.put(new Interval(100, 200), new WhateverObject());
test.get(new Interval(150, 150)) // returns the new WhateverObject i created above because 150 is betwwen 100 and 200
test.get(new Interval(250, 250)) // doesn't find the value because there is no key that contains 250 in it's interval
Run Code Online (Sandbox Code Playgroud)
基本上我想要的是Interval对象中一系列值之间的键给出对应的WhateverObject.我知道我必须在区间对象中重写equals()和hashcode(),我认为主要问题是以某种方式将所有值介于100和200之间(在此特定示例中)以给出相同的散列.
任何想法,如果这是可能的?
谢谢