From 0545c07d330b457348c75f84308b4b6d58896f2d Mon Sep 17 00:00:00 2001 From: Mike Jensen Date: Tue, 29 Apr 2014 09:52:27 -0600 Subject: [PATCH] Added SortedMap interface I also changed TreeMap to implement the "SortedMap" interface, like it should. Unfortanetly not all the code to implement the interface was there. Where it was simple I implemented the additional functions, in the case of headMap, tailMap, subMap we are currently just throwing an UnsupportedOperationException. --- classpath/java/util/SortedMap.java | 15 +++++++++++++ classpath/java/util/TreeMap.java | 35 +++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 classpath/java/util/SortedMap.java 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;