Class TermAdapter<T>
- java.lang.Object
-
- net.sf.tweety.logics.commons.syntax.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
-
-
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<?>>
booleancontainsTermsOfType(java.lang.Class<C> cls)Checks if this logical structure contains at least one term of type C.booleanequals(java.lang.Object obj)Tget()SortgetSort()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.inthashCode()voidset(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.StringtoString()
-
-
-
Constructor Detail
-
TermAdapter
public TermAdapter(T value)
Default-Ctor: Creates an TermAdapter with the Sort "Thing"- Parameters:
value- the value of this term
-
-
Method Detail
-
getTerms
public java.util.Set<Term<?>> getTerms()
- Specified by:
getTermsin interfaceLogicStructure- 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:LogicStructureProcesses 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:
getTermsin interfaceLogicStructure- 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:LogicStructureChecks if this logical structure contains at least one term of type C. This method is a shortcut for !getTerms(TermImplementation.class).isEmpty().- Specified by:
containsTermsOfTypein interfaceLogicStructure- 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:TermSubstitutes all occurrences of term "v" in this term by term "t" and returns the new term.- Specified by:
substitutein interfaceTerm<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()
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
clone
public abstract TermAdapter<?> clone()
Description copied from interface:TermCreates a deep copy of the term
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
set
public void set(T value)
Description copied from interface:TermChanges the java-object representation of the term to the given value.
-
-