Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * ClientList.java
- * (c) Chaos, ZLIB license
- * http://www.opensource.org/licenses/zlib-license.php
- */
- // NOT DONE :)
- package net.chaos95.jsauer;
- /**
- * The <tt>ClientList</tt> class is used to represent a list of <tt>Client</tt> objects. It contains
- * a variety of useful methods for obtaining particular pieces of information pertaining to the list
- * of clients.
- *
- * @see Client
- * @see Decode
- * @see Server
- */
- import java.util.ArrayList;
- public class ClientList {
- /** The list of clients to be used to construct the <tt>ClientList</tt>. */
- public ArrayList<Client> list;
- /**
- * Constructs a <tt>ClientList</tt> from an <tt>ArrayList<Client></tt>.
- * @param l an <tt>ArrayList</tt> of <tt>Client</tt> objects
- */
- public ClientList(ArrayList<Client> l)
- { list = l; }
- /**
- * Returns the number of <tt>Client</tt> objects in this <tt>ClientList</tt>.
- * @return number of clients
- */
- public int numClients()
- { return list.size(); }
- /**
- * Returns the total number of kills made by every client in this <tt>ClientList</tt>.
- * @return total frags of all clients
- */
- public int totalFrags() {
- int count = 0;
- for(Client c : list)
- count += c.getFrags();
- return count;
- }
- /**
- * Returns the total number of deaths of every client in this <tt>ClientList</tt>.
- * @return total deaths of all clients
- */
- public int totalDeaths() {
- int count = 0;
- for(Client c : list)
- count += c.getDeaths();
- return count;
- }
- /**
- * Returns the total number of times team mates have been killed by clients in this
- * <tt>ClientList</tt>.
- * @return total number of teamkills
- */
- public int totalTK() {
- int count = 0;
- for(Client c : list)
- count += c.getTeamkills();
- return count;
- }
- /**
- * Returns the average accuracy of the clients in this <tt>ClientList</tt>.
- * @return average accuracy of all clients
- */
- public double avgAcc() {
- double count = 0;
- for(Client c : list)
- count += c.getAccuracy();
- return count / list.size();
- }
- /**
- * Returns the total number of administrators present in this <tt>ClientList</tt>.
- * @return total number of administrators
- */
- public int numAdmins() {
- int count = 0;
- for(Client c : list)
- if (c.getPrivilege() == Client.PRIV_ADMIN)
- count++;
- return count;
- }
- /**
- * Returns an <tt>ArrayList</tt> containing the administrators of this <tt>ClientList</tt>
- * @return list of administrators
- */
- public ArrayList<Client> listAdmins() {
- ArrayList<Client> temp = new ArrayList<Client>();
- for(Client c : list)
- if (c.getPrivilege() == Client.PRIV_ADMIN)
- temp.add(c);
- return temp;
- }
- /**
- * Returns the total number of spectators present in this <tt>ClientList</tt>.
- * @return total number of spectators
- */
- public int numSpecs() {
- int count = 0;
- for(Client c : list)
- if (c.isSpec())
- count++;
- return count;
- }
- /**
- * Returns an <tt>ArrayList</tt> containing the spectators of this <tt>ClientList</tt>
- * @return list of spectators
- */
- public ArrayList<Client> listSpecs() {
- ArrayList<Client> temp = new ArrayList<Client>();
- for(Client c : list)
- if (c.isSpec()) temp.add(c);
- return temp;
- }
- /**
- * Returns an <tt>ArrayList</tt> of all clients in the specified team from this
- * <tt>ClientList</tt>.
- * @param team team to search for, represented as a <tt>String</tt>
- * @return list of clients in the specified team
- */
- public ArrayList<Client> listClientsInTeam(String team) {
- ArrayList<Client> temp = new ArrayList<Client>();
- for(Client c : list)
- if (c.getTeam().equals(team))
- temp.add(c);
- return temp;
- }
- public Client getMaster() {
- for(Client c : list)
- if (c.getPrivilege() == Client.PRIV_MASTER)
- return c; // since there can only be one master
- return null;
- }
- public Client maxFrags() {
- if (list.isEmpty()) return null;
- Client temp = list.get(0);
- for(Client c : list)
- if (c.getFrags() > temp.getFrags())
- temp = c;
- return temp;
- }
- public Client maxDeaths() {
- if (list.isEmpty()) return null;
- Client temp = list.get(0);
- for(Client c : list)
- if (c.getDeaths() > temp.getDeaths())
- temp = c;
- return temp;
- }
- public Client maxAcc() {
- if (list.isEmpty()) return null;
- Client temp = list.get(0);
- for(Client c : list)
- if (c.getAccuracy() > temp.getAccuracy())
- temp = c;
- return temp;
- }
- public Client maxFlags() {
- if (list.isEmpty()) return null;
- Client temp = list.get(0);
- for(Client c : list)
- if (c.getFlags() > temp.getFlags())
- temp = c;
- return temp;
- }
- public Client maxTK() {
- if (list.isEmpty()) return null;
- Client temp = list.get(0);
- for(Client c : list)
- if (c.getTeamkills() > temp.getTeamkills())
- temp = c;
- return temp;
- }
- public Client maxKpD() {
- if (list.isEmpty()) return null;
- Client temp = list.get(0);
- for(Client c : list)
- if (c.kpd() > temp.kpd())
- temp = c;
- return temp;
- }
- public Client maxDpK() {
- if (list.isEmpty()) return null;
- Client temp = list.get(0);
- for(Client c : list)
- if (c.dpk() > temp.dpk())
- temp = c;
- return temp;
- }
- public ArrayList<String> listTeams() {
- ArrayList<String> teamList = new ArrayList<String>();
- for(Client c : list)
- if (teamList.indexOf(c.getTeam()) < 0)
- teamList.add(c.getTeam());
- return teamList;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment