Class TypeCache


  • public final class TypeCache
    extends java.lang.Object
    Implements a type cache to avoid repeatedly identifying, iterating over and collecting constraints for complex types.
    Author:
    Holger Eichelberger
    • Field Detail

      • ENABLED

        public static final boolean ENABLED
        Globally enables or disables type-caching.
        See Also:
        Constant Field Values
      • ON_DEMAND_ACCESSORS

        static final boolean ON_DEMAND_ACCESSORS
        Variable-accessor and name-accessor mappings may be transferred back to the current context in one copy step false or step-wise and on-demand only true. Only active if #ENABLED.
        See Also:
        Constant Field Values
    • Constructor Detail

      • TypeCache

        public TypeCache()
    • Method Detail

      • get

        public TypeCache.Entry get​(IDatatype type)
        Returns a type cache entry for the given type.
        Parameters:
        type - the type to return the cache entry for
        Returns:
        the cache entry, may be null for none
      • contains

        public boolean contains​(IDatatype type)
        Returns whether this type cache contains an entry for type.
        Parameters:
        type - the type to look for
        Returns:
        true if type is in the cache, false else
      • createEntryFor

        public TypeCache.Entry createEntryFor​(IDatatype type,
                                              AbstractVariable var)
        Creates a type cache entry.
        Parameters:
        type - the type to create the entry for
        var - the template varible
        Returns:
        the created entry
      • transferConstraints

        public boolean transferConstraints​(IDatatype type,
                                           TypeCache.IConstraintTarget target,
                                           IDecisionVariable register,
                                           AbstractVariable var)
        Transfers collected constraints for type.
        Parameters:
        type - the type to transfer the constraints to
        target - the constraint target receiving instantiated constraints
        register - the variable to register new constraints with
        var - the variable to replace the template variable
        Returns:
        true for transferred, false else
      • transferContext

        public void transferContext​(IDatatype type,
                                    java.util.Map<AbstractVariable,​ConstraintSyntaxTree> varMap,
                                    java.util.Map<java.lang.String,​ConstraintSyntaxTree> nameMap)
        Transfers the mappings of the given context into the cache entry of type.
        Parameters:
        type - the type
        varMap - the variable-accessor mapping (optional, may be null)
        nameMap - the name-accessor mapping (optional, may be null)
      • transferToContext

        public void transferToContext​(IDatatype type,
                                      ContextStack contexts,
                                      AbstractVariable var)
        Transfers all accessors stored in TypeCache.Entry.varMap into the actual context in contexts by instantiating them.
        Parameters:
        type - the type to transfer
        contexts - the target contexts (using the actual one)
        var - the variable to instantiate for