Class ChildHelper<E>

java.lang.Object
org.oddjob.structural.ChildHelper<E>
All Implemented Interfaces:
Iterable<E>, Structural, ChildList<E>

public class ChildHelper<E> extends Object implements Structural, Iterable<E>, ChildList<E>
Helper for managing child Objects. This class will track structural changes and notify listeners.
Author:
Rob Gordon
  • Constructor Details

    • ChildHelper

      public ChildHelper(Structural source)
      Constructor.
      Parameters:
      source - The source used as the source of the event.
  • Method Details

    • insertChild

      public void insertChild(int index, E child)
      Insert a child.
      Specified by:
      insertChild in interface ChildList<E>
      Parameters:
      index - The index.
      child - The child.
    • addChild

      public int addChild(E child)
      Add a child to the end of the list.
      Specified by:
      addChild in interface ChildList<E>
      Parameters:
      child - The child. Must not be null.
      Returns:
      The index the child was added at.
    • removeChildAt

      public E removeChildAt(int index) throws IndexOutOfBoundsException
      Remove a child by index. This method fires the appropriate event in accordance with the Structural interface.
      Specified by:
      removeChildAt in interface ChildList<E>
      Parameters:
      index - The index of the child to remove.
      Returns:
      The child removed.
      Throws:
      IndexOutOfBoundsException - If there is no child at the index.
    • insertOrRemoveChild

      public void insertOrRemoveChild(int index, E child)
      Insert or remove a child depending on if the child is null.
      Parameters:
      index - The index.
      child - The child.
    • removeChild

      public int removeChild(E child) throws IllegalStateException
      Remove a child.
      Specified by:
      removeChild in interface ChildList<E>
      Parameters:
      child - The child to be removed.
      Returns:
      The index the child was removed from.
      Throws:
      IllegalStateException - If the child is not our child.
    • removeAllChildren

      public void removeAllChildren()
      Allows a sub class to remove all children from itself. This method fires the appropriate events in accordance with the structural interface.

      This method isn't synchronized. Simultaneous removal of children by a different thread could result in an IndexOutOfBoundsException.

    • stopChildren

      public void stopChildren() throws FailedToStopException
      Stops all the child jobs. Jobs are stopped in reverse order.
      Throws:
      FailedToStopException
    • stopChildren

      public void stopChildren(boolean wait) throws FailedToStopException
      Stops all the child jobs. Jobs are stopped in reverse order.
      Throws:
      FailedToStopException
    • softResetChildren

      public void softResetChildren()
      Perform a soft reset. This method propagates the soft reset message down to all child jobs. This is a convenience method that a sub class can choose to use.
    • hardResetChildren

      public void hardResetChildren()
      Perform a hard reset. This method propagates the hard reset message down to all child jobs. This is a convenience method a sub class can choose to use.
    • getChildren

      public Object[] getChildren()
      Return an array of children.
      Returns:
      An array of child objects.
    • getChildren

      public E[] getChildren(E[] array)
      Return an array of children.
      Returns:
      An array of child objects.
    • getChildAt

      public E getChildAt(int index)
      Return a child.
      Returns:
      A child.
    • getChild

      public E getChild()
      Return an only child.
      Returns:
      A child.
    • contains

      public boolean contains(E child)
      Is this child ours?
      Parameters:
      child -
      Returns:
      true if it is, false if it isn't.
    • iterator

      public Iterator<E> iterator()
      Specified by:
      iterator in interface Iterable<E>
    • addStructuralListener

      public void addStructuralListener(StructuralListener listener)
      Description copied from interface: Structural
      Add a listener. The listener will immediately receive add notifications for all existing children.
      Specified by:
      addStructuralListener in interface Structural
      Parameters:
      listener - The listener.
    • removeStructuralListener

      public void removeStructuralListener(StructuralListener listener)
      Description copied from interface: Structural
      Remove a listener.
      Specified by:
      removeStructuralListener in interface Structural
      Parameters:
      listener - The listener.
    • isNoListeners

      public boolean isNoListeners()
      Returns true if there are no listeners listening for StructuralEvents.
      Returns:
      true/false.
    • size

      public int size()
      The number of children.
      Returns:
      The number of children.
    • getChildren

      public static Object[] getChildren(Structural structural)
    • toString

      public String toString()
      Overrides:
      toString in class Object