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.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()
-
-
-
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:
getTerms
in 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: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 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: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 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:Term
Substitutes all occurrences of term "v" in this term by term "t" and returns the new term.- Specified by:
substitute
in 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:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
clone
public abstract TermAdapter<?> clone()
Description copied from interface:Term
Creates a deep copy of the term
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.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.
-
-