Class AttributeHolder
-
- All Implemented Interfaces:
public class AttributeHolderApp level, default ttl=12H, unbounded thread safe cache. Need manually register and remove (or publish AttributeRidEvent)
- Since:
2021-03-30
trydofor
-
-
Field Summary
Fields Modifier and Type Field Description public final static intTtlDefault
-
Constructor Summary
Constructors Constructor Description AttributeHolder()
-
Method Summary
Modifier and Type Method Description static <K, V> AttributeCache<K, V>getCache(@NotNull() TypedReg<K, V> reg)static Set<TypedReg<out Object, out Object>>holders()static <K, V> voidregLoader(@NotNull() TypedReg<K, V> reg, @NotNull() Function<K, V> loader)Registering a typed key-value and its loader static <K, V> voidputAttr(@NotNull() TypedReg<K, V> reg, @NotNull() K key, @NotNull() V value)Put an attribute value to the typed key. static <K, V> voidputAttr(@NotNull() TypedReg<K, V> reg, @NotNull() K key, @NotNull() V value, int ttl)Put an attribute value to the typed key. static <K, V> voidputAttrs(@NotNull() TypedReg<K, V> reg, @NotNull() Map<K, V> map)Put all attribute value from map to the typed key. static <K, V> voidputAttrs(@NotNull() TypedReg<K, V> reg, @NotNull() Map<K, V> map, int ttl)Put all attribute value from map to the typed key. static <K, V> VtryAttr(@NotNull() TypedReg<K, V> reg, @NotNull() K key, V elze)Try to get an attribute by typed key, load it if not found, return `elze` if the result is null. static <K, V> VtryAttr(@NotNull() TypedReg<K, V> reg, @NotNull() K key, V elze, int ttl)Try to get an attribute by typed key, load it if not found, return `elze` if the result is null. static <K, V> VtryAttr(@NotNull() TypedReg<K, V> reg, @NotNull() K key)Try to get an attribute by typed key, load it if not found, throw NPE if the result is null. static <K, V> VtryAttr(@NotNull() TypedReg<K, V> reg, @NotNull() K key, int ttl)Try to get an attribute by typed key, load it if not found, throw NPE if the result is null. static <K, V> VtryAttr(@NotNull() TypedReg<K, V> reg, @NotNull() K key, boolean notnull)Try to get an attribute by typed key, load it if not found, throw NPE if notnull and the result is null. static <K, V> VtryAttr(@NotNull() TypedReg<K, V> reg, @NotNull() K key, boolean notnull, int ttl)Try to get an attribute by typed key, load it if not found, throw NPE if notnull and the result is null. static <K, V> VgetAttr(@NotNull() TypedReg<K, V> reg, @NotNull() K key)Get an attribute by typed key, and NOT load if not found. static <K, V> Map<K, V>getAttrs(@NotNull() TypedReg<K, V> reg, @NotNull() Collection<K> key)Get all attributes by typed keys, and NOT load if not found. static <K> voidridAttr(TypedReg<K, out Object> reg, K key)remove an attribute by key static <K> voidridAttrs(TypedReg<K, out Object> reg, Collection<out K> key)remove all attribute by keys static voidridAttrAll(Array<TypedReg<out Object, out Object>> reg)remove all attribute of type static voidridAttrAll(Collection<out TypedReg<out Object, out Object>> reg)remove all attribute of type static voidridLoader(Array<TypedReg<out Object, out Object>> reg)remove the loader static voidridLoader(Collection<out TypedReg<out Object, out Object>> reg)remove the loader static voidunregister(Array<TypedReg<out Object, out Object>> reg)unregister from the event -
-
Method Detail
-
regLoader
static <K, V> void regLoader(@NotNull() TypedReg<K, V> reg, @NotNull() Function<K, V> loader)
Registering a typed key-value and its loader
- Parameters:
reg- Type to registerloader- returns `null` is not cached and is called every time, so it is recommended to return `nonnull`.
-
putAttr
static <K, V> void putAttr(@NotNull() TypedReg<K, V> reg, @NotNull() K key, @NotNull() V value)
Put an attribute value to the typed key.
- Parameters:
reg- Type to registerkey- unique key, e.g.value- value
-
putAttr
static <K, V> void putAttr(@NotNull() TypedReg<K, V> reg, @NotNull() K key, @NotNull() V value, int ttl)
Put an attribute value to the typed key.
- Parameters:
reg- Type to registerkey- unique key, e.g.value- valuettl- ttl in second
-
putAttrs
static <K, V> void putAttrs(@NotNull() TypedReg<K, V> reg, @NotNull() Map<K, V> map)
Put all attribute value from map to the typed key.
- Parameters:
reg- Type to registermap- map of attribute
-
putAttrs
static <K, V> void putAttrs(@NotNull() TypedReg<K, V> reg, @NotNull() Map<K, V> map, int ttl)
Put all attribute value from map to the typed key.
- Parameters:
reg- Type to registermap- map of attributettl- ttl in second
-
tryAttr
@Contract(value = "_,_,!null->!null") static <K, V> V tryAttr(@NotNull() TypedReg<K, V> reg, @NotNull() K key, V elze)
Try to get an attribute by typed key, load it if not found, return `elze` if the result is null.
- Parameters:
reg- Type to registerkey- unique key, e.g.elze- return `elze` if result is null
-
tryAttr
@Contract(value = "_,_,!null,_->!null") static <K, V> V tryAttr(@NotNull() TypedReg<K, V> reg, @NotNull() K key, V elze, int ttl)
Try to get an attribute by typed key, load it if not found, return `elze` if the result is null.
- Parameters:
reg- Type to registerkey- unique key, e.g.elze- return `elze` if result is nullttl- ttl in second
-
tryAttr
@NotNull() static <K, V> V tryAttr(@NotNull() TypedReg<K, V> reg, @NotNull() K key)
Try to get an attribute by typed key, load it if not found, throw NPE if the result is null.
- Parameters:
reg- Type to registerkey- unique key, e.g.
-
tryAttr
@NotNull() static <K, V> V tryAttr(@NotNull() TypedReg<K, V> reg, @NotNull() K key, int ttl)
Try to get an attribute by typed key, load it if not found, throw NPE if the result is null.
- Parameters:
reg- Type to registerkey- unique key, e.g.ttl- ttl in second
-
tryAttr
@Contract(value = "_,_,true ->!null") static <K, V> V tryAttr(@NotNull() TypedReg<K, V> reg, @NotNull() K key, boolean notnull)
Try to get an attribute by typed key, load it if not found, throw NPE if notnull and the result is null.
- Parameters:
reg- Type to registerkey- unique key, e.g.notnull- whether notnull
-
tryAttr
@Contract(value = "_,_,true,_ ->!null") static <K, V> V tryAttr(@NotNull() TypedReg<K, V> reg, @NotNull() K key, boolean notnull, int ttl)
Try to get an attribute by typed key, load it if not found, throw NPE if notnull and the result is null.
- Parameters:
reg- Type to registerkey- unique key, e.g.notnull- whether notnullttl- ttl in second
-
getAttr
@Nullable() static <K, V> V getAttr(@NotNull() TypedReg<K, V> reg, @NotNull() K key)
Get an attribute by typed key, and NOT load if not found.
- Parameters:
reg- Type to registerkey- unique key, e.g.
-
getAttrs
@NotNull() static <K, V> Map<K, V> getAttrs(@NotNull() TypedReg<K, V> reg, @NotNull() Collection<K> key)
Get all attributes by typed keys, and NOT load if not found.
- Parameters:
reg- Type to registerkey- unique key, e.g.
-
ridAttr
static <K> void ridAttr(TypedReg<K, out Object> reg, K key)
remove an attribute by key
- Parameters:
reg- Type to registerkey- unique key, e.g.
-
ridAttrs
static <K> void ridAttrs(TypedReg<K, out Object> reg, Collection<out K> key)
remove all attribute by keys
- Parameters:
reg- Type to registerkey- unique key, e.g.
-
ridAttrAll
static void ridAttrAll(Array<TypedReg<out Object, out Object>> reg)
remove all attribute of type
- Parameters:
reg- Type to register
-
ridAttrAll
static void ridAttrAll(Collection<out TypedReg<out Object, out Object>> reg)
remove all attribute of type
- Parameters:
reg- Type to register
-
ridLoader
static void ridLoader(Array<TypedReg<out Object, out Object>> reg)
remove the loader
- Parameters:
reg- Type to register
-
ridLoader
static void ridLoader(Collection<out TypedReg<out Object, out Object>> reg)
remove the loader
- Parameters:
reg- Type to register
-
unregister
static void unregister(Array<TypedReg<out Object, out Object>> reg)
unregister from the event
-
-
-
-