project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/Roomlist.java
author Medo <smaxein@googlemail.com>
Sat, 18 Aug 2012 00:47:51 +0200
changeset 7508 763d3961400b
parent 7491 d954c1a36e51
child 7584 7831c84cc644
permissions -rw-r--r--
Hedgeroid: Frantic scrabbling toward the deadline - Added activities for weapon/scheme editors (unfinished) - Completed tablet version of netroom activity - Added map preview - Fixed default team files having the wrong names - Restructuring - Updated frontlib JNA bindings to respect the latest frontlib changes

package org.hedgewars.hedgeroid.netplay;

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

import org.hedgewars.hedgeroid.Datastructures.Room;
import org.hedgewars.hedgeroid.Datastructures.RoomWithId;
import org.hedgewars.hedgeroid.util.ObservableTreeMap;

public class Roomlist extends ObservableTreeMap<String, RoomWithId> {
	private long nextId = 1;
	
	public void updateList(Room[] newRooms) {
		Map<String, RoomWithId> newMap = new TreeMap<String, RoomWithId>();
		for(Room room : newRooms) {
			RoomWithId oldEntry = get(room.name);
			if(oldEntry == null) {
				newMap.put(room.name, new RoomWithId(room, nextId++));
			} else {
				newMap.put(room.name, new RoomWithId(room, oldEntry.id));
			}
		}
		replaceContent(newMap);
	}
	
	public void addRoomWithNewId(Room room) {
		put(room.name, new RoomWithId(room, nextId++));
	}
	
	public void updateRoom(String name, Room room) {
		RoomWithId oldEntry = get(name);
		if(oldEntry == null) {
			addRoomWithNewId(room);
		} else {
			remove(name);
			put(room.name, new RoomWithId(room, oldEntry.id));
		}
	}
}