Class ApplicationContextImpl
-
- All Implemented Interfaces:
-
io.github.funofprograming.context.ApplicationContext
public class ApplicationContextImpl implements ApplicationContext
Plain vanilla implementation of {@linkplain ApplicationContext}
Akshay Jain
-
-
Constructor Summary
Constructors Constructor Description ApplicationContextImpl(String name, Set<Key<?>> permittedKeys, ApplicationContext initialCopy)ApplicationContextImpl(String name, Set<Key<?>> permittedKeys)
-
Method Summary
Modifier and Type Method Description StringgetName()Application context name Set<Key<?>>getPermittedKeys()Keys permitted for this context. BooleanisKeyValid(Key<?> key)Checks if key is valid for this context. <T extends Any> UnitaddIfNotPresent(Key<T> key, T value)Add value for given key if not already present. <T extends Any> ObjectaddWithOverwrite(Key<T> key, T value)Add value for given key even if already present. <T extends Any> Unitadd(Key<T> key, T value)Add value for given key. <T extends Any> Booleanexists(Key<T> key)Check if any value or null associated with give key <T extends Any> Tfetch(Key<T> key)Fetch value associated with key or null <T extends Any> Terase(Key<T> key)Erase value associated with key if any Unitclear()Clear the entire context Set<Key<?>>keySet()Get a set of keys in context Unitmerge(ApplicationContext other, ApplicationContextMergeStrategy mergeStrategy)Merge other context with this using the given merge strategy ApplicationContextclone(String cloneName, Set<Key<?>> clonePermittedKeys)Creates a clone of this context with passed cloneName and clonePermittedKeys. Booleanequals(Object other)IntegerhashCode()-
-
Method Detail
-
getPermittedKeys
Set<Key<?>> getPermittedKeys()
Keys permitted for this context. Empty set means all keys permitted.
Implementations should allow setting up of PermittedKeys at time of context initialization
- Returns:
set of permitted keys
-
isKeyValid
Boolean isKeyValid(Key<?> key)
Checks if key is valid for this context.
- Returns:
key
-
addIfNotPresent
<T extends Any> Unit addIfNotPresent(Key<T> key, T value)
Add value for given key if not already present.
This is semmantically same as
if(!exists(key)) add(key, value)*- Parameters:
value- </T>
-
addWithOverwrite
<T extends Any> Object addWithOverwrite(Key<T> key, T value)
Add value for given key even if already present.
- Returns:
Previous value associated with key if any or null </T>
-
exists
<T extends Any> Boolean exists(Key<T> key)
Check if any value or null associated with give key
- Returns:
true if value or null associated with give key otherwise false </T>
-
fetch
<T extends Any> T fetch(Key<T> key)
Fetch value associated with key or null
- Returns:
value associated with key or null </T>
-
erase
<T extends Any> T erase(Key<T> key)
Erase value associated with key if any
- Returns:
value associate with key or null </T>
-
merge
Unit merge(ApplicationContext other, ApplicationContextMergeStrategy mergeStrategy)
Merge other context with this using the given merge strategy
- Parameters:
other- other context.
-
clone
ApplicationContext clone(String cloneName, Set<Key<?>> clonePermittedKeys)
Creates a clone of this context with passed cloneName and clonePermittedKeys. While cloning only the permittedKeys will be added
- Parameters:
cloneName- name of the cloned ApplicationContextclonePermittedKeys- permittedKeys of the cloned ApplicationContext
-
-
-
-