Merge pull request #364 from dicej/navigable-map

add minimal NavigableMap interface
This commit is contained in:
Mike Jensen 2014-11-05 15:01:07 -07:00
commit d037a69cd3
2 changed files with 17 additions and 1 deletions

View File

@ -0,0 +1,6 @@
package java.util;
public interface NavigableMap<K, V> extends SortedMap<K, V> {
Map.Entry<K,V> firstEntry();
Map.Entry<K,V> lastEntry();
}

View File

@ -14,7 +14,7 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class TreeMap<K,V> implements SortedMap<K,V> {
public class TreeMap<K,V> implements NavigableMap<K,V> {
private final Comparator<K> comparator;
private transient TreeSet<MyEntry<K,V>> set;
@ -50,6 +50,16 @@ public class TreeMap<K,V> implements SortedMap<K,V> {
return comparator;
}
@Override
public Map.Entry<K,V> firstEntry() {
return set.first();
}
@Override
public Map.Entry<K,V> lastEntry() {
return set.last();
}
@Override
public K firstKey() {
return set.first().key;