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; return players;
} }
@Override
public boolean contains(LocalPlayer player) { public boolean contains(LocalPlayer player) {
if (players.contains(player.getName().toLowerCase())) { if (contains(player.getName())) {
return true; return true;
} }
for (String group : groups) { for (String group : groups) {
if (player.hasGroup(group)) { if (player.hasGroup(group)) {
return true; return true;
} }
} }
return false; return false;
} }
@Override
public boolean contains(String playerName) {
return players.contains(playerName.toLowerCase());
}
public int size() { public int size() {
return groups.size() + players.size(); return groups.size() + players.size();
} }

View File

@ -5,9 +5,18 @@
public interface Domain { public interface Domain {
/** /**
* Returns true if a domain contains a player. * Returns true if a domain contains a player.
* *
* @param player The player to check * @param player The player to check
* @return whether this domain contains {@code player} * @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 { public class DomainCollection implements Domain {
private Set<Domain> domains; private Set<Domain> domains;
public DomainCollection() { public DomainCollection() {
domains = new LinkedHashSet<Domain>(); domains = new LinkedHashSet<Domain>();
} }
public void add(Domain domain) { public void add(Domain domain) {
domains.add(domain); domains.add(domain);
} }
public void remove(Domain domain) { public void remove(Domain domain) {
domains.remove(domain); domains.remove(domain);
} }
public int size() { public int size() {
return domains.size(); return domains.size();
} }
@Override
public boolean contains(LocalPlayer player) { public boolean contains(LocalPlayer player) {
for (Domain domain : domains) { for (Domain domain : domains) {
if (domain.contains(player)) { if (domain.contains(player)) {
return true; return true;
} }
} }
return false; 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 { public class GroupDomain implements Domain {
private Set<String> groups; private Set<String> groups;
public GroupDomain() { public GroupDomain() {
this.groups = new LinkedHashSet<String>(); this.groups = new LinkedHashSet<String>();
} }
public GroupDomain(String[] groups) { public GroupDomain(String[] groups) {
this.groups = new LinkedHashSet<String>(Arrays.asList(groups)); this.groups = new LinkedHashSet<String>(Arrays.asList(groups));
} }
public void addGroup(String name) { public void addGroup(String name) {
groups.add(name); groups.add(name);
} }
@ -46,12 +46,16 @@ public boolean contains(LocalPlayer player) {
return true; return true;
} }
} }
return false; return false;
} }
@Override
public boolean contains(String playerName) {
return false; // GroupDomains can't contain player names.
}
public int size() { public int size() {
return groups.size(); return groups.size();
} }
} }

View File

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