Package org.oddjob.structural
Class ChildHelper<E>
java.lang.Object
org.oddjob.structural.ChildHelper<E>
- All Implemented Interfaces:
Iterable<E>,Structural,ChildList<E>
Helper for managing child Objects. This class will track structural
changes and notify listeners.
- Author:
- Rob Gordon
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintAdd a child to the end of the list.voidaddStructuralListener(StructuralListener listener) Add a listener.booleanIs this child ours?getChild()Return an only child.getChildAt(int index) Return a child.Object[]Return an array of children.E[]getChildren(E[] array) Return an array of children.static Object[]getChildren(Structural structural) voidPerform a hard reset.voidinsertChild(int index, E child) Insert a child.voidinsertOrRemoveChild(int index, E child) Insert or remove a child depending on if the child is null.booleanReturns true if there are no listeners listening forStructuralEvents.iterator()voidAllows a sub class to remove all children from itself.intremoveChild(E child) Remove a child.removeChildAt(int index) Remove a child by index.voidremoveStructuralListener(StructuralListener listener) Remove a listener.intsize()The number of children.voidPerform a soft reset.voidStops all the child jobs.voidstopChildren(boolean wait) Stops all the child jobs.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ChildHelper
Constructor.- Parameters:
source- The source used as the source of the event.
-
-
Method Details
-
insertChild
Insert a child.- Specified by:
insertChildin interfaceChildList<E>- Parameters:
index- The index.child- The child.
-
addChild
Add a child to the end of the list. -
removeChildAt
Remove a child by index. This method fires the appropriate event in accordance with the Structural interface.- Specified by:
removeChildAtin interfaceChildList<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
Insert or remove a child depending on if the child is null.- Parameters:
index- The index.child- The child.
-
removeChild
Remove a child.- Specified by:
removeChildin interfaceChildList<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
Stops all the child jobs. Jobs are stopped in reverse order.- Throws:
FailedToStopException
-
stopChildren
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
Return an array of children.- Returns:
- An array of child objects.
-
getChildren
Return an array of children.- Returns:
- An array of child objects.
-
getChildAt
Return a child.- Returns:
- A child.
-
getChild
Return an only child.- Returns:
- A child.
-
contains
Is this child ours?- Parameters:
child-- Returns:
- true if it is, false if it isn't.
-
iterator
-
addStructuralListener
Description copied from interface:StructuralAdd a listener. The listener will immediately receive add notifications for all existing children.- Specified by:
addStructuralListenerin interfaceStructural- Parameters:
listener- The listener.
-
removeStructuralListener
Description copied from interface:StructuralRemove a listener.- Specified by:
removeStructuralListenerin interfaceStructural- Parameters:
listener- The listener.
-
isNoListeners
public boolean isNoListeners()Returns true if there are no listeners listening forStructuralEvents.- Returns:
- true/false.
-
size
public int size()The number of children.- Returns:
- The number of children.
-
getChildren
-
toString
-