@Override protected ToStringHelper addToStringAttributes(final ToStringHelper helper) { return super.addToStringAttributes(helper).add("delegate", delegate); } }
@Override public Map<K, V> getAllFrom(final NamespaceStorageNode storage) { return delegate.getAllFrom(storage); }
protected NamespaceBehaviourWithListeners(final NamespaceBehaviour<K, V, N> delegate) { super(delegate.getIdentifier()); this.delegate = delegate; }
@Override public void addTo(final NamespaceStorageNode storage, final K key, final V value) { delegate.addTo(storage, key, value); notifyListeners(storage, listeners.get(derivedDelegate.getSignificantKey(key)).iterator(), value); notifyDerivedNamespaces(storage, key, value); } }
@Override public V getFrom(final NamespaceStorageNode storage, final K key) { return delegate.getFrom(storage, key); }
/** * Map of fully qualified statement name to statement definition. */ public interface QNameToStatementDefinition extends IdentifierNamespace<QName, StatementDefinition> { NamespaceBehaviour<QName, StatementDefinition, @NonNull QNameToStatementDefinition> BEHAVIOUR = NamespaceBehaviour.sourceLocal(QNameToStatementDefinition.class); /** * Returns StatementDefinition with specified QName. * * @param identifier * QName of requested statement * @return StatementDefinition */ @Override StatementDefinition get(QName identifier); /** * Returns StatementDefinition with specified namespace and localName. * * @param namespace * namespace of requested statement * @param localName * localName of requested statement * @return StatementDefinition */ @Nullable StatementDefinition getByNamespaceAndLocalName(@NonNull URI namespace, @NonNull String localName); }
NamespaceBehaviour.global(PrefixToModule.class); String DEFAULT_PREFIX = "";
final NamespaceStorageNode lookupStartStorage; if (key.isAbsolute() || storage.getStorageNodeType() == StorageNodeType.ROOT_STATEMENT_LOCAL) { lookupStartStorage = NamespaceBehaviour.findClosestTowardsRoot(storage, StorageNodeType.GLOBAL); } else { lookupStartStorage = storage;
@Override public void addTo(final NamespaceStorageNode storage, final K key, final V value) { delegate.addTo(storage, key, value); if (listeners != null) { notifyListeners(storage, listeners.iterator(), value); if (listeners.isEmpty()) { listeners = null; } } if (predicateListeners != null) { final Iterator<PredicateValueAddedListener<K, V>> it = predicateListeners.iterator(); while (it.hasNext()) { if (it.next().onValueAdded(key, value)) { it.remove(); } } if (predicateListeners.isEmpty()) { predicateListeners = null; } } notifyDerivedNamespaces(storage, key, value); } }
final <V> boolean isRequestedValue(final NamespaceBehaviour<K, ? , ?> behavior, final NamespaceStorageNode storage, final V value) { return value == behavior.getFrom(getCtxNode(), key); }
protected final V getFromLocalStorage(final NamespaceStorageNode storage, final K key) { return storage.getFromLocalStorage(getIdentifier(), key); }
@Override protected ToStringHelper addToStringAttributes(final ToStringHelper helper) { return super.addToStringAttributes(helper.add("type", storageType)); } }
public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(final Class<N> type) { return getBehaviourRegistry().getNamespaceBehaviour(type).getAllFrom(this); }
/** * 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); }
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); }
public <K, V, N extends IdentifierNamespace<K, V>> Builder addSupport( final NamespaceBehaviour<K, V, N> namespaceSupport) { final Class<N> identifier = namespaceSupport.getIdentifier(); checkState(!namespaces.containsKey(identifier)); checkState(!parent.hasNamespaceBehaviour(identifier)); namespaces.put(identifier, namespaceSupport); return this; }
@Override // FIXME: 3.0.0: make this final public String toString() { return addToStringAttributes(MoreObjects.toStringHelper(this)).toString(); }
/** * Returns the key/value mapping best matching specified criterion. * * @param storage namespace storage * @param criterion selection criterion * @return Selected mapping, if available. */ public final Optional<Entry<K, V>> getFrom(final NamespaceStorageNode storage, final NamespaceKeyCriterion<K> criterion) { final Map<K, V> mappings = getAllFrom(storage); if (mappings == null) { return Optional.empty(); } Entry<K, V> match = null; for (Entry<K, V> entry : mappings.entrySet()) { final K key = entry.getKey(); if (criterion.match(key)) { if (match != null) { final K selected = criterion.select(match.getKey(), key); if (selected.equals(match.getKey())) { continue; } Verify.verify(selected == key, "Criterion %s selected invalid key %s from candidates [%s %s]", selected, match.getKey(), key); } match = entry; } } return Optional.ofNullable(match); }
/** * 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); }
/** * 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); }