Guest User

Untitled

a guest
Mar 10th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. package org.hyperion.rs2.content.clan;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Collection;
  5. import java.util.HashSet;
  6. import java.util.Iterator;
  7. import java.util.List;
  8. import java.util.Optional;
  9. import java.util.function.IntConsumer;
  10. import java.util.stream.IntStream;
  11.  
  12. import org.hyperion.rs2.model.Player;
  13.  
  14. /**
  15. * A clan collection
  16. *
  17. * @author Dan0194
  18. */
  19. public abstract class ClanList<T> {
  20.  
  21. /**
  22. * The list containing the data
  23. */
  24. private final List<T> list;
  25.  
  26.  
  27. /**
  28. * The first line id in the list
  29. */
  30. private int first;
  31.  
  32. /**
  33. * The second line id in the list
  34. */
  35. private int second;
  36.  
  37. /**
  38. * @param first to the first
  39. * @param second to the second
  40. */
  41. public ClanList(int first, int second, int size) {
  42. this.list = new ArrayList<T>(size);
  43. this.first = first;
  44. this.second = second;
  45. }
  46.  
  47.  
  48. /**
  49. * Called when there is an update
  50. *
  51. * @param owner The owner recieving the update
  52. * @param value The optional value given on update
  53. * @param slot The slot is the line id of the update
  54. */
  55. public abstract void onUpdate(Player owner, Optional<T> value, int slot);
  56.  
  57. /**
  58. * Sends an update that has no owner value
  59. */
  60. public void update() {
  61. update(null);
  62. }
  63.  
  64. /**
  65. * Starts the updating of the list
  66. *
  67. * @param owner The person recieving the update
  68. */
  69. public void update(Player owner) {
  70.  
  71. /** Loops through all the line ids */
  72. IntStream.range(first, second).forEach(new IntConsumer() {
  73.  
  74. @Override
  75. public void accept(int value) {
  76.  
  77. /** The slot of the line id */
  78. int slot = value - first;
  79.  
  80. /** The Optional value */
  81. Optional<T> name = slot < list.size() ? Optional.of(list.get(slot)) : Optional.empty();
  82.  
  83. /** Calls the update method */
  84. onUpdate(owner, name, value);
  85.  
  86. }
  87.  
  88. });
  89. }
  90.  
  91. /**
  92. * Gets the list
  93. *
  94. * @return list
  95. */
  96. public List<T> getList() {
  97. return list;
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment