Class AssociativeFormulaSupport<T extends SimpleLogicalFormula>
- java.lang.Object
-
- net.sf.tweety.logics.commons.syntax.ComplexLogicalFormulaAdapter
-
- net.sf.tweety.logics.commons.syntax.AssociativeFormulaSupport<T>
-
- Type Parameters:
T- The type of the formulas which are saved by the associative formula support.
- All Implemented Interfaces:
Iterable<T>,Collection<T>,List<T>,net.sf.tweety.commons.Formula,AssociativeFormula<T>,ComplexLogicalFormula,LogicStructure,SimpleLogicalFormula
public class AssociativeFormulaSupport<T extends SimpleLogicalFormula> extends ComplexLogicalFormulaAdapter implements AssociativeFormula<T>
This class provides common implementation for associative formulas that are formulas which consists of several other formulas. It implements common methods like getTerms(), getFormulas() or getAtoms(). Although SimpleLogicalFormula can be used as content for an associative Formula this support class also implements the functionality for ComplexLogicalFormula and assumes that methods of ComplexLogicalFormula like substitute() are not called by the parent of the AssociativeFormulaSupport, otherwise a ClassCastException will occur.- Author:
- Tim Janus
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAssociativeFormulaSupport.AssociativeSupportBridgeThis interface defines a bridge between the AssociativeFormula implementation like a concrete Disjunction and the AssociativeFormulaSupport object which adds the implementation of the common functionality.
-
Constructor Summary
Constructors Constructor Description AssociativeFormulaSupport(AssociativeFormulaSupport.AssociativeSupportBridge bridge)Ctor: Creates a AssociativeFormulaSupport object that uses the given bridgeAssociativeFormulaSupport(AssociativeFormulaSupport<T> other)Copy-Ctor creates a deep copy of the associative formula support.
-
Method Summary
Modifier and Type Method Description voidadd(int index, T element)booleanadd(T e)booleanadd(T... formulas)Appends the specified elements to the end of this collection (optional operation).booleanaddAll(int index, Collection<? extends T> c)booleanaddAll(Collection<? extends T> c)voidclear()AssociativeFormulaSupport<T>clone()Creates a deep copy of this formulabooleancontains(Object o)booleancontainsAll(Collection<?> c)Collection<T>copyHelper(Collection<T> collection)This method generates a deep copy of the given collection of RelationalFormulabooleanequals(Object other)Tget(int index)Set<? extends Atom>getAtoms()Processes the set of all atoms which appear in this formulaList<T>getFormulas()<C extends SimpleLogicalFormula>
Set<C>getFormulas(Class<C> cls)Process the formulas of type C that are children of this associative formulaClass<? extends Predicate>getPredicateCls()Set<? extends Predicate>getPredicates()Processes the set of all predicates which appear in this formulanet.sf.tweety.commons.SignaturegetSignature()Set<Term<?>>getTerms()<C extends Term<?>>
Set<C>getTerms(Class<C> cls)Processes the set containing all terms of type C.inthashCode()intindexOf(Object o)booleanisEmpty()booleanisWellFormed()Checks if this formula is well formed in the logical langauge.Iterator<T>iterator()intlastIndexOf(Object o)ListIterator<T>listIterator()ListIterator<T>listIterator(int index)Tremove(int index)booleanremove(Object o)booleanremoveAll(Collection<?> c)booleanretainAll(Collection<?> c)Tset(int index, T element)intsize()List<T>subList(int fromIndex, int toIndex)ComplexLogicalFormulasubstitute(Term<?> v, Term<?> t)Substitutes all occurrences of term "v" in this formula by term "t" and returns the new formula.Object[]toArray()<C> C[]toArray(C[] a)StringtoString()-
Methods inherited from class net.sf.tweety.logics.commons.syntax.ComplexLogicalFormulaAdapter
containsTermsOfType, exchange, isGround, isLiteral, substitute
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
replaceAll, sort, spliterator
-
Methods inherited from interface net.sf.tweety.logics.commons.syntax.interfaces.SimpleLogicalFormula
isLiteral
-
-
-
-
Constructor Detail
-
AssociativeFormulaSupport
public AssociativeFormulaSupport(AssociativeFormulaSupport.AssociativeSupportBridge bridge)
Ctor: Creates a AssociativeFormulaSupport object that uses the given bridge- Parameters:
bridge- an associative support bridge
-
AssociativeFormulaSupport
public AssociativeFormulaSupport(AssociativeFormulaSupport<T> other)
Copy-Ctor creates a deep copy of the associative formula support.- Parameters:
other- another associative formula suppport
-
-
Method Detail
-
copyHelper
public Collection<T> copyHelper(Collection<T> collection)
This method generates a deep copy of the given collection of RelationalFormula- Parameters:
collection- The collection of RelationalFormula to copy- Returns:
- A collection containing the deep copy of the given collection
-
getFormulas
public List<T> getFormulas()
- Specified by:
getFormulasin interfaceAssociativeFormula<T extends SimpleLogicalFormula>- Returns:
- all the formulas saved as childs in the associative formula
-
getFormulas
public <C extends SimpleLogicalFormula> Set<C> getFormulas(Class<C> cls)
Description copied from interface:AssociativeFormulaProcess the formulas of type C that are children of this associative formula- Specified by:
getFormulasin interfaceAssociativeFormula<T extends SimpleLogicalFormula>- Type Parameters:
C- the type of formulas- Parameters:
cls- the class structure defining the type of formulas which are searched.- Returns:
- A set of formulas of type C which are members of the associative formula
-
getAtoms
public Set<? extends Atom> getAtoms()
Description copied from interface:SimpleLogicalFormulaProcesses the set of all atoms which appear in this formula- Specified by:
getAtomsin interfaceSimpleLogicalFormula- Returns:
- The set of all atoms
-
getPredicates
public Set<? extends Predicate> getPredicates()
Description copied from interface:SimpleLogicalFormulaProcesses the set of all predicates which appear in this formula- Specified by:
getPredicatesin interfaceSimpleLogicalFormula- Returns:
- all predicates that appear in this formula
-
getSignature
public net.sf.tweety.commons.Signature getSignature()
- Specified by:
getSignaturein interfacenet.sf.tweety.commons.Formula
-
equals
public boolean equals(Object other)
- Specified by:
equalsin interfaceCollection<T extends SimpleLogicalFormula>- Specified by:
equalsin interfaceList<T extends SimpleLogicalFormula>- Specified by:
equalsin interfaceSimpleLogicalFormula- Overrides:
equalsin classObject
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceCollection<T extends SimpleLogicalFormula>- Specified by:
hashCodein interfaceList<T extends SimpleLogicalFormula>- Specified by:
hashCodein interfaceSimpleLogicalFormula- Overrides:
hashCodein classObject
-
clone
public AssociativeFormulaSupport<T> clone()
Description copied from interface:SimpleLogicalFormulaCreates a deep copy of this formula- Specified by:
clonein interfaceComplexLogicalFormula- Specified by:
clonein interfaceSimpleLogicalFormula- Specified by:
clonein classComplexLogicalFormulaAdapter- Returns:
- the cloned formula
-
getTerms
public Set<Term<?>> getTerms()
- Specified by:
getTermsin interfaceLogicStructure- 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: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- Overrides:
getTermsin classComplexLogicalFormulaAdapter- 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
-
substitute
public ComplexLogicalFormula substitute(Term<?> v, Term<?> t) throws IllegalArgumentException
Description copied from interface:ComplexLogicalFormulaSubstitutes all occurrences of term "v" in this formula by term "t" and returns the new formula.- Specified by:
substitutein interfaceComplexLogicalFormula- Parameters:
v- the term to be substituted.t- the term to substitute.- Returns:
- a formula where every occurrence of "v" is replaced by "t".
- Throws:
IllegalArgumentException- if "v" and "t" are of different sorts
-
isWellFormed
public boolean isWellFormed()
Description copied from interface:ComplexLogicalFormulaChecks if this formula is well formed in the logical langauge. What well- formed means is highly language dependent and the documentation of implementing sub classes shall describe the well formed term for the language they model.- Specified by:
isWellFormedin interfaceComplexLogicalFormula- Overrides:
isWellFormedin classComplexLogicalFormulaAdapter- Returns:
- true if the formula is well-formed, false otherwise
-
add
public boolean add(T e)
- Specified by:
addin interfaceCollection<T extends SimpleLogicalFormula>- Specified by:
addin interfaceList<T extends SimpleLogicalFormula>
-
add
public boolean add(T... formulas)
Appends the specified elements to the end of this collection (optional operation).- Parameters:
formulas- to be appended to collection- Returns:
- true if all elements were added, false otherwise
-
addAll
public boolean addAll(Collection<? extends T> c)
- Specified by:
addAllin interfaceCollection<T extends SimpleLogicalFormula>- Specified by:
addAllin interfaceList<T extends SimpleLogicalFormula>
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<T extends SimpleLogicalFormula>- Specified by:
clearin interfaceList<T extends SimpleLogicalFormula>
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceCollection<T extends SimpleLogicalFormula>- Specified by:
containsin interfaceList<T extends SimpleLogicalFormula>
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAllin interfaceCollection<T extends SimpleLogicalFormula>- Specified by:
containsAllin interfaceList<T extends SimpleLogicalFormula>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<T extends SimpleLogicalFormula>- Specified by:
isEmptyin interfaceList<T extends SimpleLogicalFormula>
-
iterator
public Iterator<T> iterator()
- Specified by:
iteratorin interfaceCollection<T extends SimpleLogicalFormula>- Specified by:
iteratorin interfaceIterable<T extends SimpleLogicalFormula>- Specified by:
iteratorin interfaceList<T extends SimpleLogicalFormula>
-
remove
public boolean remove(Object o)
- Specified by:
removein interfaceCollection<T extends SimpleLogicalFormula>- Specified by:
removein interfaceList<T extends SimpleLogicalFormula>
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAllin interfaceCollection<T extends SimpleLogicalFormula>- Specified by:
removeAllin interfaceList<T extends SimpleLogicalFormula>
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAllin interfaceCollection<T extends SimpleLogicalFormula>- Specified by:
retainAllin interfaceList<T extends SimpleLogicalFormula>
-
size
public int size()
- Specified by:
sizein interfaceCollection<T extends SimpleLogicalFormula>- Specified by:
sizein interfaceList<T extends SimpleLogicalFormula>
-
toArray
public Object[] toArray()
- Specified by:
toArrayin interfaceCollection<T extends SimpleLogicalFormula>- Specified by:
toArrayin interfaceList<T extends SimpleLogicalFormula>
-
toArray
public <C> C[] toArray(C[] a)
- Specified by:
toArrayin interfaceCollection<T extends SimpleLogicalFormula>- Specified by:
toArrayin interfaceList<T extends SimpleLogicalFormula>
-
getPredicateCls
public Class<? extends Predicate> getPredicateCls()
- Specified by:
getPredicateClsin interfaceSimpleLogicalFormula- Returns:
- The class description of the predicate used by this formula.
-
add
public void add(int index, T element)- Specified by:
addin interfaceList<T extends SimpleLogicalFormula>
-
addAll
public boolean addAll(int index, Collection<? extends T> c)- Specified by:
addAllin interfaceList<T extends SimpleLogicalFormula>
-
get
public T get(int index)
- Specified by:
getin interfaceList<T extends SimpleLogicalFormula>
-
indexOf
public int indexOf(Object o)
- Specified by:
indexOfin interfaceList<T extends SimpleLogicalFormula>
-
lastIndexOf
public int lastIndexOf(Object o)
- Specified by:
lastIndexOfin interfaceList<T extends SimpleLogicalFormula>
-
listIterator
public ListIterator<T> listIterator()
- Specified by:
listIteratorin interfaceList<T extends SimpleLogicalFormula>
-
listIterator
public ListIterator<T> listIterator(int index)
- Specified by:
listIteratorin interfaceList<T extends SimpleLogicalFormula>
-
remove
public T remove(int index)
- Specified by:
removein interfaceList<T extends SimpleLogicalFormula>
-
set
public T set(int index, T element)
- Specified by:
setin interfaceList<T extends SimpleLogicalFormula>
-
-