project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/ObservableTreeMap.java
author Medo <smaxein@googlemail.com>
Sun, 12 Aug 2012 22:37:57 +0200
changeset 7482 d70a5b0d1190
parent 7476 2fb781bbdd51
permissions -rw-r--r--
frontlib improvements: - Added README with overview documentation - Improved code documentation/comments - Added flib_gameconn_send_quit to gracefully exit a running game - Changed the type of some size variables to size_t - Fixed starting a mission/training sending the mission script like a multiplayer script - Removed reference counters from flib_scheme and flib_map - Removed INGAME state from netconn (there is no useful difference to ROOM state) - Added extras/jnacontrol.c to warn when functions signatures used by Hedgeroid change - Other small code improvements

package org.hedgewars.hedgeroid.netplay;

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);
	}
}