mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-27 14:13:11 +02:00
[BLIND] Extend API further.
Despite having an interface yet, add things like unregister many objects (items) and getting all registered items, e.g. for dealing with sub-registries efficiently (at first code-wise).
This commit is contained in:
parent
2b51dfa8b8
commit
730d09aa78
@ -1,5 +1,7 @@
|
||||
package fr.neatmonster.nocheatplus.components.registry.store;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@ -41,6 +43,10 @@ public class RegisteredItemStore {
|
||||
*/
|
||||
static class ItemNode <T> implements IGetRegistrationOrder, Comparable<ItemNode<T>> {
|
||||
|
||||
/*
|
||||
* TODO: Looking ahead, should probably rather equal on base of the
|
||||
* stored item (HashSet). Sorting by internalId may use a Comparator.
|
||||
*/
|
||||
// TODO: implement IGetItem
|
||||
|
||||
final RegistrationOrder order;
|
||||
@ -78,6 +84,13 @@ public class RegisteredItemStore {
|
||||
};
|
||||
|
||||
static final class ItemList <T> {
|
||||
|
||||
/*
|
||||
* Looking ahead: Should probably rather use a LinkedHashSet for
|
||||
* itemNodes, for faster removal and contains check. Sorting by
|
||||
* internalId may use a Comparator.
|
||||
*/
|
||||
|
||||
/** I bit heavy on the tip of the blade, java. */
|
||||
private final SortItemNode<T> typedSort = new SortItemNode<T>();
|
||||
// TODO: always fetch an array and store as sorted.
|
||||
@ -374,6 +387,23 @@ public class RegisteredItemStore {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister each of all given items from all types it had been registered
|
||||
* for.
|
||||
*
|
||||
* @param items
|
||||
* @return
|
||||
* @throws NullPointerException
|
||||
* If items or any of the items within items is null.
|
||||
*/
|
||||
public boolean unregister(final Collection<Object> items) {
|
||||
boolean had = false;
|
||||
for (final Object item : items) {
|
||||
had |= unregister(item);
|
||||
}
|
||||
return had;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if an item is registered for a given type.
|
||||
*
|
||||
@ -429,6 +459,15 @@ public class RegisteredItemStore {
|
||||
return items.containsKey(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a copy of all registered items.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<Object> getAllRegisteredItems() {
|
||||
return new ArrayList<Object>(items.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure all contained lists are sorted and optimized.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user