project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/Roomlist.java
changeset 10017 de822cd3df3a
parent 7584 7831c84cc644
equal deleted inserted replaced
10015:4feced261c68 10017:de822cd3df3a
    25 import org.hedgewars.hedgeroid.Datastructures.Room;
    25 import org.hedgewars.hedgeroid.Datastructures.Room;
    26 import org.hedgewars.hedgeroid.Datastructures.RoomWithId;
    26 import org.hedgewars.hedgeroid.Datastructures.RoomWithId;
    27 import org.hedgewars.hedgeroid.util.ObservableTreeMap;
    27 import org.hedgewars.hedgeroid.util.ObservableTreeMap;
    28 
    28 
    29 public class Roomlist extends ObservableTreeMap<String, RoomWithId> {
    29 public class Roomlist extends ObservableTreeMap<String, RoomWithId> {
    30 	private long nextId = 1;
    30     private long nextId = 1;
    31 	
    31 
    32 	public void updateList(Room[] newRooms) {
    32     public void updateList(Room[] newRooms) {
    33 		Map<String, RoomWithId> newMap = new TreeMap<String, RoomWithId>();
    33         Map<String, RoomWithId> newMap = new TreeMap<String, RoomWithId>();
    34 		for(Room room : newRooms) {
    34         for(Room room : newRooms) {
    35 			RoomWithId oldEntry = get(room.name);
    35             RoomWithId oldEntry = get(room.name);
    36 			if(oldEntry == null) {
    36             if(oldEntry == null) {
    37 				newMap.put(room.name, new RoomWithId(room, nextId++));
    37                 newMap.put(room.name, new RoomWithId(room, nextId++));
    38 			} else {
    38             } else {
    39 				newMap.put(room.name, new RoomWithId(room, oldEntry.id));
    39                 newMap.put(room.name, new RoomWithId(room, oldEntry.id));
    40 			}
    40             }
    41 		}
    41         }
    42 		replaceContent(newMap);
    42         replaceContent(newMap);
    43 	}
    43     }
    44 	
    44 
    45 	public void addRoomWithNewId(Room room) {
    45     public void addRoomWithNewId(Room room) {
    46 		put(room.name, new RoomWithId(room, nextId++));
    46         put(room.name, new RoomWithId(room, nextId++));
    47 	}
    47     }
    48 	
    48 
    49 	public void updateRoom(String name, Room room) {
    49     public void updateRoom(String name, Room room) {
    50 		RoomWithId oldEntry = get(name);
    50         RoomWithId oldEntry = get(name);
    51 		if(oldEntry == null) {
    51         if(oldEntry == null) {
    52 			addRoomWithNewId(room);
    52             addRoomWithNewId(room);
    53 		} else {
    53         } else {
    54 			remove(name);
    54             remove(name);
    55 			put(room.name, new RoomWithId(room, oldEntry.id));
    55             put(room.name, new RoomWithId(room, oldEntry.id));
    56 		}
    56         }
    57 	}
    57     }
    58 }
    58 }