* @return Value, or null if there is no element
* @throws NamespaceNotAvailableException when the namespace is not available.
*/
- <K, V, T extends K, N extends IdentifierNamespace<K, V>> @Nullable V getFromNamespace(Class<N> type, T key);
+ <K, V, T extends K, N extends IdentifierNamespace<K, V>> @Nullable V getFromNamespace(Class<@NonNull N> type,
+ T key);
<K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(Class<N> type);
<K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
- @NonNull StmtContext<?, ?, ?> getRoot();
+ @NonNull RootStmtContext<?, ?, ?> getRoot();
/**
* Return declared substatements. These are the statements which are explicitly written in the source model.
* @param <U> value type
* @throws NamespaceNotAvailableException when the namespace is not available.
*/
- <K, V, T extends K, U extends V, N extends IdentifierNamespace<K, V>> void addToNs(Class<N> type, T key,
- U value);
+ <K, V, T extends K, U extends V, N extends IdentifierNamespace<K, V>> void addToNs(Class<@NonNull N> type,
+ T key, U value);
@Override
- Mutable<?, ?, ?> getRoot();
+ RootStmtContext.Mutable<?, ?, ?> getRoot();
/**
* Create a child sub-statement, which is a child of this statement, inheriting all attributes from specified
* @param stmt
* to be added to namespace map
*/
- <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(Class<N> namespace, KT key,
+ <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(Class<@NonNull N> namespace, KT key,
StmtContext<?, ?, ?> stmt);
/**
void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
}
+
+ /**
+ * Search of any child statement context of specified type and return its argument. If such a statement exists, it
+ * is assumed to have the right argument. Users should be careful to use this method for statements which have
+ * cardinality {@code 0..1}, otherwise this method can return any one of the statement's argument.
+ *
+ * <p>
+ * The default implementation defers to
+ * {@link StmtContextDefaults#findSubstatementArgument(StmtContext, Class)}, subclasses are expected to provide
+ * optimized implementation if possible.
+ *
+ * @param <X> Substatement argument type
+ * @param <Z> Substatement effective statement representation
+ * @param type Effective statement representation being look up
+ * @return {@link Optional#empty()} if no statement exists, otherwise the argument value
+ */
+ default <X, Z extends EffectiveStatement<X, ?>> @NonNull Optional<X> findSubstatementArgument(
+ final @NonNull Class<Z> type) {
+ return StmtContextDefaults.findSubstatementArgument(this, type);
+ }
+
+ /**
+ * Check if there is any child statement context of specified type.
+ *
+ * <p>
+ * The default implementation defers to {@link StmtContextDefaults#hasSubstatement(StmtContext, Class)},
+ * subclasses are expected to provide optimized implementation if possible.
+ *
+ * @param type Effective statement representation being look up
+ * @return True if such a child statement exists, false otherwise
+ */
+ default boolean hasSubstatement(final @NonNull Class<? extends EffectiveStatement<?, ?>> type) {
+ return StmtContextDefaults.hasSubstatement(this, type);
+ }
}