Class 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 from LinkedList to fix types and to allow access from subclasses.
    Author:
    Holger Eichelberger
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected static interface  ConstraintList.IModificationListener
      A listener to be informed if the underlying list changes.
      protected static class  ConstraintList.Node
      The node type in a linked constraint base.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(Constraint constraint)
      Appends the specified constraint to the end of this constraint base.
      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.
      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.
      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.
      private void addAll​(int index, Constraint[] cArray)
      Adds all constraints from cArray to this collection at position index.
      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.
      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.
      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.
      void addFirst​(Constraint constraint)
      Inserts the specified constraint at the beginning of this constraint base.
      void addLast​(Constraint constraint)
      Appends the specified constraint to the end of this constraint base.
      private void checkPositionIndex​(int index)
      Checks index to be a valid position.
      void clear()
      Removes all of the elements from this list.
      boolean contains​(Constraint constraint)
      Returns true if this list contains the specified constraint.
      Constraint getFirst()
      Returns the first constraint in this list.
      Constraint getLast()
      Returns the last constraint in this list.
      int indexOf​(Constraint constraint)
      Returns the index of the first occurrence of the specified constraint in this list, or -1 if this list does not contain the element.
      boolean isEmpty()
      Returns true if this list contains no constraints.
      private boolean isPositionIndex​(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 void linkFirst​(Constraint constraint)
      Links constraint as first constraint.
      private void linkLast​(Constraint constraint)
      Links constraint as last constraint.
      private ConstraintList.Node node​(int index)
      Returns the (non-null) Node at the specified element index.
      private java.lang.String outOfBoundsMsg​(int index)
      Constructs an IndexOutOfBoundsException detail message.
      Constraint pop()
      Pops an element from the stack represented by this list.
      boolean removeAll​(java.util.Collection<? extends Constraint> constraints)
      Removes all elements from this list, which are also in constraints.
      Constraint removeFirst()
      Removes and returns the first constraint from this list.
      Constraint removeLast()
      Removes and returns the last constraint from this list.
      protected void setModificationListener​(ConstraintList.IModificationListener listener)
      Changes the modification listener.
      int size()
      Returns the number of constraints in this constraint base.
      Constraint[] toArray()
      Turns this list into an array containing all constraints.
      void toCollection​(java.util.Collection<Constraint> collection)
      Adds all elements in this list to a collection of constraints.
      java.lang.String toString()
      Turns the list into its string representation.
      (package private) Constraint unlink​(ConstraintList.Node node)
      Unlinks non-null node x.
      private Constraint unlinkFirst​(ConstraintList.Node node)
      Unlinks non-null first node node.
      private Constraint unlinkLast​(ConstraintList.Node node)
      Unlinks non-null last node node.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • 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)
        Returns true if this list contains the specified constraint. More formally, returns true if and only if this list contains at least one constraint constraint such that o == constraint.
        Parameters:
        constraint - the constraint whose presence in this list is to be tested
        Returns:
        true if this list contains the specified element
      • indexOf

        public int indexOf​(Constraint constraint)
        Returns the index of the first occurrence of the specified constraint in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that o == 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()
        Returns true if this list contains no constraints.
        Returns:
        true if 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 specified constraint at the beginning of this constraint base.
        Parameters:
        constraint - the constraint to add
      • addLast

        public void addLast​(Constraint constraint)
        Appends the specified constraint to 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:
        true if 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 collection
        constraints - collection containing constraints to be added to this list
        Returns:
        true if this list changed as a result of the call
        Throws:
        java.lang.IndexOutOfBoundsException
        java.lang.NullPointerException - if the specified collection is null
      • addAll

        private void addAll​(int index,
                            Constraint[] cArray)
        Adds all constraints from cArray to this collection at position index.
        Parameters:
        index - index at which to insert the first element from the specified collection
        cArray - 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:
        true if 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 list
        clear - clears constraints by taking over all internal nodes
        Returns:
        true if 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 collection
        constraints - collection containing constraints to be added to this list
        Returns:
        true if 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 collection
        constraints - collection containing constraints to be added to this list
        clear - clears constraints by taking over all internal nodes
        Returns:
        true if 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 a collection of 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:
        iterator in interface java.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 in constraints.
        Parameters:
        constraints - the elements to remove
        Returns:
        the removed elements
        Throws:
        java.lang.NullPointerException - if null == constraints
      • linkFirst

        private void linkFirst​(Constraint constraint)
        Links constraint as first constraint.
        Parameters:
        constraint - the constraint to be linked
        See Also:
        #notifyNodeAdded(Constraint, Node)
      • linkLast

        private void linkLast​(Constraint constraint)
        Links constraint as 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 node node.
        Parameters:
        node - the node to unlink
        Returns:
        constraint the removed constraint
      • unlinkLast

        private Constraint unlinkLast​(ConstraintList.Node node)
        Unlinks non-null last node node.
        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 index is a valid position
      • checkPositionIndex

        private void checkPositionIndex​(int index)
        Checks index to be a valid position. If not, throws an IndexOutOfBoundsException.
        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:
        toString in class java.lang.Object
        Returns:
        the string representation