All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aQute.bnd.deployer.repository.MapToDictionaryAdapter Maven / Gradle / Ivy

There is a newer version: 7.1.0
Show newest version
package aQute.bnd.deployer.repository;

import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;

public class MapToDictionaryAdapter extends Dictionary {

	private final Map map;

	public MapToDictionaryAdapter(Map map) {
		this.map = map;
	}

	@Override
	public Enumeration elements() {
		final Iterator iter = map.values()
			.iterator();
		return new Enumeration() {
			@Override
			public boolean hasMoreElements() {
				return iter.hasNext();
			}

			@Override
			public Object nextElement() {
				return iter.next();
			}
		};
	}

	@Override
	public Object get(Object key) {
		return map.get(key);
	}

	@Override
	public boolean isEmpty() {
		return map.isEmpty();
	}

	@Override
	public Enumeration keys() {
		final Iterator iter = map.keySet()
			.iterator();
		return new Enumeration() {
			@Override
			public boolean hasMoreElements() {
				return iter.hasNext();
			}

			@Override
			public String nextElement() {
				return iter.next();
			}
		};
	}

	@Override
	public Object put(String key, Object value) {
		return map.put(key, value);
	}

	@Override
	public Object remove(Object key) {
		return map.remove(key);
	}

	@Override
	public int size() {
		return map.size();
	}

}