Class ConstraintList
- java.lang.Object
-
- net.ssehub.easy.reasoning.core.reasoner.ConstraintList
-
- All Implemented Interfaces:
java.lang.Iterable<Constraint>
- Direct Known Subclasses:
ConstraintBase
public class ConstraintList extends java.lang.Object implements java.lang.Iterable<Constraint>
Implements a constraint list. This list assumes reference equality for constraints. Partially taken over fromLinkedListto fix types and to allow access from subclasses.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceConstraintList.IModificationListenerA listener to be informed if the underlying list changes.protected static classConstraintList.NodeThe node type in a linked constraint base.
-
Field Summary
Fields Modifier and Type Field Description private ConstraintList.Nodefirstprivate ConstraintList.Nodelastprivate ConstraintList.IModificationListenerlistenerprotected intmodCountprivate intsize
-
Constructor Summary
Constructors Modifier Constructor Description ConstraintList()Constructs an empty constraint base.protectedConstraintList(ConstraintList.IModificationListener listener)Constructs an empty constraint base.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Constraint constraint)Appends the specified constraint to the end of this constraint base.booleanaddAll(int index, java.util.Collection<? extends Constraint> constraints)Inserts all of the constraints in the specified collection into this list, starting at the specified position.booleanaddAll(int index, ConstraintList constraints)Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.booleanaddAll(int index, ConstraintList constraints, boolean clear)Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.private voidaddAll(int index, Constraint[] cArray)Adds all constraints fromcArrayto this collection at positionindex.booleanaddAll(java.util.Collection<? extends Constraint> constraints)Appends all of the constraints in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.booleanaddAll(ConstraintList constraints)Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.booleanaddAll(ConstraintList constraints, boolean clear)Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.voidaddFirst(Constraint constraint)Inserts the specifiedconstraintat the beginning of this constraint base.voidaddLast(Constraint constraint)Appends the specifiedconstraintto the end of this constraint base.private voidcheckPositionIndex(int index)Checksindexto be a valid position.voidclear()Removes all of the elements from this list.booleancontains(Constraint constraint)Returnstrueif this list contains the specifiedconstraint.ConstraintgetFirst()Returns the first constraint in this list.ConstraintgetLast()Returns the last constraint in this list.intindexOf(Constraint constraint)Returns the index of the first occurrence of the specifiedconstraintin this list, or -1 if this list does not contain the element.booleanisEmpty()Returnstrueif this list contains no constraints.private booleanisPositionIndex(int index)Tells if the argument is the index of a valid position for an iterator or an add operation.java.util.Iterator<Constraint>iterator()Returns an iterator over the elements in this list (in proper sequence).private voidlinkFirst(Constraint constraint)Linksconstraintas first constraint.private voidlinkLast(Constraint constraint)Linksconstraintas last constraint.private ConstraintList.Nodenode(int index)Returns the (non-null) Node at the specified element index.private java.lang.StringoutOfBoundsMsg(int index)Constructs an IndexOutOfBoundsException detail message.Constraintpop()Pops an element from the stack represented by this list.booleanremoveAll(java.util.Collection<? extends Constraint> constraints)Removes all elements from this list, which are also inconstraints.ConstraintremoveFirst()Removes and returns the first constraint from this list.ConstraintremoveLast()Removes and returns the last constraint from this list.protected voidsetModificationListener(ConstraintList.IModificationListener listener)Changes the modification listener.intsize()Returns the number of constraints in this constraint base.Constraint[]toArray()Turns this list into an array containing all constraints.voidtoCollection(java.util.Collection<Constraint> collection)Adds all elements in this list to acollectionof constraints.java.lang.StringtoString()Turns the list into its string representation.(package private) Constraintunlink(ConstraintList.Node node)Unlinks non-null node x.private ConstraintunlinkFirst(ConstraintList.Node node)Unlinks non-null first nodenode.private ConstraintunlinkLast(ConstraintList.Node node)Unlinks non-null last nodenode.
-
-
-
Field Detail
-
modCount
protected transient int modCount
-
size
private int size
-
first
private ConstraintList.Node first
-
last
private ConstraintList.Node last
-
listener
private transient ConstraintList.IModificationListener listener
-
-
Constructor Detail
-
ConstraintList
public ConstraintList()
Constructs an empty constraint base.
-
ConstraintList
protected ConstraintList(ConstraintList.IModificationListener listener)
Constructs an empty constraint base.- Parameters:
listener- the modification listener (null for none)
-
-
Method Detail
-
setModificationListener
protected void setModificationListener(ConstraintList.IModificationListener listener)
Changes the modification listener.- Parameters:
listener- the modification listener (null for none)
-
contains
public boolean contains(Constraint constraint)
Returnstrueif this list contains the specifiedconstraint. More formally, returnstrueif and only if this list contains at least one constraintconstraintsuch thato == constraint.- Parameters:
constraint- the constraint whose presence in this list is to be tested- Returns:
trueif this list contains the specified element
-
indexOf
public int indexOf(Constraint constraint)
Returns the index of the first occurrence of the specifiedconstraintin this list, or -1 if this list does not contain the element. More formally, returns the lowest indexisuch thato == get(i), or -1 if there is no such index.- Parameters:
constraint- constraint to search for- Returns:
- the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element
-
getFirst
public Constraint getFirst()
Returns the first constraint in this list.- Returns:
- the first constraint in this list
- Throws:
java.util.NoSuchElementException- if this list is empty
-
getLast
public Constraint getLast()
Returns the last constraint in this list.- Returns:
- the last constraint in this list
- Throws:
java.util.NoSuchElementException- if this list is empty
-
size
public int size()
Returns the number of constraints in this constraint base.- Returns:
- the number of constraints in this constraint base
-
isEmpty
public boolean isEmpty()
Returnstrueif this list contains no constraints.- Returns:
trueif this list contains no constraints
-
add
public void add(Constraint constraint)
Appends the specified constraint to the end of this constraint base.- Parameters:
constraint- constraint to be appended
-
addFirst
public void addFirst(Constraint constraint)
Inserts the specifiedconstraintat the beginning of this constraint base.- Parameters:
constraint- the constraint to add
-
addLast
public void addLast(Constraint constraint)
Appends the specifiedconstraintto the end of this constraint base.- Parameters:
constraint- the constraint to add
-
clear
public void clear()
Removes all of the elements from this list. The list will be empty after this call returns.
-
addAll
public boolean addAll(java.util.Collection<? extends Constraint> constraints)
Appends all of the constraints in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)- Parameters:
constraints- collection containing constraints to be added to this list- Returns:
trueif this list changed as a result of the call- Throws:
java.lang.NullPointerException- if the specified collection is null
-
addAll
public boolean addAll(int index, java.util.Collection<? extends Constraint> constraints)Inserts all of the constraints in the specified collection into this list, starting at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in the list in the order that they are returned by the specified collection's iterator.- Parameters:
index- index at which to insert the first element from the specified collectionconstraints- collection containing constraints to be added to this list- Returns:
trueif this list changed as a result of the call- Throws:
java.lang.IndexOutOfBoundsExceptionjava.lang.NullPointerException- if the specified collection is null
-
addAll
private void addAll(int index, Constraint[] cArray)Adds all constraints fromcArrayto this collection at positionindex.- Parameters:
index- index at which to insert the first element from the specified collectioncArray- the constraints as array
-
addAll
public boolean addAll(ConstraintList constraints)
Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)- Parameters:
constraints- collection containing constraints to be added to this list- Returns:
trueif this list changed as a result of the call- Throws:
java.lang.NullPointerException- if the specified collection is null
-
addAll
public boolean addAll(ConstraintList constraints, boolean clear)
Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)- Parameters:
constraints- collection containing constraints to be added to this listclear- clearsconstraintsby taking over all internal nodes- Returns:
trueif this list changed as a result of the call- Throws:
java.lang.NullPointerException- if the specified collection is null
-
addAll
public boolean addAll(int index, ConstraintList constraints)Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)- Parameters:
index- index at which to insert the first element from the specified collectionconstraints- collection containing constraints to be added to this list- Returns:
trueif this list changed as a result of the call- Throws:
java.lang.NullPointerException- if the specified collection is null
-
addAll
public boolean addAll(int index, ConstraintList constraints, boolean clear)Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)- Parameters:
index- index at which to insert the first element from the specified collectionconstraints- collection containing constraints to be added to this listclear- clearsconstraintsby taking over all internal nodes- Returns:
trueif this list changed as a result of the call- Throws:
java.lang.NullPointerException- if the specified collection is null
-
toArray
public Constraint[] toArray()
Turns this list into an array containing all constraints.- Returns:
- the array
-
toCollection
public void toCollection(java.util.Collection<Constraint> collection)
Adds all elements in this list to acollectionof constraints.- Parameters:
collection- the collection to add to
-
pop
public Constraint pop()
Pops an element from the stack represented by this list. In other words, removes and returns the first element of this list.This method is equivalent to
removeFirst().- Returns:
- the element at the front of this list (which is the top of the stack represented by this list)
- Throws:
java.util.NoSuchElementException- if this list is empty- Since:
- 1.6
-
removeFirst
public Constraint removeFirst()
Removes and returns the first constraint from this list.- Returns:
- the first constraint from this list
- Throws:
java.util.NoSuchElementException- if this list is empty
-
removeLast
public Constraint removeLast()
Removes and returns the last constraint from this list.- Returns:
- the last constraint from this list
- Throws:
java.util.NoSuchElementException- if this list is empty
-
iterator
public java.util.Iterator<Constraint> iterator()
Returns an iterator over the elements in this list (in proper sequence).This implementation merely returns a list iterator over the list.
- Specified by:
iteratorin interfacejava.lang.Iterable<Constraint>- Returns:
- an iterator over the elements in this list (in proper sequence)
-
removeAll
public boolean removeAll(java.util.Collection<? extends Constraint> constraints)
Removes all elements from this list, which are also inconstraints.- Parameters:
constraints- the elements to remove- Returns:
- the removed elements
- Throws:
java.lang.NullPointerException- ifnull == constraints
-
linkFirst
private void linkFirst(Constraint constraint)
Linksconstraintas first constraint.- Parameters:
constraint- the constraint to be linked- See Also:
#notifyNodeAdded(Constraint, Node)
-
linkLast
private void linkLast(Constraint constraint)
Linksconstraintas last constraint.- Parameters:
constraint- the constraint to be linked- See Also:
#notifyNodeAdded(Constraint, Node)
-
unlinkFirst
private Constraint unlinkFirst(ConstraintList.Node node)
Unlinks non-null first nodenode.- Parameters:
node- the node to unlink- Returns:
- constraint the removed constraint
-
unlinkLast
private Constraint unlinkLast(ConstraintList.Node node)
Unlinks non-null last nodenode.- Parameters:
node- the node to unlink- Returns:
- constraint the removed constraint
-
unlink
Constraint unlink(ConstraintList.Node node)
Unlinks non-null node x.- Parameters:
node- the node to unlink- Returns:
- constraint the removed constraint
-
outOfBoundsMsg
private java.lang.String outOfBoundsMsg(int index)
Constructs an IndexOutOfBoundsException detail message. Of the many possible refactorings of the error handling code, this "outlining" performs best with both server and client VMs.- Parameters:
index- the failing index- Returns:
- the out of bounds message
-
isPositionIndex
private boolean isPositionIndex(int index)
Tells if the argument is the index of a valid position for an iterator or an add operation.- Parameters:
index- the index to check- Returns:
- returns whether
indexis a valid position
-
checkPositionIndex
private void checkPositionIndex(int index)
Checksindexto be a valid position. If not, throws anIndexOutOfBoundsException.- Parameters:
index- the index to check
-
node
private ConstraintList.Node node(int index)
Returns the (non-null) Node at the specified element index.- Parameters:
index- the index- Returns:
- the node
-
toString
public java.lang.String toString()
Turns the list into its string representation.- Overrides:
toStringin classjava.lang.Object- Returns:
- the string representation
-
-