com.venky.core.collections.SequenceMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common Show documentation
Show all versions of common Show documentation
Commonly used programming tasks in java
package com.venky.core.collections;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class SequenceMap implements Map{
private HashMap inner = new HashMap();
private SequenceSet keys = new SequenceSet();
@Override
public int size() {
return inner.size();
}
@Override
public boolean isEmpty() {
return inner.isEmpty();
}
@Override
public boolean containsKey(Object key) {
return inner.containsKey(key);
}
@Override
public boolean containsValue(Object value) {
return inner.containsValue(value);
}
@Override
public V get(Object key) {
return inner.get(key);
}
@Override
public V put(K key, V value) {
V old = inner.put(key, value);
keys.add(key);
return old;
}
@Override
public V remove(Object key) {
V v = inner.remove(key);
keys.remove(key);
return v;
}
@Override
public void putAll(Map extends K, ? extends V> m) {
for (K k : m.keySet()){
put(k,m.get(k));
}
}
@Override
public void clear() {
inner.clear();
keys.clear();
}
@Override
public Set keySet() {
return Collections.unmodifiableSet(keys);
}
@Override
public Collection values() {
return Collections.unmodifiableCollection(inner.values());
}
@Override
public Set> entrySet() {
return Collections.unmodifiableSet(inner.entrySet());
}
}