Interface IHasChildren<CHILDTYPE>

Type Parameters:
CHILDTYPE - The type of the children.
All Known Subinterfaces:
IHasChildrenRecursive<CHILDTYPE>, IHasChildrenSorted<CHILDTYPE>

public interface IHasChildren<CHILDTYPE>
A simple interface, indicating that an item has direct children.
Author:
Philip Helger
  • Method Details

    • hasChildren

      default boolean hasChildren()
      Returns:
      true if this item has direct children, false otherwise.
    • hasNoChildren

      default boolean hasNoChildren()
      Returns:
      true if this item has no direct children, false otherwise.
    • getChildCount

      @Nonnegative int getChildCount()
      Returns:
      The number of contained direct children. Always ≥ 0.
    • getAllChildren

      Returns:
      A collection of all direct child elements. May be null if no children are contained. This method should always return a copy of the collection to avoid ConcurrentModificationException when modifying it.
      See Also:
    • getChildren

      @Nullable ICommonsIterable<? extends CHILDTYPE> getChildren()
      Returns:
      An iterable over all direct children. May be null if no children are contained. Compared to getAllChildren() this method is not supposed to create a copy of the underlying container but instead return the iterable only. Be careful when using this method to modify a collection - it will lead to a ConcurrentModificationException.
      Since:
      9.0.0
      See Also:
    • forAllChildren

      default void forAllChildren(@Nonnull Consumer<? super CHILDTYPE> aConsumer)
      Perform something on all children (if any).
      Note: use this only for reading. Writing operations will potentially cause concurrent modification exceptions!
      Parameters:
      aConsumer - The consumer to be invoked. May not be null.
    • forAllChildrenBreakable

      @Nonnull default EContinue forAllChildrenBreakable(@Nonnull Function<? super CHILDTYPE,EContinue> aConsumer)
      Perform something on all children (if any).
      Note: use this only for reading. Writing operations will potentially cause concurrent modification exceptions!
      Parameters:
      aConsumer - The breakable consumer to be invoked. May not be null.
      Returns:
      EContinue.BREAK if iteration was stopped, EContinue.CONTINUE otherwise.
    • forAllChildren

      default void forAllChildren(@Nonnull Predicate<? super CHILDTYPE> aFilter, @Nonnull Consumer<? super CHILDTYPE> aConsumer)
      Iterate all direct children (if at least one is present) and invoke the provided consumer if the passed predicate is fulfilled.
      Note: use this only for reading. Writing operations will potentially cause concurrent modification exceptions!
      Parameters:
      aFilter - The filter that is applied to all children. May not be null.
      aConsumer - The consumer to be invoked for all children matching the filter. May not be null.
    • forAllChildrenMapped

      default <DSTTYPE> void forAllChildrenMapped(@Nonnull Predicate<? super CHILDTYPE> aFilter, @Nonnull Function<? super CHILDTYPE,? extends DSTTYPE> aMapper, @Nonnull Consumer<? super DSTTYPE> aConsumer)
      Iterate all direct children (if at least one is present) and invoked the provided consumer if the passed predicate is fulfilled.
      Note: use this only for reading. Writing operations will potentially cause concurrent modification exceptions!
      Type Parameters:
      DSTTYPE - The destination data type.
      Parameters:
      aFilter - The filter that is applied to all children. May not be null.
      aMapper - The mapping function from child type to the target type. May not be null.
      aConsumer - The consumer to be invoked for all target types matching the filter. May not be null.