mirror of
https://github.com/corda/corda.git
synced 2025-01-07 05:28:51 +00:00
Merge pull request #248 from jentfoo/SortedMap_Interface
Added SortedMap interface
This commit is contained in:
commit
548d70b5e4
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