Use LinkedHashSet instead of List

This commit is contained in:
TfT_02 2013-04-13 18:43:22 +02:00
parent c60e5a65d6
commit f05b9ae365
3 changed files with 14 additions and 18 deletions

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.api;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import org.bukkit.OfflinePlayer;
@ -148,7 +149,7 @@ public final class PartyAPI {
* @param player The player to check
* @return all the player names in the player's party
*/
public static List<String> getMembers(Player player) {
public static LinkedHashSet<String> getMembers(Player player) {
return PartyManager.getAllMembers(player);
}

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.datatypes.party;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import org.bukkit.OfflinePlayer;
@ -10,7 +11,7 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.party.ShareHandler;
public class Party {
private List<String> members = new ArrayList<String>();
private LinkedHashSet<String> members = new LinkedHashSet<String>();
private String leader;
private String name;
private String password;
@ -24,7 +25,7 @@ public class Party {
private boolean shareHerbalismDrops = true;
private boolean shareWoodcuttingDrops = true;
public List<String> getMembers() {
public LinkedHashSet<String> getMembers() {
return members;
}

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.party;
import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import org.bukkit.OfflinePlayer;
@ -97,7 +98,7 @@ public final class PartyManager {
* @param player The player to check
* @return all the players in the player's party
*/
public static List<String> getAllMembers(Player player) {
public static LinkedHashSet<String> getAllMembers(Player player) {
Party party = UserManager.getPlayer(player).getParty();
if (party == null) {
@ -189,12 +190,9 @@ public final class PartyManager {
* @param party The party
*/
public static void removeFromParty(OfflinePlayer player, Party party) {
List<String> members = party.getMembers();
LinkedHashSet<String> members = party.getMembers();
while (members.contains(player.getName())) {
// Remove all the duplicates as well
members.remove(player.getName());
}
if (members.isEmpty()) {
parties.remove(party);
@ -202,7 +200,7 @@ public final class PartyManager {
else {
// If the leaving player was the party leader, appoint a new leader from the party members
if (party.getLeader().equalsIgnoreCase(player.getName())) {
String newLeader = members.get(0);
String newLeader = members.iterator().next();
party.setLeader(newLeader);
}
@ -223,7 +221,7 @@ public final class PartyManager {
* @param party The party to remove
*/
public static void disbandParty(Party party) {
List<String> members = party.getMembers();
LinkedHashSet<String> members = party.getMembers();
for (String memberName : members) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(memberName);
@ -363,10 +361,8 @@ public final class PartyManager {
informPartyMembersJoin(player, party);
mcMMOPlayer.setParty(party);
if (!party.getMembers().contains(player.getName())) {
party.getMembers().add(player.getName());
}
}
/**
* Get the leader of a party.
@ -469,13 +465,11 @@ public final class PartyManager {
party.setItemShareMode(ShareHandler.ShareMode.getFromString(partiesFile.getString(partyName + ".ItemShareMode")));
List<String> memberNames = partiesFile.getStringList(partyName + ".Members");
List<String> members = party.getMembers();
LinkedHashSet<String> members = party.getMembers();
for (String memberName : memberNames) {
if (!members.contains(memberName)) {
members.add(memberName);
}
}
parties.add(party);
}