package com.madhackerdesigns.jinder;

import java.io.IOException;
import java.util.List;
import java.util.SortedSet;
import java.util.concurrent.ConcurrentSkipListSet;

import com.madhackerdesigns.jinder.models.RoomList;
import com.madhackerdesigns.jinder.models.Self;
import com.madhackerdesigns.jinder.models.User;


public class Campfire {
  
  private Connection connection;
  
  // constructors
  
  public Campfire(String subdomain, String token) {
    this.connection = new Connection(subdomain, token);
  }
  
  public Campfire(String subdomain, String username, String password) {
    this.connection = new Connection(subdomain, username, password);
  }
  
  // public methods
  
  public Connection connection() {
    return connection;
  }
  
  public Room findRoomById(long id) throws IOException {
    for (Room room : rooms()) {
      if (id == room.id) { return room; }
    }
    return null;
  }
  
  public Room findRoomByName(String name) throws IOException {
    for (Room room : rooms()) {
      if (name.equals(room.name)) { return room; }
    }
    return null;
  }
  
  public Room findRoomByGuestHash(String hash) throws IOException {
    for (Room room : rooms()) {
      if (hash.equals(room.active_token_value)) { return room; }
    }
    return null;
  }
  
  public User me() throws IOException {
    return connection.get("/users/me.json").parseAs(Self.class).user;
  }
  
  public List<Room> rooms() throws IOException {
    List<Room> rooms = connection.get("/rooms.json").parseAs(RoomList.class).rooms;
    for (Room room : rooms) {
      room.setConnection(connection);
    }
    return rooms;
  }
  
  public SortedSet<User> users() throws IOException {
    SortedSet<User> users = new ConcurrentSkipListSet<User>();
    for (Room room : rooms()) {
//      users.addAll(room.users());
      for (User user : room.users()) {
        users.add(user);
      }
    }
    return users;
  }

}

@@ -1777,18 +1777,16 @@
 ms()) %7B%0A
-//
       us
@@ -1815,80 +1815,8 @@
 ));%0A
-      for (User user : room.users()) %7B%0A        users.add(user);%0A      %7D%0A
     

Use addAll() instead of for loop.