Added Domain.contains(String playerName).

This commit is contained in:
TomyLobo 2012-03-23 14:40:20 +01:00
parent f2fead1444
commit 690da2332b
5 changed files with 59 additions and 25 deletions

View File

@ -70,20 +70,26 @@ public Set<String> getPlayers() {
return players;
}
@Override
public boolean contains(LocalPlayer player) {
if (players.contains(player.getName().toLowerCase())) {
if (contains(player.getName())) {
return true;
}
for (String group : groups) {
if (player.hasGroup(group)) {
return true;
}
}
return false;
}
@Override
public boolean contains(String playerName) {
return players.contains(playerName.toLowerCase());
}
public int size() {
return groups.size() + players.size();
}

View File

@ -5,9 +5,18 @@
public interface Domain {
/**
* Returns true if a domain contains a player.
*
*
* @param player The player to check
* @return whether this domain contains {@code player}
*/
public boolean contains(LocalPlayer player);
boolean contains(LocalPlayer player);
/**
* Returns true if a domain contains a player.<br />
* This method doesn't check for groups!
*
* @param playerName The name of the player to check
* @return whether this domain contains a player by that name
*/
boolean contains(String playerName);
}

View File

@ -26,31 +26,42 @@
public class DomainCollection implements Domain {
private Set<Domain> domains;
public DomainCollection() {
domains = new LinkedHashSet<Domain>();
}
public void add(Domain domain) {
domains.add(domain);
}
public void remove(Domain domain) {
domains.remove(domain);
}
public int size() {
return domains.size();
}
@Override
public boolean contains(LocalPlayer player) {
for (Domain domain : domains) {
if (domain.contains(player)) {
return true;
}
}
return false;
}
@Override
public boolean contains(String playerName) {
for (Domain domain : domains) {
if (domain.contains(playerName)) {
return true;
}
}
return false;
}
}

View File

@ -27,15 +27,15 @@
public class GroupDomain implements Domain {
private Set<String> groups;
public GroupDomain() {
this.groups = new LinkedHashSet<String>();
}
public GroupDomain(String[] groups) {
this.groups = new LinkedHashSet<String>(Arrays.asList(groups));
}
public void addGroup(String name) {
groups.add(name);
}
@ -46,12 +46,16 @@ public boolean contains(LocalPlayer player) {
return true;
}
}
return false;
}
@Override
public boolean contains(String playerName) {
return false; // GroupDomains can't contain player names.
}
public int size() {
return groups.size();
}
}

View File

@ -26,29 +26,33 @@
public class PlayerDomain implements Domain {
private Set<String> players;
public PlayerDomain() {
this.players = new HashSet<String>();
}
public PlayerDomain(String[] players) {
this.players = new HashSet<String>();
for (String name : players) {
this.players.add(name.toLowerCase());
}
}
public void addPlayer(String name) {
players.add(name.toLowerCase());
}
public boolean contains(LocalPlayer player) {
return players.contains(player.getName().toLowerCase());
return contains(player.getName());
}
@Override
public boolean contains(String playerName) {
return players.contains(playerName.toLowerCase());
}
public int size() {
return players.size();
}
}