project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/ObservableTreeMap.java
author Medo <smaxein@googlemail.com>
Mon, 20 Aug 2012 20:19:35 +0200 (2012-08-20)
changeset 7582 714310efad8f
parent 7508 763d3961400b
child 7584 7831c84cc644
permissions -rw-r--r--
Hedgeroid: Final sprint to the deadline - Changed local game setup to use the new fragments from the netroom - Pulled team editing into the main activity menu / action bar - Cleanups, renames, anything to make the code look better ;)
package org.hedgewars.hedgeroid.util;

import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;

import android.database.DataSetObservable;

public class ObservableTreeMap<K,V> extends DataSetObservable {
	private final Map<K, V> map = new TreeMap<K, V>();
	
	public void replaceContent(Map<? extends K, ? extends V> newMap) {
		map.clear();
		map.putAll(newMap);
		notifyChanged();
	}
	
	public void put(K key, V value) {
		map.put(key, value);
		notifyChanged();
	}
	
	public V get(K key) {
		return map.get(key);
	}
	
	public void remove(K key) {
		if(map.remove(key) != null) {
			notifyChanged();
		}
	}
	
	public void clear() {
		if(!map.isEmpty()) {
			map.clear();
			notifyChanged();
		}
	}
	
	public Map<K, V> getMap() {
		return Collections.unmodifiableMap(map);
	}
}