package ats_jp.activity.profile;
import java.awt.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import ats_jp.activity.datastore.ArrayStore;
public class PlayerList {
private ArrayStore myPlayer;
public PlayerList(int size)
{
myPlayer=new ArrayStore(size);
}
public boolean addPlayer(PlayerProfile playerProfile)
{
boolean flag=false;
if(playerProfile!=null)
{
if(!myPlayer.contains(playerProfile))
{
flag=myPlayer.add(playerProfile);
}
} else {
throw new IllegalArgumentException("Null argument");
}
return flag;
}
public PlayerProfile findPlayer(int index)
{
return (PlayerProfile) myPlayer.check(index);
}
public PlayerProfile findPlayer(PlayerProfile playerProfile)
{
return (PlayerProfile) myPlayer.check(myPlayer.find(playerProfile));
}
public int getMaxPlayerCount()
{
return myPlayer.getSize();
}
public int getPlayerCount()
{
return myPlayer.getCount();
}
public PlayerProfile findPlayer(int index)
{
return myPlayer.check(index);
}
public PlayerProfile findPlayer(PlayerProfile arg)
{
return myPlayer.find(arg);
}
public PlayerProfile[] findPlayer(String nome)
{
// mi creo un qualcosa di appoggio
ArrayList<PlayerProfile> mList=new ArrayList<PlayerProfile>();
for(int i=0; i<myPlayer.getCount(); i++)
{
PlayerProfile tmp = (PlayerProfile) myPlayer.check(i);
if(tmp.getName().equals(nome))
{
mList.add(tmp);
}
}
PlayerProfile[] tmpArray = new PlayerProfile[mList.size()];
mList.toArray(tmpArray);
return tmpArray;
}
public PlayerProfile removePlayer(int index)
{
return (PlayerProfile) myPlayer.remove(index);
}
public PlayerProfile[] getAll()
{
PlayerProfile[] tmp = new PlayerProfile[myPlayer.getSize()-1];
if(!myPlayer.isEmpty())
{
System.arraycopy(myPlayer.toArray(), 0, tmp, 0, myPlayer.toArray().length);
}
return tmp;
}
}