Package com.helger.commons.hierarchy
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 Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidforAllChildren(Consumer<? super CHILDTYPE> aConsumer)Perform something on all children (if any).
Note: use this only for reading.default voidforAllChildren(Predicate<? super CHILDTYPE> aFilter, 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.default EContinueforAllChildrenBreakable(Function<? super CHILDTYPE,EContinue> aConsumer)Perform something on all children (if any).
Note: use this only for reading.default <DSTTYPE> voidforAllChildrenMapped(Predicate<? super CHILDTYPE> aFilter, Function<? super CHILDTYPE,? extends DSTTYPE> aMapper, 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.ICommonsCollection<? extends CHILDTYPE>getAllChildren()intgetChildCount()ICommonsIterable<? extends CHILDTYPE>getChildren()default booleanhasChildren()default booleanhasNoChildren()
-
-
-
Method Detail
-
hasChildren
default boolean hasChildren()
- Returns:
trueif this item has direct children,falseotherwise.
-
hasNoChildren
default boolean hasNoChildren()
- Returns:
trueif this item has no direct children,falseotherwise.
-
getChildCount
@Nonnegative int getChildCount()
- Returns:
- The number of contained direct children. Always ≥ 0.
-
getAllChildren
@Nullable @ReturnsMutableCopy ICommonsCollection<? extends CHILDTYPE> getAllChildren()
- Returns:
- A collection of all direct child elements. May be
nullif no children are contained. This method should always return a copy of the collection to avoidConcurrentModificationExceptionwhen modifying it. - See Also:
hasChildren(),getChildren()
-
getChildren
@Nullable ICommonsIterable<? extends CHILDTYPE> getChildren()
- Returns:
- An iterable over all direct children. May be
nullif no children are contained. Compared togetAllChildren()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 aConcurrentModificationException. - Since:
- 9.0.0
- See Also:
hasChildren(),getChildren()
-
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 benull.
-
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 benull.- Returns:
EContinue.BREAKif iteration was stopped,EContinue.CONTINUEotherwise.
-
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 benull.aConsumer- The consumer to be invoked for all children matching the filter. May not benull.
-
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 benull.aMapper- The mapping function from child type to the target type. May not benull.aConsumer- The consumer to be invoked for all target types matching the filter. May not benull.
-
-