sauerCHAOS

ClientList.java

Feb 4th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.43 KB | None | 0 0
  1. /*
  2.  * ClientList.java
  3.  * (c) Chaos, ZLIB license
  4.  * http://www.opensource.org/licenses/zlib-license.php
  5.  */
  6.  
  7. // NOT DONE :)
  8.  
  9. package net.chaos95.jsauer;
  10.  
  11. /**
  12.  * The <tt>ClientList</tt> class is used to represent a list of <tt>Client</tt> objects. It contains
  13.  * a variety of useful methods for obtaining particular pieces of information pertaining to the list
  14.  * of clients.
  15.  *
  16.  * @see Client
  17.  * @see Decode
  18.  * @see Server
  19.  */
  20.  
  21. import java.util.ArrayList;
  22.  
  23. public class ClientList {
  24.    
  25.     /** The list of clients to be used to construct the <tt>ClientList</tt>. */
  26.     public ArrayList<Client> list;
  27.    
  28.     /**
  29.      * Constructs a <tt>ClientList</tt> from an <tt>ArrayList&lt;Client&gt;</tt>.
  30.      * @param l an <tt>ArrayList</tt> of <tt>Client</tt> objects
  31.      */
  32.     public ClientList(ArrayList<Client> l)
  33.     { list = l; }
  34.    
  35.     /**
  36.      * Returns the number of <tt>Client</tt> objects in this <tt>ClientList</tt>.
  37.      * @return number of clients
  38.      */
  39.     public int numClients()
  40.     { return list.size(); }
  41.    
  42.     /**
  43.      * Returns the total number of kills made by every client in this <tt>ClientList</tt>.
  44.      * @return total frags of all clients
  45.      */
  46.     public int totalFrags() {
  47.         int count = 0;
  48.         for(Client c : list)
  49.             count += c.getFrags();
  50.         return count;
  51.     }
  52.    
  53.     /**
  54.      * Returns the total number of deaths of every client in this <tt>ClientList</tt>.
  55.      * @return total deaths of all clients
  56.      */
  57.     public int totalDeaths() {
  58.         int count = 0;
  59.         for(Client c : list)
  60.             count += c.getDeaths();
  61.         return count;
  62.     }
  63.    
  64.     /**
  65.      * Returns the total number of times team mates have been killed by clients in this
  66.      * <tt>ClientList</tt>.
  67.      * @return total number of teamkills
  68.      */
  69.     public int totalTK() {
  70.         int count = 0;
  71.         for(Client c : list)
  72.             count += c.getTeamkills();
  73.         return count;
  74.     }
  75.    
  76.     /**
  77.      * Returns the average accuracy of the clients in this <tt>ClientList</tt>.
  78.      * @return average accuracy of all clients
  79.      */
  80.     public double avgAcc() {
  81.         double count = 0;
  82.         for(Client c : list)
  83.             count += c.getAccuracy();
  84.         return count / list.size();
  85.     }
  86.    
  87.     /**
  88.      * Returns the total number of administrators present in this <tt>ClientList</tt>.
  89.      * @return total number of administrators
  90.      */
  91.     public int numAdmins() {
  92.         int count = 0;
  93.         for(Client c : list)
  94.             if (c.getPrivilege() == Client.PRIV_ADMIN)
  95.                 count++;
  96.         return count;
  97.     }
  98.    
  99.     /**
  100.      * Returns an <tt>ArrayList</tt> containing the administrators of this <tt>ClientList</tt>
  101.      * @return list of administrators
  102.      */
  103.     public ArrayList<Client> listAdmins() {
  104.         ArrayList<Client> temp = new ArrayList<Client>();
  105.         for(Client c : list)
  106.             if (c.getPrivilege() == Client.PRIV_ADMIN)
  107.                 temp.add(c);
  108.         return temp;
  109.     }
  110.    
  111.     /**
  112.      * Returns the total number of spectators present in this <tt>ClientList</tt>.
  113.      * @return total number of spectators
  114.      */
  115.     public int numSpecs() {
  116.         int count = 0;
  117.         for(Client c : list)
  118.             if (c.isSpec())
  119.                 count++;
  120.         return count;
  121.     }
  122.    
  123.     /**
  124.      * Returns an <tt>ArrayList</tt> containing the spectators of this <tt>ClientList</tt>
  125.      * @return list of spectators
  126.      */
  127.     public ArrayList<Client> listSpecs() {
  128.         ArrayList<Client> temp = new ArrayList<Client>();
  129.         for(Client c : list)
  130.             if (c.isSpec()) temp.add(c);
  131.         return temp;
  132.     }
  133.    
  134.     /**
  135.      * Returns an <tt>ArrayList</tt> of all clients in the specified team from this
  136.      * <tt>ClientList</tt>.
  137.      * @param team team to search for, represented as a <tt>String</tt>
  138.      * @return list of clients in the specified team
  139.      */
  140.     public ArrayList<Client> listClientsInTeam(String team) {
  141.         ArrayList<Client> temp = new ArrayList<Client>();
  142.         for(Client c : list)
  143.             if (c.getTeam().equals(team))
  144.                 temp.add(c);
  145.         return temp;
  146.     }
  147.    
  148.     public Client getMaster() {
  149.         for(Client c : list)
  150.             if (c.getPrivilege() == Client.PRIV_MASTER)
  151.                 return c; // since there can only be one master
  152.         return null;
  153.     }
  154.    
  155.     public Client maxFrags() {
  156.         if (list.isEmpty()) return null;
  157.         Client temp = list.get(0);
  158.         for(Client c : list)
  159.             if (c.getFrags() > temp.getFrags())
  160.                 temp = c;
  161.         return temp;
  162.     }
  163.    
  164.     public Client maxDeaths() {
  165.         if (list.isEmpty()) return null;
  166.         Client temp = list.get(0);
  167.         for(Client c : list)
  168.             if (c.getDeaths() > temp.getDeaths())
  169.                 temp = c;
  170.         return temp;
  171.     }
  172.    
  173.     public Client maxAcc() {
  174.         if (list.isEmpty()) return null;
  175.         Client temp = list.get(0);
  176.         for(Client c : list)
  177.             if (c.getAccuracy() > temp.getAccuracy())
  178.                 temp = c;
  179.         return temp;
  180.     }
  181.    
  182.     public Client maxFlags() {
  183.         if (list.isEmpty()) return null;
  184.         Client temp = list.get(0);
  185.         for(Client c : list)
  186.             if (c.getFlags() > temp.getFlags())
  187.                 temp = c;
  188.         return temp;
  189.     }
  190.    
  191.     public Client maxTK() {
  192.         if (list.isEmpty()) return null;
  193.         Client temp = list.get(0);
  194.         for(Client c : list)
  195.             if (c.getTeamkills() > temp.getTeamkills())
  196.                 temp = c;
  197.         return temp;
  198.     }
  199.    
  200.     public Client maxKpD() {
  201.         if (list.isEmpty()) return null;
  202.         Client temp = list.get(0);
  203.         for(Client c : list)
  204.             if (c.kpd() > temp.kpd())
  205.                 temp = c;
  206.         return temp;
  207.     }
  208.    
  209.     public Client maxDpK() {
  210.         if (list.isEmpty()) return null;
  211.         Client temp = list.get(0);
  212.         for(Client c : list)
  213.             if (c.dpk() > temp.dpk())
  214.                 temp = c;
  215.         return temp;
  216.     }
  217.    
  218.     public ArrayList<String> listTeams() {
  219.         ArrayList<String> teamList = new ArrayList<String>();
  220.         for(Client c : list)
  221.             if (teamList.indexOf(c.getTeam()) < 0)
  222.                 teamList.add(c.getTeam());
  223.         return teamList;
  224.     }
  225.    
  226. }
Advertisement
Add Comment
Please, Sign In to add comment