Class AbstractEffectiveStatement<A,​D extends DeclaredStatement<A>>

  • Type Parameters:
    A - Argument type (Void if statement does not have argument.)
    D - Class representing declared version of this statement.
    All Implemented Interfaces:
    EffectiveStatement<A,​D>, ModelStatement<A>
    Direct Known Subclasses:
    AbstractDeclaredEffectiveStatement, AbstractUndeclaredEffectiveStatement, EffectiveStatementBase

    @Beta
    public abstract class AbstractEffectiveStatement<A,​D extends DeclaredStatement<A>>
    extends Object
    implements EffectiveStatement<A,​D>
    Baseline stateless implementation of an EffectiveStatement. This class adds a few default implementations and namespace dispatch, but does not actually force any state on its subclasses. This approach is different from EffectiveStatementBase in that it adds requirements for an implementation, but it leaves it up to the final class to provide object layout.

    This finds immense value in catering the common case, for example effective statements which can, but typically do not, contain substatements.

    • Constructor Detail

      • AbstractEffectiveStatement

        public AbstractEffectiveStatement()
    • Method Detail

      • get

        public final <K,​V,​N extends IdentifierNamespace<K,​V>> Optional<? extends V> get​(Class<N> namespace,
                                                                                                          K identifier)
        Description copied from interface: EffectiveStatement
        Returns value associated with supplied identifier.
        Specified by:
        get in interface EffectiveStatement<A,​D extends DeclaredStatement<A>>
        Type Parameters:
        K - Identifier type
        V - Value type
        N - Namespace identifier type
        Parameters:
        namespace - Namespace type
        identifier - Identifier of element.
        Returns:
        Value if present
      • getAll

        public final <K,​V,​N extends IdentifierNamespace<K,​V>> Map<K,​V> getAll​(Class<N> namespace)
        Description copied from interface: EffectiveStatement
        Returns all local values from supplied namespace.
        Specified by:
        getAll in interface EffectiveStatement<A,​D extends DeclaredStatement<A>>
        Type Parameters:
        K - Identifier type
        V - Value type
        N - Namespace identifier type
        Parameters:
        namespace - Namespace type
        Returns:
        Key-value mappings, empty if the namespace does not exist.
      • getNamespaceContents

        protected <K,​V,​N extends IdentifierNamespace<K,​V>> Optional<? extends Map<K,​V>> getNamespaceContents​(@NonNull Class<N> namespace)
        Return the statement-specific contents of specified namespace, if available.
        Parameters:
        namespace - Requested namespace
        Returns:
        Namespace contents, if available.
      • maskList

        protected static final @NonNull Object maskList​(ImmutableList<?> list)
        Utility method for squashing singleton lists into single objects. This is a CPU/mem trade-off, which we are usually willing to make: for the cost of an instanceof check we can save one object and re-create it when needed. The inverse operation is #unmaskSubstatements(Object)}.
        Parameters:
        list - list to mask
        Returns:
        Masked list
        Throws:
        NullPointerException - if list is null
      • unmaskSet

        protected static final <T> @NonNull ImmutableSet<? extends T> unmaskSet​(@NonNull Object masked,
                                                                                @NonNull Class<T> type)