Package com.helger.tree
Class BasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItem<DATATYPE,ITEMTYPE>>
- java.lang.Object
-
- com.helger.tree.BasicTreeItem<DATATYPE,ITEMTYPE>
-
- Type Parameters:
DATATYPE- tree item value typeITEMTYPE- tree item implementation type
- All Implemented Interfaces:
com.helger.commons.hierarchy.IHasChildren<ITEMTYPE>,com.helger.commons.hierarchy.IHasChildrenRecursive<ITEMTYPE>,com.helger.commons.hierarchy.IHasChildrenSorted<ITEMTYPE>,com.helger.commons.hierarchy.IHasParent<ITEMTYPE>,com.helger.commons.traits.IGenericImplTrait<ITEMTYPE>,IBasicTreeItem<DATATYPE,ITEMTYPE>,ITreeItem<DATATYPE,ITEMTYPE>
- Direct Known Subclasses:
DefaultTreeItem
@NotThreadSafe public class BasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItem<DATATYPE,ITEMTYPE>> extends Object implements ITreeItem<DATATYPE,ITEMTYPE>
Basic implementation of theITreeIteminterface- Author:
- Philip Helger
-
-
Constructor Summary
Constructors Constructor Description BasicTreeItem(ITreeItemFactory<DATATYPE,ITEMTYPE> aFactory)Constructor for root object.BasicTreeItem(ITEMTYPE aParent)Constructor for normal elements.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.helger.commons.state.ESuccesschangeParent(ITEMTYPE aNewParent)Change the parent node of this node to another node (subordination).ITEMTYPEcreateChildItem(DATATYPE aData)Add a child item to this item.booleanequals(Object o)ITEMTYPEfindFirstChild(Predicate<? super ITEMTYPE> aFilter)<DSTTYPE> DSTTYPEfindFirstChildMapped(Predicate<? super ITEMTYPE> aFilter, Function<? super ITEMTYPE,? extends DSTTYPE> aMapper)voidforAllChildren(Consumer<? super ITEMTYPE> aConsumer)voidforAllChildren(Predicate<? super ITEMTYPE> aFilter, Consumer<? super ITEMTYPE> aConsumer)com.helger.commons.state.EContinueforAllChildrenBreakable(Function<? super ITEMTYPE,com.helger.commons.state.EContinue> aConsumer)<DSTTYPE> voidforAllChildrenMapped(Predicate<? super ITEMTYPE> aFilter, Function<? super ITEMTYPE,? extends DSTTYPE> aMapper, Consumer<? super DSTTYPE> aConsumer)com.helger.commons.collection.impl.ICommonsList<DATATYPE>getAllChildDatas()Get the data values of all contained children.com.helger.commons.collection.impl.ICommonsList<ITEMTYPE>getAllChildren()ITEMTYPEgetChildAtIndex(int nIndex)intgetChildCount()com.helger.commons.collection.impl.ICommonsIterable<ITEMTYPE>getChildren()DATATYPEgetData()ITreeItemFactory<DATATYPE,ITEMTYPE>getFactory()ITEMTYPEgetFirstChild()ITEMTYPEgetLastChild()intgetLevel()ITEMTYPEgetParent()DATATYPEgetParentData()booleanhasChildren()inthashCode()com.helger.commons.state.EChangeinternalAddChild(ITEMTYPE aChild)Add an existing child to this tree item.booleanisRootItem()booleanisSameOrChildOf(ITEMTYPE aParent)Check if this item is the same or a child of the passed item.protected booleanisValidData(DATATYPE aData)This method is called to validate a data object.com.helger.commons.state.EChangeremoveChild(ITEMTYPE aChild)Remove the passed node as a child node from this node.voidreorderChildItems(Comparator<? super ITEMTYPE> aComparator)Reorder the child items based on the item itself.voidsetData(DATATYPE aData)Change the data associated with this node.StringtoString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
-
-
-
Constructor Detail
-
BasicTreeItem
public BasicTreeItem(@Nonnull ITreeItemFactory<DATATYPE,ITEMTYPE> aFactory)
Constructor for root object.- Parameters:
aFactory- The factory to use for creating tree items. May not benull.
-
-
Method Detail
-
getFactory
@Nonnull public final ITreeItemFactory<DATATYPE,ITEMTYPE> getFactory()
-
isValidData
@OverrideOnDemand protected boolean isValidData(DATATYPE aData)
This method is called to validate a data object. This method may be overloaded in derived classes. The default implementation accepts all values.- Parameters:
aData- The value to validate.- Returns:
trueif the ID is valid,falseotherwise.
-
setData
public final void setData(@Nullable DATATYPE aData)
Description copied from interface:IBasicTreeItemChange the data associated with this node.
-
isRootItem
public final boolean isRootItem()
- Specified by:
isRootItemin interfaceIBasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItem<DATATYPE,ITEMTYPE>>- Returns:
trueif this is the internal root item without a parent,falseif this is a public item.
-
getParent
@Nullable public final ITEMTYPE getParent()
- Specified by:
getParentin interfacecom.helger.commons.hierarchy.IHasParent<DATATYPE>
-
getParentData
@Nullable public final DATATYPE getParentData()
- Specified by:
getParentDatain interfaceIBasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItem<DATATYPE,ITEMTYPE>>- Returns:
- the data associated with the parent node. May be
null. This is like a shortcut forgetParent().getData()with implicitnullhandling.
-
getLevel
@Nonnegative public final int getLevel()
-
createChildItem
@Nonnull public final ITEMTYPE createChildItem(@Nullable DATATYPE aData)
Add a child item to this item.
-
hasChildren
public final boolean hasChildren()
- Specified by:
hasChildrenin interfacecom.helger.commons.hierarchy.IHasChildren<DATATYPE>
-
getAllChildren
@Nullable @ReturnsMutableCopy public final com.helger.commons.collection.impl.ICommonsList<ITEMTYPE> getAllChildren()
-
getChildren
@Nullable public final com.helger.commons.collection.impl.ICommonsIterable<ITEMTYPE> getChildren()
- Specified by:
getChildrenin interfacecom.helger.commons.hierarchy.IHasChildren<DATATYPE>
-
forAllChildren
public final void forAllChildren(@Nonnull Consumer<? super ITEMTYPE> aConsumer)
- Specified by:
forAllChildrenin interfacecom.helger.commons.hierarchy.IHasChildren<DATATYPE>
-
forAllChildrenBreakable
@Nonnull public final com.helger.commons.state.EContinue forAllChildrenBreakable(@Nonnull Function<? super ITEMTYPE,com.helger.commons.state.EContinue> aConsumer)
- Specified by:
forAllChildrenBreakablein interfacecom.helger.commons.hierarchy.IHasChildren<DATATYPE>
-
forAllChildren
public final void forAllChildren(@Nonnull Predicate<? super ITEMTYPE> aFilter, @Nonnull Consumer<? super ITEMTYPE> aConsumer)
- Specified by:
forAllChildrenin interfacecom.helger.commons.hierarchy.IHasChildren<DATATYPE>
-
forAllChildrenMapped
public final <DSTTYPE> void forAllChildrenMapped(@Nonnull Predicate<? super ITEMTYPE> aFilter, @Nonnull Function<? super ITEMTYPE,? extends DSTTYPE> aMapper, @Nonnull Consumer<? super DSTTYPE> aConsumer)
- Specified by:
forAllChildrenMappedin interfacecom.helger.commons.hierarchy.IHasChildren<DATATYPE>
-
getAllChildDatas
@Nullable @ReturnsMutableCopy public final com.helger.commons.collection.impl.ICommonsList<DATATYPE> getAllChildDatas()
Description copied from interface:IBasicTreeItemGet the data values of all contained children.- Specified by:
getAllChildDatasin interfaceIBasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItem<DATATYPE,ITEMTYPE>>- Returns:
nullif this item does not have children. UseIHasChildren.hasChildren()to check for the existence.
-
getChildAtIndex
@Nullable public final ITEMTYPE getChildAtIndex(@Nonnegative int nIndex)
- Specified by:
getChildAtIndexin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<DATATYPE>
-
getChildCount
@Nonnegative public final int getChildCount()
- Specified by:
getChildCountin interfacecom.helger.commons.hierarchy.IHasChildren<DATATYPE>
-
getFirstChild
@Nullable public final ITEMTYPE getFirstChild()
- Specified by:
getFirstChildin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<DATATYPE>
-
findFirstChild
@Nullable public final ITEMTYPE findFirstChild(@Nonnull Predicate<? super ITEMTYPE> aFilter)
- Specified by:
findFirstChildin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<DATATYPE>
-
findFirstChildMapped
@Nullable public final <DSTTYPE> DSTTYPE findFirstChildMapped(@Nonnull Predicate<? super ITEMTYPE> aFilter, @Nonnull Function<? super ITEMTYPE,? extends DSTTYPE> aMapper)
- Specified by:
findFirstChildMappedin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<DATATYPE>
-
getLastChild
@Nullable public final ITEMTYPE getLastChild()
- Specified by:
getLastChildin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<DATATYPE>
-
isSameOrChildOf
public final boolean isSameOrChildOf(@Nonnull ITEMTYPE aParent)
Description copied from interface:IBasicTreeItemCheck if this item is the same or a child of the passed item. This is not limited to direct children but to children on all levels.- Specified by:
isSameOrChildOfin interfaceIBasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItem<DATATYPE,ITEMTYPE>>- Parameters:
aParent- The parent item to check whether this is a child of it. May not benull.- Returns:
trueifthisis the same or a child of aParent.
-
changeParent
@Nonnull public final com.helger.commons.state.ESuccess changeParent(@Nonnull ITEMTYPE aNewParent)
Description copied from interface:IBasicTreeItemChange the parent node of this node to another node (subordination).- Specified by:
changeParentin interfaceIBasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItem<DATATYPE,ITEMTYPE>>- Parameters:
aNewParent- The new parent to use. May not benull. To make it a root item, pass the owning tree's root item.- Returns:
ESuccess
-
internalAddChild
@Nonnull public final com.helger.commons.state.EChange internalAddChild(@Nonnull ITEMTYPE aChild)
Description copied from interface:ITreeItemAdd an existing child to this tree item. Use only internally!
-
removeChild
@Nonnull public final com.helger.commons.state.EChange removeChild(@Nonnull ITEMTYPE aChild)
Description copied from interface:ITreeItemRemove the passed node as a child node from this node.
-
reorderChildItems
public final void reorderChildItems(@Nonnull Comparator<? super ITEMTYPE> aComparator)
Description copied from interface:ITreeItemReorder the child items based on the item itself.
-
-