Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.hyperion.rs2.content.clan;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.HashSet;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Optional;
- import java.util.function.IntConsumer;
- import java.util.stream.IntStream;
- import org.hyperion.rs2.model.Player;
- /**
- * A clan collection
- *
- * @author Dan0194
- */
- public abstract class ClanList<T> {
- /**
- * The list containing the data
- */
- private final List<T> list;
- /**
- * The first line id in the list
- */
- private int first;
- /**
- * The second line id in the list
- */
- private int second;
- /**
- * @param first to the first
- * @param second to the second
- */
- public ClanList(int first, int second, int size) {
- this.list = new ArrayList<T>(size);
- this.first = first;
- this.second = second;
- }
- /**
- * Called when there is an update
- *
- * @param owner The owner recieving the update
- * @param value The optional value given on update
- * @param slot The slot is the line id of the update
- */
- public abstract void onUpdate(Player owner, Optional<T> value, int slot);
- /**
- * Sends an update that has no owner value
- */
- public void update() {
- update(null);
- }
- /**
- * Starts the updating of the list
- *
- * @param owner The person recieving the update
- */
- public void update(Player owner) {
- /** Loops through all the line ids */
- IntStream.range(first, second).forEach(new IntConsumer() {
- @Override
- public void accept(int value) {
- /** The slot of the line id */
- int slot = value - first;
- /** The Optional value */
- Optional<T> name = slot < list.size() ? Optional.of(list.get(slot)) : Optional.empty();
- /** Calls the update method */
- onUpdate(owner, name, value);
- }
- });
- }
- /**
- * Gets the list
- *
- * @return list
- */
- public List<T> getList() {
- return list;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment