package com.lightstreamer.adapters.Dart.room;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

class Room {
    
    /**
     * 
     */
    private final ChatRoom chatRoom;
    private String roomId;
    private Set<String> users = new HashSet<String>();
    private Object statusHandle = null;
    private Object messageHandle = null;
    
    public Room(ChatRoom chatRoom, String roomId) {
        this.chatRoom = chatRoom;
        this.roomId = roomId;
    }

    public String getId() {
        return this.roomId;
    }

    public void broadcastMessage(User user, String message) {
        if (this.messageHandle != null) {
          this.chatRoom.sendRoomMessageEvent(user,this.roomId,this.messageHandle,message);
        }
    }

    public boolean isEmpty() {
        return users.isEmpty();
    }
    
    public boolean isListened() {
        return this.statusHandle != null || this.messageHandle != null;
    }

    public void setStatusHandle(Object roomStatusHandle) {
        this.statusHandle = roomStatusHandle;
    }
    
    public void setMessageHandle(Object messageHandle) {
        this.messageHandle = messageHandle;
    }
    
    void addUser(User user) {
        this.users.add(user.getId());
        if (this.statusHandle != null) {
            this.chatRoom.sendRoomStatusEvent(user, this.roomId, this.statusHandle, ChatRoom.ENTER, ChatRoom.REALTIME);
        }
    }

    void removeUser(User user) {
        if (this.users.remove(user.getId()) && this.statusHandle != null ) {
            this.chatRoom.sendRoomStatusEvent(user, this.roomId, this.statusHandle, ChatRoom.EXIT, ChatRoom.REALTIME);
        }
    }
    
    public Iterator<String> getUsers() {
        return this.users.iterator();
    }
    

}
@@ -1,8 +1,595 @@
+/*%0ACopyright 2014 Weswit s.r.l.%0A%0A   Licensed under the Apache License, Version 2.0 (the %22License%22);%0A   you may not use this file except in compliance with the License.%0A   You may obtain a copy of the License at%0A%0A       http://www.apache.org/licenses/LICENSE-2.0%0A%0A   Unless required by applicable law or agreed to in writing, software%0A   distributed under the License is distributed on an %22AS IS%22 BASIS,%0A   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A   See the License for the specific language governing permissions and%0A   limitations under the License.%0A*/%0A
 package 
@@ -720,37 +720,13 @@
 m %7B%0A
+
     %0A
-    /**%0A     * %0A     */%0A
     

add license