private <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> ensureLocalNamespace(final Class<N> type) { @SuppressWarnings("unchecked") Map<K, V> ret = (Map<K,V>) namespaces.get(type); if (ret == null) { checkLocalNamespaceAllowed(type); ret = new HashMap<>(1); if (namespaces.isEmpty()) { namespaces = new HashMap<>(1); } namespaces.put(type, ret); } return ret; }
@Override public <K, V, N extends IdentifierNamespace<K, V>> V putToLocalStorage(final Class<N> type, final K key, final V value) { final V ret = ensureLocalNamespace(type).put(key, value); onNamespaceElementAdded(type, key, value); return ret; }
public final <K, V, N extends IdentifierNamespace<K, V>> Optional<Entry<K, V>> getFromNamespace( final Class<N> type, final NamespaceKeyCriterion<K> criterion) { return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, criterion); }
/** * Associate a context with a key within a namespace. * * @param type Namespace type * @param key Key * @param value Context value * @param <K> namespace key type * @param <N> namespace type * @throws NamespaceNotAvailableException when the namespace is not available. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public final <K, N extends StatementNamespace<K, ?,?>> void addContextToNamespace(final Class<N> type, final K key, final StmtContext<?, ?, ?> value) { getBehaviourRegistry().getNamespaceBehaviour((Class)type).addTo(this, key, value); }
@Override public <K, V, N extends IdentifierNamespace<K, V>> V putToLocalStorageIfAbsent(final Class<N> type, final K key, final V value) { final V ret = ensureLocalNamespace(type).putIfAbsent(key, value); if (ret == null) { onNamespaceElementAdded(type, key, value); } return ret; } }
public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(final Class<N> type) { return getBehaviourRegistry().getNamespaceBehaviour(type).getAllFrom(this); }
/** * Return a value associated with specified key within a namespace. * * @param type Namespace type * @param key Key * @param <K> namespace key type * @param <V> namespace value type * @param <N> namespace type * @param <T> key type * @return Value, or null if there is no element * @throws NamespaceNotAvailableException when the namespace is not available. */ public final <K, V, T extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(final Class<N> type, final T key) { return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, key); }
/** * Associate a value with a key within a namespace. * * @param type Namespace type * @param key Key * @param value value * @param <K> namespace key type * @param <V> namespace value type * @param <N> namespace type * @param <T> key type * @param <U> value type * @throws NamespaceNotAvailableException when the namespace is not available. */ public final <K, V, T extends K, U extends V, N extends IdentifierNamespace<K, V>> void addToNs( final Class<N> type, final T key, final U value) { getBehaviourRegistry().getNamespaceBehaviour(type).addTo(this,key,value); }