KEYTYPE - tree item key typeDATATYPE - tree item value typeITEMTYPE - tree item implementation type@NotThreadSafe public class BasicTreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>> extends Object implements ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>
| Constructor and Description |
|---|
BasicTreeItemWithID(ITEMTYPE aParent,
KEYTYPE aDataID)
Constructor for normal elements
|
BasicTreeItemWithID(ITreeItemWithIDFactory<KEYTYPE,DATATYPE,ITEMTYPE> aFactory)
Constructor for root object with a
null data ID |
BasicTreeItemWithID(ITreeItemWithIDFactory<KEYTYPE,DATATYPE,ITEMTYPE> aFactory,
KEYTYPE aDataID)
Constructor for root object
|
| Modifier and Type | Method and Description |
|---|---|
com.helger.commons.state.ESuccess |
changeParent(ITEMTYPE aNewParent)
Change the parent node of this node to another node (subordination).
|
boolean |
containsChildItemWithDataID(KEYTYPE aDataID)
Check if a direct child item with the given ID is present
|
ITEMTYPE |
createChildItem(KEYTYPE aDataID,
DATATYPE aData)
Add a direct child item to this item.
|
ITEMTYPE |
createChildItem(KEYTYPE aDataID,
DATATYPE aData,
boolean bAllowOverwrite)
Add a direct child item to this item.
|
boolean |
equals(Object o) |
ITEMTYPE |
findFirstChild(Predicate<? super ITEMTYPE> aFilter) |
<DSTTYPE> DSTTYPE |
findFirstChildMapped(Predicate<? super ITEMTYPE> aFilter,
Function<? super ITEMTYPE,? extends DSTTYPE> aMapper) |
void |
forAllChildren(Consumer<? super ITEMTYPE> aConsumer) |
void |
forAllChildren(Predicate<? super ITEMTYPE> aFilter,
Consumer<? super ITEMTYPE> aConsumer) |
<DSTTYPE> void |
forAllChildrenMapped(Predicate<? super ITEMTYPE> aFilter,
Function<? super ITEMTYPE,? extends DSTTYPE> aMapper,
Consumer<? super DSTTYPE> aConsumer) |
com.helger.commons.collection.impl.ICommonsSet<KEYTYPE> |
getAllChildDataIDs() |
com.helger.commons.collection.impl.ICommonsList<DATATYPE> |
getAllChildDatas()
Get the data values of all contained children.
|
com.helger.commons.collection.impl.ICommonsList<ITEMTYPE> |
getAllChildren() |
ITEMTYPE |
getChildAtIndex(int nIndex) |
int |
getChildCount() |
ITEMTYPE |
getChildItemOfDataID(KEYTYPE aDataID)
Find the direct child item with the given ID
|
com.helger.commons.collection.impl.ICommonsIterable<ITEMTYPE> |
getChildren() |
DATATYPE |
getData() |
ITreeItemWithIDFactory<KEYTYPE,DATATYPE,ITEMTYPE> |
getFactory() |
ITEMTYPE |
getFirstChild() |
KEYTYPE |
getID() |
ITEMTYPE |
getLastChild() |
int |
getLevel() |
ITEMTYPE |
getParent() |
DATATYPE |
getParentData() |
KEYTYPE |
getParentID() |
boolean |
hasChildren() |
int |
hashCode() |
com.helger.commons.state.EChange |
internalAddChild(KEYTYPE aDataID,
ITEMTYPE aChild,
boolean bAllowOverwrite)
Add an existing direct child to this tree item.
|
boolean |
isRootItem() |
boolean |
isSameOrChildOf(ITEMTYPE aParent)
Check if this item is the same or a child of the passed item.
|
protected boolean |
isValidData(DATATYPE aData)
This method is called to validate a data object.
|
protected boolean |
isValidDataID(KEYTYPE aDataID)
This method is called to validate a data ID object.
|
com.helger.commons.state.EChange |
removeAllChildren()
Remove all children from this node.
|
com.helger.commons.state.EChange |
removeChild(KEYTYPE aDataID)
Remove the passed node as a direct child node from this node.
|
void |
reorderChildrenByItems(Comparator<? super ITEMTYPE> aComparator)
Reorder the child items based on the item itself.
|
void |
setData(DATATYPE aData)
Change the data associated with this node.
|
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitforAllChildrenRecursive, forAllChildrenRecursivepublic BasicTreeItemWithID(@Nonnull ITreeItemWithIDFactory<KEYTYPE,DATATYPE,ITEMTYPE> aFactory)
null data IDaFactory - The tree item factory to use. May not be null.public BasicTreeItemWithID(@Nonnull ITreeItemWithIDFactory<KEYTYPE,DATATYPE,ITEMTYPE> aFactory, @Nullable KEYTYPE aDataID)
aFactory - The tree item factory to use. May not be null.aDataID - The data ID to use for the root item. May be null.@Nonnull public final ITreeItemWithIDFactory<KEYTYPE,DATATYPE,ITEMTYPE> getFactory()
getFactory in interface ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>@OverrideOnDemand protected boolean isValidDataID(KEYTYPE aDataID)
aDataID - The value to validate.true if the ID is valid, false otherwise.@OverrideOnDemand protected boolean isValidData(DATATYPE aData)
aData - The value to validate.true if the ID is valid, false otherwise.public final boolean isRootItem()
isRootItem in interface IBasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>true if this is the internal root item without a
parent, false if this is a public item.@Nullable public final ITEMTYPE getParent()
getParent in interface com.helger.commons.hierarchy.IHasParent<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>@Nullable public final KEYTYPE getParentID()
getParentID in interface ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>null if no
parent is present or depending on the validator.@Nullable public final DATATYPE getParentData()
getParentData in interface IBasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>null.
This is like a shortcut for getParent().getData() with
implicit null handling.@Nonnegative public final int getLevel()
getLevel in interface IBasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>@Nullable public final KEYTYPE getID()
getID in interface com.helger.commons.id.IHasID<KEYTYPE>getID in interface ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>null depending on the
validator.@Nullable public final DATATYPE getData()
getData in interface IBasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>null.public final boolean hasChildren()
hasChildren in interface com.helger.commons.hierarchy.IHasChildren<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>@Nonnegative public final int getChildCount()
getChildCount in interface com.helger.commons.hierarchy.IHasChildren<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>@Nullable @ReturnsMutableCopy public final com.helger.commons.collection.impl.ICommonsList<ITEMTYPE> getAllChildren()
getAllChildren in interface com.helger.commons.hierarchy.IHasChildren<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>getAllChildren in interface com.helger.commons.hierarchy.IHasChildrenSorted<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>@Nullable public final com.helger.commons.collection.impl.ICommonsIterable<ITEMTYPE> getChildren()
getChildren in interface com.helger.commons.hierarchy.IHasChildren<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>public final void forAllChildren(@Nonnull Consumer<? super ITEMTYPE> aConsumer)
forAllChildren in interface com.helger.commons.hierarchy.IHasChildren<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>public final void forAllChildren(@Nonnull Predicate<? super ITEMTYPE> aFilter, @Nonnull Consumer<? super ITEMTYPE> aConsumer)
forAllChildren in interface com.helger.commons.hierarchy.IHasChildren<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>public final <DSTTYPE> void forAllChildrenMapped(@Nonnull Predicate<? super ITEMTYPE> aFilter, @Nonnull Function<? super ITEMTYPE,? extends DSTTYPE> aMapper, @Nonnull Consumer<? super DSTTYPE> aConsumer)
forAllChildrenMapped in interface com.helger.commons.hierarchy.IHasChildren<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>@Nullable @ReturnsMutableCopy public final com.helger.commons.collection.impl.ICommonsSet<KEYTYPE> getAllChildDataIDs()
getAllChildDataIDs in interface ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>null if returned.@Nullable @ReturnsMutableCopy public final com.helger.commons.collection.impl.ICommonsList<DATATYPE> getAllChildDatas()
IBasicTreeItemgetAllChildDatas in interface IBasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>null if this item does not have children. Use
IHasChildren.hasChildren() to check for the existence.@Nullable public final ITEMTYPE getChildAtIndex(@Nonnegative int nIndex)
getChildAtIndex in interface com.helger.commons.hierarchy.IHasChildrenSorted<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>@Nullable public final ITEMTYPE getFirstChild()
getFirstChild in interface com.helger.commons.hierarchy.IHasChildrenSorted<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>@Nullable public final ITEMTYPE findFirstChild(@Nonnull Predicate<? super ITEMTYPE> aFilter)
findFirstChild in interface com.helger.commons.hierarchy.IHasChildrenSorted<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>@Nullable public final <DSTTYPE> DSTTYPE findFirstChildMapped(@Nonnull Predicate<? super ITEMTYPE> aFilter, @Nonnull Function<? super ITEMTYPE,? extends DSTTYPE> aMapper)
findFirstChildMapped in interface com.helger.commons.hierarchy.IHasChildrenSorted<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>@Nullable public final ITEMTYPE getLastChild()
getLastChild in interface com.helger.commons.hierarchy.IHasChildrenSorted<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>public final void setData(@Nullable DATATYPE aData)
IBasicTreeItemsetData in interface IBasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>aData - The data associated with this node. May be null.@Nullable public final ITEMTYPE createChildItem(@Nullable KEYTYPE aDataID, @Nullable DATATYPE aData)
ITreeItemWithIDcreateChildItem in interface ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>aDataID - ID of the item to generate. May be null in rare
circumstances.aData - The data associated with this item.@Nullable public final ITEMTYPE createChildItem(@Nullable KEYTYPE aDataID, @Nullable DATATYPE aData, boolean bAllowOverwrite)
ITreeItemWithIDcreateChildItem in interface ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>aDataID - ID of the item to generate. May not be null.aData - The data associated with this item.bAllowOverwrite - If true a potential existing child item with the same
ID is overwritten.null if the data ID is
already in use and bAllowOverwrite is falsepublic final boolean containsChildItemWithDataID(@Nullable KEYTYPE aDataID)
ITreeItemWithIDcontainsChildItemWithDataID in interface ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>aDataID - The ID to search. May be null.true if this item has a child with the given ID,
false otherwise@Nullable public final ITEMTYPE getChildItemOfDataID(@Nullable KEYTYPE aDataID)
ITreeItemWithIDgetChildItemOfDataID in interface ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>aDataID - The ID to search. May be null.null if this item has no child with the given ID. The
item otherwise.public final boolean isSameOrChildOf(@Nonnull ITEMTYPE aParent)
IBasicTreeItemisSameOrChildOf in interface IBasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>aParent - The parent item to check whether this is a child of it. May not be
null.true if this is the same or a child of
aParent.@Nonnull public final com.helger.commons.state.ESuccess changeParent(@Nonnull ITEMTYPE aNewParent)
IBasicTreeItemchangeParent in interface IBasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>aNewParent - The new parent to use. May not be null. To make it a
root item, pass the owning tree's root item.ESuccess@Nonnull public final com.helger.commons.state.EChange internalAddChild(@Nonnull KEYTYPE aDataID, @Nonnull ITEMTYPE aChild, boolean bAllowOverwrite)
ITreeItemWithIDinternalAddChild in interface ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>aDataID - The data ID to use. May not be null.aChild - The child to be added. May not be null.bAllowOverwrite - if true existing elements are overwritten.EChange@Nonnull public final com.helger.commons.state.EChange removeChild(@Nullable KEYTYPE aDataID)
ITreeItemWithIDremoveChild in interface ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>aDataID - The ID of the element to be removed. May not be null.EChange@Nonnull public final com.helger.commons.state.EChange removeAllChildren()
ITreeItemWithIDremoveAllChildren in interface ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>EChangepublic final void reorderChildrenByItems(@Nonnull Comparator<? super ITEMTYPE> aComparator)
ITreeItemWithIDreorderChildrenByItems in interface ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>aComparator - The comparator use. May not be null.Copyright © 2014–2021 Philip Helger. All rights reserved.