diff --git a/classpath/java/util/SortedMap.java b/classpath/java/util/SortedMap.java new file mode 100644 index 0000000000..d7abb282ba --- /dev/null +++ b/classpath/java/util/SortedMap.java @@ -0,0 +1,15 @@ +package java.util; + +public interface SortedMap extends Map { + public Comparator comparator(); + + public K firstKey(); + + public K lastKey(); + + public SortedMap headMap(K toKey); + + public SortedMap tailMap(K fromKey); + + public SortedMap subMap(K fromKey, K toKey); +} diff --git a/classpath/java/util/TreeMap.java b/classpath/java/util/TreeMap.java index e5be011a07..e7258255cd 100644 --- a/classpath/java/util/TreeMap.java +++ b/classpath/java/util/TreeMap.java @@ -14,7 +14,7 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -public class TreeMap implements Map { +public class TreeMap implements SortedMap { private final Comparator comparator; private transient TreeSet> set; @@ -45,6 +45,39 @@ public class TreeMap implements Map { return avian.Data.toString(this); } + @Override + public Comparator comparator() { + return comparator; + } + + @Override + public K firstKey() { + return set.first().key; + } + + @Override + public K lastKey() { + return set.last().key; + } + + @Override + public SortedMap headMap(K toKey) { + // TODO - this should be implemented, the trick is making the returned SortedMap backed by this TreeSet + throw new UnsupportedOperationException(); + } + + @Override + public SortedMap tailMap(K fromKey) { + // TODO - this should be implemented, the trick is making the returned SortedMap backed by this TreeSet + throw new UnsupportedOperationException(); + } + + @Override + public SortedMap subMap(K fromKey, K toKey) { + // TODO - this should be implemented, the trick is making the returned SortedMap backed by this TreeSet + throw new UnsupportedOperationException(); + } + public V get(Object key) { MyEntry e = set.find(new MyEntry(key, null)); return e == null ? null : e.value;