import java.net.*; 

/* this class describes the network object.  It consists of a list of Connections, 
 * and has functions to add Connections to the list and to find specific 
 * Connections based on the name of the Connection (the person's username).
*/

 public class Network {
     private int MAX_PEER = 100;
     private int numPeers;
     private Connection peers[];
     private int myPort;
     private String myUserName;     
     private int listenPort = 4000;

     public int get_listenPort() {
	 return listenPort;
     }

     public void increase_numPeers() {
	 numPeers++;
     }

     public void change_myPort(int newPort) {
	 myPort = newPort;
     }

     public void change_myUserName(String newName) {
	 myUserName = newName;
     }

     public int get_myPort() {
	 return myPort;
     }

     public String get_myUserName() {
	 return myUserName;
     }
     
     public int get_numPeers() {
	 return numPeers;
     }

     public Connection get_Peer(int i) {
	 return peers[i];
     }
     
     /* initializes the network */
     public void Network() {
	 peers = new Connection[MAX_PEER];
	 myPort = 4000;
	 myUserName = "me";
     }
     
     /* find a connection based on the name of the connection */
     public Connection find_connection(String name) {
	 for (int i = 0; i < numPeers; i++) {
	     if (peers[i].get_Name() == name) {
		 return peers[i];
	     }
	 }
	 return null;
     }
     
     /* adds a connection to the list */
     public int add(Connection new_connection) {
	 peers[numPeers] = new_connection;
	 numPeers++;
	 return numPeers;
     }
          
 }

