Package net.orbyfied.j8.registry
Class Registry<T extends Identifiable>
java.lang.Object
net.orbyfied.j8.registry.Registry<T>
- Type Parameters:
T- The type of registry item. Restricted to ? extends Identifiable
- All Implemented Interfaces:
Iterable<T>,Identifiable,net.orbyfied.j8.util.functional.KeyProvider<Identifier>,net.orbyfied.j8.util.functional.ValueProvider<T>
public class Registry<T extends Identifiable>
extends Object
implements Identifiable, Iterable<T>, net.orbyfied.j8.util.functional.KeyProvider<Identifier>, net.orbyfied.j8.util.functional.ValueProvider<T>
Class for mapped and linear storage
of uniquely identified items using
an
Identifier. Utilizes a
HashMap and
ArrayList for
mapped and linear storage respectively.
Every registry has it's own identifier as well.
But most importantly, it allows for the addition of
mapping and listing modules and services to add functionality.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddComponent(Class<? extends RegistryComponent<Registry<T>, T, ?, ?>> of) addComponent(Class<M> of, Consumer<M> consumer) addComponent(Function<Registry<T>, RegistryComponent<Registry<T>, T, ?, ?>> f) addComponent(RegistryComponent<Registry<T>, T, ?, ?> module) addService(Class<? extends RegistryService<Registry<T>, T>> of) addService(Class<M> of, Consumer<M> consumer) addService(Function<Registry<T>, RegistryService<Registry<T>, T>> f) addService(RegistryService<Registry<T>, T> service) autoRegisterFrom(Class<?> klass, Object... instances) Registers all registrable items which allow it across the static fields and instance fields which are retrieved for every instance.net.orbyfied.j8.util.ops.EntryOperation<Registry<T>,Identifier, T> boolean<R extends T>
RGets an item by identifier.Gets an item by identifier.getByIndex(int i) Gets an item by index.<K,V, M extends RegistryComponent<Registry<T>, T, K, V>>
MgetComponent(int index) <K,V, M extends RegistryComponent<Registry<T>, T, K, V>>
MgetComponent(Class<M> klass) List<RegistryComponent<Registry<T>,T, ?, ?>> Map<Class<? extends RegistryComponent<Registry<T>,T, ?, ?>>, RegistryComponent<Registry<T>, T, ?, ?>> intGets the unique identifier of this registered/registrable item.<K,V, M extends RegistryService<Registry<T>, T>>
MgetService(int index) <K,V, M extends RegistryService<Registry<T>, T>>
MgetService(Class<M> klass) Map<Class<? extends RegistryService<Registry<T>,T>>, RegistryService<Registry<T>, T>> <S> ArrayList<S>getServicesOf(Class<S> type) <S> ArrayList<S>getServicesOf(Class<S> type, ArrayList<S> list) int<K,R> R getValue(K key) booleanhas(Identifier id) booleaninthashCode()iterator()linear()mapped()voidprovideKeys(net.orbyfied.j8.util.functional.Accumulator<Identifier> acc) voidprovideValues(net.orbyfied.j8.util.functional.Accumulator<T> acc) Registers a new item to the registry.removeComponent(Class<? extends RegistryComponent<Registry<T>, T, ?, ?>> klass) removeComponent(RegistryComponent<Registry<T>, T, ?, ?> module) removeService(Class<? extends RegistryService<Registry<T>, T>> klass) removeService(RegistryService<Registry<T>, T> service) intsize()Gets the size of the registry.toString()unregister(String id) Unregisters an item from the registry.unregister(Identifier id) Unregisters an item from the registry.unregister(T item) Unregisters an item from the registry.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface net.orbyfied.j8.registry.Identifiable
registerMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Registry
Base constructor.- Parameters:
identifier- The identifier of this registry.
-
Registry
Base constructor.- Parameters:
identifier- The identifier in string form.
-
-
Method Details
-
getIdentifier
Description copied from interface:IdentifiableGets the unique identifier of this registered/registrable item. This should always be the same.- Specified by:
getIdentifierin interfaceIdentifiable- Returns:
- The unique identifier of this registry.
- See Also:
-
size
public int size()Gets the size of the registry.- Returns:
- The size.
-
getByIndex
Gets an item by index.- Parameters:
i- The index.- Returns:
- The item.
-
getByIdentifier
Gets an item by identifier.- Parameters:
id- The identifier.- Returns:
- The item.
-
getByIdentifier
Gets an item by identifier.- Parameters:
id- The identifier as string.- Returns:
- The item.
-
register
Registers a new item to the registry.- Parameters:
item- The item to register.- Returns:
- This.
-
unregister
Unregisters an item from the registry.- Parameters:
item- The item to remove.- Returns:
- This.
-
unregister
Unregisters an item from the registry.- Parameters:
id- The identifier of the item to remove.- Returns:
- This.
-
unregister
Unregisters an item from the registry.- Parameters:
id- The identifier of the item to remove as string.- Returns:
- This.
-
linear
- Returns:
- The immutable list of items.
-
mapped
- Returns:
- The immutable map of identifiers to items.
-
getValue
public <K,R> R getValue(K key) -
entry
-
has
-
has
-
getComponent
-
getComponent
-
addComponent
-
addComponent
-
addComponent
-
addComponent
-
removeComponent
-
removeComponent
-
getComponentsMapped
public Map<Class<? extends RegistryComponent<Registry<T>,T, getComponentsMapped()?, ?>>, RegistryComponent<Registry<T>, T, ?, ?>> -
getComponentsLinear
-
getComponentsSize
public int getComponentsSize() -
getService
-
getService
-
addService
-
addService
-
addService
-
addService
-
removeService
-
removeService
-
getServicesOf
-
getServicesOf
-
getServicesLinear
-
getServicesMapped
public Map<Class<? extends RegistryService<Registry<T>,T>>, getServicesMapped()RegistryService<Registry<T>, T>> -
getServicesSize
public int getServicesSize() -
autoRegisterFrom
Registers all registrable items which allow it across the static fields and instance fields which are retrieved for every instance.- Parameters:
klass- The class.instances- The instances.- Returns:
- This.
-
provideKeys
- Specified by:
provideKeysin interfacenet.orbyfied.j8.util.functional.KeyProvider<T extends Identifiable>
-
provideValues
- Specified by:
provideValuesin interfacenet.orbyfied.j8.util.functional.ValueProvider<T extends Identifiable>
-
iterator
- Specified by:
iteratorin interfaceIterable<T extends Identifiable>
-
toString
-
equals
-
hashCode
public int hashCode()
-