Skip to main content

add new method to java.util.NavigableSet and NavigableMap

2 replies [Last post]
mifeld
Offline
Joined: 2005-12-28

I propose to add to java.util.NavigableSet new method:
public E[] getLEH(E e);

This method returns array of three elements:
- 0th element is a result of method lower(E e)
- 1st element is a result of method get(E e)
- 2nd element is a result of method hider(E e)

BTW, I propose to add to java.util.NavigableMap new method:
public Map.Entry[] getLEHEntry(K key);

This method returns array of three elements:
- 0th element is a result of method lowerEntry(K key)
- 1st element is a result of method getEntry(K key)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexlamsl
Offline
Joined: 2004-09-02

Would you mind providing sample implementation then use case(s) to at least one of your methods mentioned above?

I admit that I can't see immediately the benefits of introducing these method calls ;)

mifeld
Offline
Joined: 2005-12-28

1. I think that understand API, which contains one method ([b]getLEHEntry[/b])much more simple instead API with five methods([b]ceilingEntry,floorEntry[/b] etc.)
2. When we think about [b]getLEHEntry[/b] we can see there is no method [b]getEntry[/b] in current API. I think developers forgot to add it.

3. I propose two new methods (forgot to do this in my previous message :)

[b]public Map.Entry nextTo(Map.Entry en)[/b]
[b]public Map.Entry prevTo(Map.Entry en)[/b]

[b]nextTo[/b] ([b]prevTo[/b]) always returns closest entry next (previous) to the parameter or [b]null[/b]if there is no such entry. If parameter is [b]null[/b] [b]nextTo(prevTo)[/b] return the first(last) entry of the Map.

Implementation of this methods can keep all necessary information for future [b]nextTo[/b] in returned [b]Map.Entry[/b].

These methods may be implemented for all predefined implementations of SortedMap.

These methods can be used instead iterators for structurally modified maps.

Example:

[b]for(Map.Entry en = map.nextTo(null); en != null; en = map.nextTo(en))
{
. . . .
}[/b]