com.squeakysand.commons.util.DictionaryMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of squeakysand-commons Show documentation
Show all versions of squeakysand-commons Show documentation
Classes, interfaces and enums that assist with everyday Java development tasks.
The newest version!
/*
* Copyright 2010-2012 Craig S. Dickson (http://craigsdickson.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squeakysand.commons.util;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Dictionary;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
public class DictionaryMap extends Dictionary implements Map {
private Dictionary dictionary;
public DictionaryMap(Dictionary dictionary) {
this.dictionary = dictionary;
}
@Override
public int size() {
return dictionary.size();
}
@Override
public boolean isEmpty() {
return dictionary.isEmpty();
}
@Override
public boolean containsKey(Object o) {
Set keySet = keySet();
return keySet.contains(o);
}
@Override
public boolean containsValue(Object o) {
Collection values = values();
return values.contains(o);
}
@Override
public V get(Object o) {
return dictionary.get(o);
}
@Override
public V put(K k, V v) {
return dictionary.put(k, v);
}
@Override
public V remove(Object o) {
return dictionary.remove(o);
}
@Override
public void putAll(Map extends K, ? extends V> map) {
for (Map.Entry extends K, ? extends V> e : map.entrySet()) {
put(e.getKey(), e.getValue());
}
}
@Override
public void clear() {
Set keys = keySet();
for (K key : keys) {
dictionary.remove(key);
}
}
@Override
public Set keySet() {
Set result = new TreeSet();
IterableEnumeration keys = keys();
for (K key : keys) {
result.add(key);
}
return result;
}
@Override
public Collection values() {
List result = new ArrayList();
IterableEnumeration values = elements();
for (V value : values) {
result.add(value);
}
return result;
}
@Override
public Set> entrySet() {
Set> result = new TreeSet>();
Set keys = keySet();
for (K key : keys) {
V value = dictionary.get(key);
Entry entry = new SimpleEntry(key, value);
result.add(entry);
}
return result;
}
@Override
public IterableEnumeration keys() {
return new IterableEnumeration(dictionary.keys());
}
@Override
public IterableEnumeration elements() {
return new IterableEnumeration(dictionary.elements());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy