Class RegisteredMap<K,V extends Registered>
- Type Parameters:
K- The map's key.V- The map's registerable value.
- All Implemented Interfaces:
Registered,Registered.All,Registered.Client,Registered.Common,Registered.Generated,Registered.Server
- Direct Known Subclasses:
ArmorMap,DyeMap,PlaceholderMimicItem.Group
Object2ObjectOpenHashMap, where all values implement the
Registered interface and are generated using a provided computation function.
This is most useful when generating a large amount of values at once. For a small number of items, it may be better to instead just instantiate normally.
- Since:
- 1.5.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface dev.jaxydog.astral.register.Registered
Registered.All, Registered.Client, Registered.Common, Registered.Generated, Registered.Server -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedRegisteredMap(@NotNull String basePath, BiFunction<@NotNull String, @NotNull K, V> computeCallback) Creates a new registered map. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract intcompareKeys(K left, K right) Compares the provided keys to determine their registration order.protected voidComputes all values stored within the map.voidComputes all values stored within the map if they have not yet been created.entries()Returns a set of all entries stored within this map.voidgenerate()Generates game assets or data.Returns a value from within the map if it is assigned to the given key.getComputed(K key) Returns a value from within the map, creating it if it does not exist.getNullable(K key) Returns a value from within the map.protected abstract StringReturns an identifier path based off of the given key.Returns this value's associated registry identifier path.keys()Returns the set of all expected keys.voidRegisters this value on the client environment.voidRegisters this value on both the client and server environments.voidRegisters this value on the server environment.sortedValuesOfType(Class<? extends Registered> type) Returns a list of sorted values that match the expected registered type.values()Returns a collection of the values stored within this map.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.jaxydog.astral.register.Registered
getRegistryId
-
Field Details
-
innerMap
The inner hash map that contains all generated keys and values.- Since:
- 2.0.0
-
-
Constructor Details
-
RegisteredMap
protected RegisteredMap(@NotNull @NotNull String basePath, BiFunction<@NotNull String, @NotNull K, V> computeCallback) Creates a new registered map.- Parameters:
basePath- The base identifier path.computeCallback- The value computation callback.- Since:
- 2.0.0
-
-
Method Details
-
keys
Returns the set of all expected keys.The values within this set are fed into the computation callback to generate the values stored within this map.
- Returns:
- A set containing all expected keys.
- Since:
- 2.0.0
-
compareKeys
Compares the provided keys to determine their registration order.If
leftis lesser thanright, a negative value should be returned. Ifleftis greater thanright, a positive value should be returned. Otherwise, if both are equal,0should be returned.For a simple example, assuming
<K>is of typeInteger, the value can be determined by evaluatingright - leftfor a simple natural ordering.- Parameters:
left- The left key.right- The right key.- Returns:
- The result as defined in the method documentation.
- Since:
- 2.0.0
-
getPath
Returns an identifier path based off of the given key.- Parameters:
key- The value's key.- Returns:
- A valid identifier path.
- Since:
- 2.0.0
-
get
Returns a value from within the map if it is assigned to the given key.If the given key is present within the map, this is equivalent to calling
Optional.ofNullable(map.getNullable(key)).- Parameters:
key- The value's expected key.- Returns:
- A possible value.
- Since:
- 2.0.0
-
getNullable
Returns a value from within the map.- Parameters:
key- The value's expected key.- Returns:
- A value, or
nullif the value is not present. - Since:
- 2.0.0
-
getComputed
Returns a value from within the map, creating it if it does not exist.- Parameters:
key- The value's expected key.- Returns:
- A value, or
nullif the value is not present. - Since:
- 2.0.0
-
entries
Returns a set of all entries stored within this map.- Returns:
- A set of all stored entries.
- Since:
- 2.0.0
-
values
Returns a collection of the values stored within this map.- Returns:
- A collection of stored values.
- Since:
- 2.0.0
-
computeValuesIfMissing
public void computeValuesIfMissing()Computes all values stored within the map if they have not yet been created.If the
keys()method returns an empty set, this method does nothing.- Since:
- 2.0.0
-
computeValues
protected void computeValues()Computes all values stored within the map.If any keys are stored within the map that are included within the set returned by {}, they will be overwritten.
If the
keys()method returns an empty set, this method does nothing.- Since:
- 2.0.0
-
sortedValuesOfType
Returns a list of sorted values that match the expected registered type.- Parameters:
type- The expected type.- Returns:
- A list of sorted values.
- Since:
- 2.0.0
-
getRegistryPath
Description copied from interface:RegisteredReturns this value's associated registry identifier path.This is by default used to determine the
Identifierprovided byRegistered.getRegistryId(). For example, returning"my_item"will cause the associated identifier to beastral:my_item.- Specified by:
getRegistryPathin interfaceRegistered- Returns:
- An identifier path.
-
registerCommon
public void registerCommon()Description copied from interface:Registered.CommonRegisters this value on both the client and server environments.The contained code will run for both environments. If you only want one or the other, see its sister interfaces.
- Specified by:
registerCommonin interfaceRegistered.Common- See Also:
-
registerClient
public void registerClient()Description copied from interface:Registered.ClientRegisters this value on the client environment.The contained code will only ever run on the game client. If you only want the server or want both, see its sister interfaces.
- Specified by:
registerClientin interfaceRegistered.Client- See Also:
-
registerServer
public void registerServer()Description copied from interface:Registered.ServerRegisters this value on the server environment.The contained code will only ever run on the game server. If you only want the client or want both, see its sister interfaces.
- Specified by:
registerServerin interfaceRegistered.Server- See Also:
-
generate
public void generate()Description copied from interface:Registered.GeneratedGenerates game assets or data.It should be assumed that the contained code will only ever run on the server environment.
- Specified by:
generatein interfaceRegistered.Generated
-