mirror of
https://github.com/corda/corda.git
synced 2025-01-22 04:18:31 +00:00
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.
This commit is contained in:
parent
32d25d79fd
commit
0545c07d33
15
classpath/java/util/SortedMap.java
Normal file
15
classpath/java/util/SortedMap.java
Normal file
@ -0,0 +1,15 @@
|
||||
package java.util;
|
||||
|
||||
public interface SortedMap<K, V> extends Map<K, V> {
|
||||
public Comparator<? super K> comparator();
|
||||
|
||||
public K firstKey();
|
||||
|
||||
public K lastKey();
|
||||
|
||||
public SortedMap<K, V> headMap(K toKey);
|
||||
|
||||
public SortedMap<K, V> tailMap(K fromKey);
|
||||
|
||||
public SortedMap<K, V> subMap(K fromKey, K toKey);
|
||||
}
|
@ -14,7 +14,7 @@ import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
public class TreeMap<K,V> implements Map<K,V> {
|
||||
public class TreeMap<K,V> implements SortedMap<K,V> {
|
||||
private final Comparator<K> comparator;
|
||||
private transient TreeSet<MyEntry<K,V>> set;
|
||||
|
||||
@ -45,6 +45,39 @@ public class TreeMap<K,V> implements Map<K,V> {
|
||||
return avian.Data.toString(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<? super K> comparator() {
|
||||
return comparator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public K firstKey() {
|
||||
return set.first().key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public K lastKey() {
|
||||
return set.last().key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<K, V> 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<K, V> 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<K, V> 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<K,V> e = set.find(new MyEntry(key, null));
|
||||
return e == null ? null : e.value;
|
||||
|
Loading…
Reference in New Issue
Block a user