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:
    ArithmeticTerm, FunctionalTerm, NumberTerm, StringTerm

    public abstract class TermAdapter<T>
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      private Sort sort
      the type of the term
      protected T value  
    • Constructor Summary

      Constructors 
      Constructor Description
      TermAdapter​(T value)
      Default-Ctor: Creates an TermAdapter with the Sort "Thing"
      TermAdapter​(T value, Sort sort)
      Ctor: Creates a TermAdapter with the given Sort
    • Method Summary

      Modifier and Type Method Description
      abstract TermAdapter<?> clone()
      Creates a deep copy of the term
      <C extends Term<?>>
      boolean
      containsTermsOfType​(java.lang.Class<C> cls)
      Checks if this logical structure contains at least one term of type C.
      boolean equals​(java.lang.Object obj)  
      T get()  
      Sort getSort()  
      java.util.Set<Term<?>> getTerms()  
      <C extends Term<?>>
      java.util.Set<C>
      getTerms​(java.lang.Class<C> cls)
      Processes the set containing all terms of type C.
      int hashCode()  
      void set​(T value)
      Changes the java-object representation of the term to the given value.
      Term<?> substitute​(Term<?> v, Term<?> t)
      Substitutes all occurrences of term "v" in this term by term "t" and returns the new term.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • value

        protected T value
      • sort

        private Sort sort
        the type of the term
    • 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 java.util.Set<Term<?>> getTerms()
        Specified by:
        getTerms in interface LogicStructure
        Returns:
        a set containing all terms of this logical structure
      • getTerms

        public <C extends Term<?>> java.util.Set<C> getTerms​(java.lang.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​(java.lang.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 java.lang.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:
        java.lang.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 java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.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 java.lang.Object
        Returns:
        the clone
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • 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.