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:
java.lang.Iterable<T>
,java.util.Collection<T>
,java.util.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
Nested Classes Modifier and Type Class Description static interface
AssociativeFormulaSupport.AssociativeSupportBridge
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
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 void
add(int index, T element)
boolean
add(T e)
boolean
add(T... formulas)
Appends the specified elements to the end of this collection (optional operation).boolean
addAll(int index, java.util.Collection<? extends T> c)
boolean
addAll(java.util.Collection<? extends T> c)
void
clear()
AssociativeFormulaSupport<T>
clone()
Creates a deep copy of this formulaboolean
contains(java.lang.Object o)
boolean
containsAll(java.util.Collection<?> c)
java.util.Collection<T>
copyHelper(java.util.Collection<T> collection)
This method generates a deep copy of the given collection of RelationalFormulaboolean
equals(java.lang.Object other)
T
get(int index)
java.util.Set<? extends Atom>
getAtoms()
Processes the set of all atoms which appear in this formulajava.util.List<T>
getFormulas()
<C extends SimpleLogicalFormula>
java.util.Set<C>getFormulas(java.lang.Class<C> cls)
Process the formulas of type C that are children of this associative formulajava.lang.Class<? extends Predicate>
getPredicateCls()
java.util.Set<? extends Predicate>
getPredicates()
Processes the set of all predicates which appear in this formulaSignature
getSignature()
Returns the signature of the language of this formula.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()
int
indexOf(java.lang.Object o)
boolean
isEmpty()
boolean
isWellFormed()
Checks if this formula is well formed in the logical langauge.java.util.Iterator<T>
iterator()
int
lastIndexOf(java.lang.Object o)
java.util.ListIterator<T>
listIterator()
java.util.ListIterator<T>
listIterator(int index)
T
remove(int index)
boolean
remove(java.lang.Object o)
boolean
removeAll(java.util.Collection<?> c)
boolean
retainAll(java.util.Collection<?> c)
T
set(int index, T element)
int
size()
java.util.List<T>
subList(int fromIndex, int toIndex)
ComplexLogicalFormula
substitute(Term<?> v, Term<?> t)
Substitutes all occurrences of term "v" in this formula by term "t" and returns the new formula.java.lang.Object[]
toArray()
<C> C[]
toArray(C[] a)
java.lang.String
toString()
-
Methods inherited from class net.sf.tweety.logics.commons.syntax.ComplexLogicalFormulaAdapter
containsTermsOfType, exchange, isGround, isLiteral, substitute
-
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 java.util.Collection<T> copyHelper(java.util.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 java.util.List<T> getFormulas()
- Specified by:
getFormulas
in interfaceAssociativeFormula<T extends SimpleLogicalFormula>
- Returns:
- all the formulas saved as childs in the associative formula
-
getFormulas
public <C extends SimpleLogicalFormula> java.util.Set<C> getFormulas(java.lang.Class<C> cls)
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
public java.util.Set<? extends Atom> 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
public java.util.Set<? extends Predicate> 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
public Signature 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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Specified by:
equals
in interfacejava.util.Collection<T extends SimpleLogicalFormula>
- Specified by:
equals
in interfacejava.util.List<T extends SimpleLogicalFormula>
- Specified by:
equals
in interfaceSimpleLogicalFormula
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfacejava.util.Collection<T extends SimpleLogicalFormula>
- Specified by:
hashCode
in interfacejava.util.List<T extends SimpleLogicalFormula>
- Specified by:
hashCode
in interfaceSimpleLogicalFormula
- Overrides:
hashCode
in classjava.lang.Object
-
clone
public AssociativeFormulaSupport<T> 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
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
- 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
public ComplexLogicalFormula substitute(Term<?> v, Term<?> t) throws java.lang.IllegalArgumentException
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:
java.lang.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
public boolean add(T e)
- Specified by:
add
in interfacejava.util.Collection<T extends SimpleLogicalFormula>
- Specified by:
add
in interfacejava.util.List<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(java.util.Collection<? extends T> c)
- Specified by:
addAll
in interfacejava.util.Collection<T extends SimpleLogicalFormula>
- Specified by:
addAll
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Collection<T extends SimpleLogicalFormula>
- Specified by:
clear
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
contains
in interfacejava.util.Collection<T extends SimpleLogicalFormula>
- Specified by:
contains
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAll
in interfacejava.util.Collection<T extends SimpleLogicalFormula>
- Specified by:
containsAll
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfacejava.util.Collection<T extends SimpleLogicalFormula>
- Specified by:
isEmpty
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
iterator
public java.util.Iterator<T> iterator()
- Specified by:
iterator
in interfacejava.util.Collection<T extends SimpleLogicalFormula>
- Specified by:
iterator
in interfacejava.lang.Iterable<T extends SimpleLogicalFormula>
- Specified by:
iterator
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
remove
in interfacejava.util.Collection<T extends SimpleLogicalFormula>
- Specified by:
remove
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAll
in interfacejava.util.Collection<T extends SimpleLogicalFormula>
- Specified by:
removeAll
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAll
in interfacejava.util.Collection<T extends SimpleLogicalFormula>
- Specified by:
retainAll
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
size
public int size()
- Specified by:
size
in interfacejava.util.Collection<T extends SimpleLogicalFormula>
- Specified by:
size
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArray
in interfacejava.util.Collection<T extends SimpleLogicalFormula>
- Specified by:
toArray
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
toArray
public <C> C[] toArray(C[] a)
- Specified by:
toArray
in interfacejava.util.Collection<T extends SimpleLogicalFormula>
- Specified by:
toArray
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
getPredicateCls
public java.lang.Class<? extends Predicate> getPredicateCls()
- Specified by:
getPredicateCls
in interfaceSimpleLogicalFormula
- Returns:
- The class description of the predicate used by this formula.
-
add
public void add(int index, T element)
- Specified by:
add
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
addAll
public boolean addAll(int index, java.util.Collection<? extends T> c)
- Specified by:
addAll
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
get
public T get(int index)
- Specified by:
get
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
indexOf
public int indexOf(java.lang.Object o)
- Specified by:
indexOf
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOf
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
listIterator
public java.util.ListIterator<T> listIterator()
- Specified by:
listIterator
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
listIterator
public java.util.ListIterator<T> listIterator(int index)
- Specified by:
listIterator
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
remove
public T remove(int index)
- Specified by:
remove
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
set
public T set(int index, T element)
- Specified by:
set
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
subList
public java.util.List<T> subList(int fromIndex, int toIndex)
- Specified by:
subList
in interfacejava.util.List<T extends SimpleLogicalFormula>
-
-