added the new program for holding known games
#stroy[1188]
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package model;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Holds a table object that stores current games
|
||||
*/
|
||||
public class MatchTable {
|
||||
private HashMap<TableKey, List> matchTable;
|
||||
|
||||
public MatchTable() {
|
||||
this.matchTable = new HashMap<TableKey, List>();
|
||||
}
|
||||
|
||||
public void addEntry(ArrayList newEntry) {
|
||||
//create a key from the ip and port
|
||||
TableKey entryKey = new TableKey((String) newEntry.get(0), (Integer) newEntry.get(1));
|
||||
|
||||
//get the rest of the entry and use it as the value
|
||||
List entryItems = new ArrayList();
|
||||
for(int i = 2; i<newEntry.size(); i++) {
|
||||
entryItems.add(newEntry.get(i));
|
||||
}
|
||||
|
||||
this.matchTable.put(entryKey, entryItems);
|
||||
}
|
||||
|
||||
public HashMap<TableKey, List> getMatchTable() {
|
||||
return matchTable;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package model;
|
||||
|
||||
/**
|
||||
* Used to create a key made of an ip and port.
|
||||
*/
|
||||
public class TableKey {
|
||||
|
||||
private final String ip;
|
||||
private final int port;
|
||||
|
||||
public TableKey(String ip, int port) {
|
||||
this.ip = ip;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof TableKey)) return false;
|
||||
TableKey key = (TableKey) o;
|
||||
return ip == key.ip && port == key.port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = port;
|
||||
result = 31 * result + ip.hashCode();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user