Class AssociativeFormulaSupport<T extends SimpleLogicalFormula>
java.lang.Object
org.tweetyproject.logics.commons.syntax.ComplexLogicalFormulaAdapter
org.tweetyproject.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>
,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
Modifier and TypeClassDescriptionstatic interface
This 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
ConstructorDescriptionCtor: Creates a AssociativeFormulaSupport object that uses the given bridgeCopy-Ctor creates a deep copy of the associative formula support. -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
boolean
Appends the specified elements to the end of this collection (optional operation).boolean
addAll
(int index, Collection<? extends T> c) boolean
addAll
(Collection<? extends T> c) void
clear()
clone()
Creates a deep copy of this formulaboolean
boolean
containsAll
(Collection<?> c) copyHelper
(Collection<T> collection) This method generates a deep copy of the given collection of RelationalFormulaboolean
get
(int index) getAtoms()
Processes the set of all atoms which appear in this formula<C extends SimpleLogicalFormula>
Set<C>getFormulas
(Class<C> cls) Process the formulas of type C that are children of this associative formulaProcesses the set of all predicates which appear in this formulaReturns the signature of the language of this formula.getTerms()
Processes the set containing all terms of type C.int
hashCode()
int
boolean
isEmpty()
boolean
Checks if this formula is well formed in the logical langauge.iterator()
int
listIterator
(int index) remove
(int index) boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) int
size()
subList
(int fromIndex, int toIndex) substitute
(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) toString()
Methods inherited from class org.tweetyproject.logics.commons.syntax.ComplexLogicalFormulaAdapter
containsTermsOfType, exchange, isGround, isLiteral, substitute
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 org.tweetyproject.logics.commons.syntax.interfaces.SimpleLogicalFormula
isLiteral
-
Constructor Details
-
AssociativeFormulaSupport
Ctor: Creates a AssociativeFormulaSupport object that uses the given bridge- Parameters:
bridge
- an associative support bridge
-
AssociativeFormulaSupport
Copy-Ctor creates a deep copy of the associative formula support.- Parameters:
other
- another associative formula suppport
-
-
Method Details
-
copyHelper
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
- Specified by:
getFormulas
in interfaceAssociativeFormula<T extends SimpleLogicalFormula>
- Returns:
- all the formulas saved as childs in the associative formula
-
getFormulas
Description copied from interface:AssociativeFormula
Process the formulas of type C that are children of this associative formula- Specified by:
getFormulas
in 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
Description copied from interface:SimpleLogicalFormula
Processes the set of all atoms which appear in this formula- Specified by:
getAtoms
in interfaceSimpleLogicalFormula
- Returns:
- The set of all atoms
-
getPredicates
Description copied from interface:SimpleLogicalFormula
Processes the set of all predicates which appear in this formula- Specified by:
getPredicates
in interfaceSimpleLogicalFormula
- Returns:
- all predicates that appear in this formula
-
getSignature
Description copied from interface:Formula
Returns the signature of the language of this formula.- Specified by:
getSignature
in interfaceFormula
- Returns:
- the signature of the language of this formula.
-
toString
-
equals
- Specified by:
equals
in interfaceCollection<T extends SimpleLogicalFormula>
- Specified by:
equals
in interfaceList<T extends SimpleLogicalFormula>
- Specified by:
equals
in interfaceSimpleLogicalFormula
- Overrides:
equals
in classObject
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<T extends SimpleLogicalFormula>
- Specified by:
hashCode
in interfaceList<T extends SimpleLogicalFormula>
- Specified by:
hashCode
in interfaceSimpleLogicalFormula
- Overrides:
hashCode
in classObject
-
clone
Description copied from interface:SimpleLogicalFormula
Creates a deep copy of this formula- Specified by:
clone
in interfaceComplexLogicalFormula
- Specified by:
clone
in interfaceSimpleLogicalFormula
- Specified by:
clone
in classComplexLogicalFormulaAdapter
- Returns:
- the cloned formula
-
getTerms
- Specified by:
getTerms
in interfaceLogicStructure
- Returns:
- a set containing all terms of this logical structure
-
getTerms
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
- Overrides:
getTerms
in 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
Description copied from interface:ComplexLogicalFormula
Substitutes all occurrences of term "v" in this formula by term "t" and returns the new formula.- Specified by:
substitute
in 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:ComplexLogicalFormula
Checks 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:
isWellFormed
in interfaceComplexLogicalFormula
- Overrides:
isWellFormed
in classComplexLogicalFormulaAdapter
- Returns:
- true if the formula is well-formed, false otherwise
-
add
- Specified by:
add
in interfaceCollection<T extends SimpleLogicalFormula>
- Specified by:
add
in interfaceList<T extends SimpleLogicalFormula>
-
add
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
- Specified by:
addAll
in interfaceCollection<T extends SimpleLogicalFormula>
- Specified by:
addAll
in interfaceList<T extends SimpleLogicalFormula>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<T extends SimpleLogicalFormula>
- Specified by:
clear
in interfaceList<T extends SimpleLogicalFormula>
-
contains
- Specified by:
contains
in interfaceCollection<T extends SimpleLogicalFormula>
- Specified by:
contains
in interfaceList<T extends SimpleLogicalFormula>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<T extends SimpleLogicalFormula>
- Specified by:
containsAll
in interfaceList<T extends SimpleLogicalFormula>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<T extends SimpleLogicalFormula>
- Specified by:
isEmpty
in interfaceList<T extends SimpleLogicalFormula>
-
iterator
- Specified by:
iterator
in interfaceCollection<T extends SimpleLogicalFormula>
- Specified by:
iterator
in interfaceIterable<T extends SimpleLogicalFormula>
- Specified by:
iterator
in interfaceList<T extends SimpleLogicalFormula>
-
remove
- Specified by:
remove
in interfaceCollection<T extends SimpleLogicalFormula>
- Specified by:
remove
in interfaceList<T extends SimpleLogicalFormula>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<T extends SimpleLogicalFormula>
- Specified by:
removeAll
in interfaceList<T extends SimpleLogicalFormula>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<T extends SimpleLogicalFormula>
- Specified by:
retainAll
in interfaceList<T extends SimpleLogicalFormula>
-
size
public int size()- Specified by:
size
in interfaceCollection<T extends SimpleLogicalFormula>
- Specified by:
size
in interfaceList<T extends SimpleLogicalFormula>
-
toArray
- Specified by:
toArray
in interfaceCollection<T extends SimpleLogicalFormula>
- Specified by:
toArray
in interfaceList<T extends SimpleLogicalFormula>
-
toArray
public <C> C[] toArray(C[] a) - Specified by:
toArray
in interfaceCollection<T extends SimpleLogicalFormula>
- Specified by:
toArray
in interfaceList<T extends SimpleLogicalFormula>
-
getPredicateCls
- Specified by:
getPredicateCls
in interfaceSimpleLogicalFormula
- Returns:
- The class description of the predicate used by this formula.
-
add
- Specified by:
add
in interfaceList<T extends SimpleLogicalFormula>
-
addAll
- Specified by:
addAll
in interfaceList<T extends SimpleLogicalFormula>
-
get
- Specified by:
get
in interfaceList<T extends SimpleLogicalFormula>
-
indexOf
- Specified by:
indexOf
in interfaceList<T extends SimpleLogicalFormula>
-
lastIndexOf
- Specified by:
lastIndexOf
in interfaceList<T extends SimpleLogicalFormula>
-
listIterator
- Specified by:
listIterator
in interfaceList<T extends SimpleLogicalFormula>
-
listIterator
- Specified by:
listIterator
in interfaceList<T extends SimpleLogicalFormula>
-
remove
- Specified by:
remove
in interfaceList<T extends SimpleLogicalFormula>
-
set
- Specified by:
set
in interfaceList<T extends SimpleLogicalFormula>
-
subList
- Specified by:
subList
in interfaceList<T extends SimpleLogicalFormula>
-