Class TermAdapter<T>

  • Type Parameters:
    T - The type of the value saved in the term, this might be a string if the term is a constant or a variable, or it might be an integer if the term is a number term.
    All Implemented Interfaces:
    LogicStructure, Term<T>
    Direct Known Subclasses:
    FunctionalTerm, NumberTerm, StringTerm

    public abstract class TermAdapter<T>
    extends Object
    implements Term<T>
    Abstract base class implementing the substitute(), getSort(), getTerms(), and containsTermsOfType() methods in a way it is useful for terms.
    Author:
    Tim Janus, Matthias Thimm
    • Field Detail

      • value

        protected T value
    • Constructor Detail

      • TermAdapter

        public TermAdapter​(T value)
        Default-Ctor: Creates an TermAdapter with the Sort "Thing"
        Parameters:
        value - the value of this term
      • TermAdapter

        public TermAdapter​(T value,
                           Sort sort)
        Ctor: Creates a TermAdapter with the given Sort
        Parameters:
        value - the value of this term
        sort - The Sort (Type) of the TermAdapter instance
    • Method Detail

      • getTerms

        public Set<Term<?>> getTerms()
        Specified by:
        getTerms in interface LogicStructure
        Returns:
        a set containing all terms of this logical structure
      • getTerms

        public <C extends Term<?>> Set<C> getTerms​(Class<C> cls)
        Description copied from interface: LogicStructure
        Processes the set containing all terms of type C. This method uses the equals method of the given Class and therefore does not add terms which are sub classes of type C to the set.
        Specified by:
        getTerms in interface LogicStructure
        Type Parameters:
        C - the type of terms
        Parameters:
        cls - The Class structure containing type information about the searched term
        Returns:
        A set containing all terms of type C of this logical structure
      • containsTermsOfType

        public <C extends Term<?>> boolean containsTermsOfType​(Class<C> cls)
        Description copied from interface: LogicStructure
        Checks if this logical structure contains at least one term of type C. This method is a shortcut for !getTerms(TermImplementation.class).isEmpty().
        Specified by:
        containsTermsOfType in interface LogicStructure
        Type Parameters:
        C - the type of terms
        Parameters:
        cls - The class structure representing the type C of the term.
        Returns:
        True if this logical structure contains at least one term of type C or false otherwise.
      • substitute

        public Term<?> substitute​(Term<?> v,
                                  Term<?> t)
                           throws IllegalArgumentException
        Description copied from interface: Term
        Substitutes all occurrences of term "v" in this term by term "t" and returns the new term.
        Specified by:
        substitute in interface Term<T>
        Parameters:
        v - the term to be substituted.
        t - the term to substitute.
        Returns:
        a term where every occurrence of "v" is replaced by "t".
        Throws:
        IllegalArgumentException - if "v" and "t" are of different sorts (NOTE: this exception is only thrown when "v" actually appears in this formula)
      • getSort

        public Sort getSort()
        Specified by:
        getSort in interface Term<T>
        Returns:
        the sort (type) of this term.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • clone

        public abstract TermAdapter<?> clone()
        Description copied from interface: Term
        Creates a deep copy of the term
        Specified by:
        clone in interface Term<T>
        Overrides:
        clone in class Object
        Returns:
        the clone
      • set

        public void set​(T value)
        Description copied from interface: Term
        Changes the java-object representation of the term to the given value.
        Specified by:
        set in interface Term<T>
        Parameters:
        value - The new java-object representation of the term.
      • get

        public T get()
        Specified by:
        get in interface Term<T>
        Returns:
        the java-object representation of the term.