Package jodd.util
Class TypeCache<T>
- java.lang.Object
-
- jodd.util.TypeCache<T>
-
public class TypeCache<T> extends java.lang.ObjectTypes cache. Provides several implementations depending on what you need to be addressed. There are two things you should take care off:- synchronization - especially on storing items. If not synchronized, one instance of an item may be put more then once into the map. This is usually fine, as it happens only during the initialization and makes not harm if something is created twice
- weak - if your key classes are replaced during the runtime, you should use weak map, in order to automatically remove obsolete keys.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTypeCache.Builder<A>
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears complete cache.static <A> TypeCache.Builder<A>create()Creates a type cache by using a builder.static <A> TypeCache<A>createDefault()Creates default implementation of the type cache.voidforEachValue(java.util.function.Consumer<? super T> valueConsumer)Iterates all cached values.Tget(java.lang.Class<?> key)Returns value from the map ornullif value does not exist.<K> Tget(java.lang.Class<K> key, java.util.function.Function<java.lang.Class<K>,? extends T> mappingFunction)Returns existing value or add default supplied one.booleanisEmpty()Returnstrueif cache is empty.Tput(java.lang.Class<?> type, T value)Add values to the map.Tremove(java.lang.Class<?> type)Removes element from the type cache.intsize()Returns cache size.
-
-
-
Method Detail
-
create
public static <A> TypeCache.Builder<A> create()
Creates a type cache by using a builder.
-
createDefault
public static <A> TypeCache<A> createDefault()
Creates default implementation of the type cache.
-
get
public T get(java.lang.Class<?> key)
Returns value from the map ornullif value does not exist.
-
get
public <K> T get(java.lang.Class<K> key, java.util.function.Function<java.lang.Class<K>,? extends T> mappingFunction)
Returns existing value or add default supplied one. Use this method instead ofget-nullcheck-putblock when thread-safety is of importance.
-
remove
public T remove(java.lang.Class<?> type)
Removes element from the type cache.
-
clear
public void clear()
Clears complete cache.
-
size
public int size()
Returns cache size.
-
isEmpty
public boolean isEmpty()
Returnstrueif cache is empty.
-
forEachValue
public void forEachValue(java.util.function.Consumer<? super T> valueConsumer)
Iterates all cached values.
-
-