PlayerList


SUBMITTED BY: Guest

DATE: May 11, 2016, 1:15 p.m.

FORMAT: Java

SIZE: 2.0 kB

HITS: 714

  1. package ats_jp.activity.profile;
  2. import java.awt.List;
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5. import java.util.LinkedList;
  6. import ats_jp.activity.datastore.ArrayStore;
  7. public class PlayerList {
  8. private ArrayStore myPlayer;
  9. public PlayerList(int size)
  10. {
  11. myPlayer=new ArrayStore(size);
  12. }
  13. public boolean addPlayer(PlayerProfile playerProfile)
  14. {
  15. boolean flag=false;
  16. if(playerProfile!=null)
  17. {
  18. if(!myPlayer.contains(playerProfile))
  19. {
  20. flag=myPlayer.add(playerProfile);
  21. }
  22. } else {
  23. throw new IllegalArgumentException("Null argument");
  24. }
  25. return flag;
  26. }
  27. public PlayerProfile findPlayer(int index)
  28. {
  29. return (PlayerProfile) myPlayer.check(index);
  30. }
  31. public PlayerProfile findPlayer(PlayerProfile playerProfile)
  32. {
  33. return (PlayerProfile) myPlayer.check(myPlayer.find(playerProfile));
  34. }
  35. public int getMaxPlayerCount()
  36. {
  37. return myPlayer.getSize();
  38. }
  39. public int getPlayerCount()
  40. {
  41. return myPlayer.getCount();
  42. }
  43. public PlayerProfile findPlayer(int index)
  44. {
  45. return myPlayer.check(index);
  46. }
  47. public PlayerProfile findPlayer(PlayerProfile arg)
  48. {
  49. return myPlayer.find(arg);
  50. }
  51. public PlayerProfile[] findPlayer(String nome)
  52. {
  53. // mi creo un qualcosa di appoggio
  54. ArrayList<PlayerProfile> mList=new ArrayList<PlayerProfile>();
  55. for(int i=0; i<myPlayer.getCount(); i++)
  56. {
  57. PlayerProfile tmp = (PlayerProfile) myPlayer.check(i);
  58. if(tmp.getName().equals(nome))
  59. {
  60. mList.add(tmp);
  61. }
  62. }
  63. PlayerProfile[] tmpArray = new PlayerProfile[mList.size()];
  64. mList.toArray(tmpArray);
  65. return tmpArray;
  66. }
  67. public PlayerProfile removePlayer(int index)
  68. {
  69. return (PlayerProfile) myPlayer.remove(index);
  70. }
  71. public PlayerProfile[] getAll()
  72. {
  73. PlayerProfile[] tmp = new PlayerProfile[myPlayer.getSize()-1];
  74. if(!myPlayer.isEmpty())
  75. {
  76. System.arraycopy(myPlayer.toArray(), 0, tmp, 0, myPlayer.toArray().length);
  77. }
  78. return tmp;
  79. }
  80. }

comments powered by Disqus