Package com.helger.tree.withid.unique
Class BasicTreeWithGlobalUniqueID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>
- java.lang.Object
-
- com.helger.tree.withid.BasicTreeWithID<KEYTYPE,DATATYPE,ITEMTYPE>
-
- com.helger.tree.withid.unique.BasicTreeWithGlobalUniqueID<KEYTYPE,DATATYPE,ITEMTYPE>
-
- Type Parameters:
KEYTYPE- The type of the key elements for the tree.DATATYPE- The type of the elements contained in the treeITEMTYPE- tree item type
- All Implemented Interfaces:
com.helger.commons.hierarchy.IChildrenProvider<ITEMTYPE>,com.helger.commons.hierarchy.IChildrenProviderWithID<KEYTYPE,ITEMTYPE>,com.helger.commons.hierarchy.IHasChildren<ITEMTYPE>,IBasicTree<DATATYPE,ITEMTYPE>,ITreeWithID<KEYTYPE,DATATYPE,ITEMTYPE>,ITreeWithGlobalUniqueID<KEYTYPE,DATATYPE,ITEMTYPE>
- Direct Known Subclasses:
BasicFolderTree,DefaultTreeWithGlobalUniqueID
@NotThreadSafe public class BasicTreeWithGlobalUniqueID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>> extends BasicTreeWithID<KEYTYPE,DATATYPE,ITEMTYPE> implements ITreeWithGlobalUniqueID<KEYTYPE,DATATYPE,ITEMTYPE>
A managed tree is a specialized version of the tree, where each item is required to have a unique ID so that item searching can be performed quite easily.- Author:
- Philip Helger
-
-
Constructor Summary
Constructors Constructor Description BasicTreeWithGlobalUniqueID(ITreeItemWithUniqueIDFactory<KEYTYPE,DATATYPE,ITEMTYPE> aFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsItemWithID(KEYTYPE aDataID)Check if a tree item corresponding to the given ID is present.booleanequals(Object o)com.helger.commons.collection.impl.ICommonsList<? extends ITEMTYPE>getAllChildren(ITEMTYPE aItem)com.helger.commons.collection.impl.ICommonsCollection<DATATYPE>getAllItemDatas()com.helger.commons.collection.impl.ICommonsCollection<ITEMTYPE>getAllItems()intgetChildCount(ITEMTYPE aItem)ITEMTYPEgetChildWithID(ITEMTYPE aCurrentItem, KEYTYPE aDataID)protected ITreeItemWithUniqueIDFactory<KEYTYPE,DATATYPE,ITEMTYPE>getFactory()intgetItemCount()DATATYPEgetItemDataWithID(KEYTYPE aDataID)Get the data of the tree item that corresponds to the given ID.ITEMTYPEgetItemWithID(KEYTYPE aDataID)Get theITreeItemWithIDthat corresponds to the given ID.booleanhasChildren(ITEMTYPE aItem)inthashCode()booleanisItemSameOrDescendant(KEYTYPE aParentItemID, KEYTYPE aChildItemID)Check if one item is equal or a child of the other item.com.helger.commons.state.EChangeremoveItemWithID(KEYTYPE aDataID)Remove the item with the specified IDStringtoString()-
Methods inherited from class com.helger.tree.withid.BasicTreeWithID
forAllChildren, forAllChildren, forAllChildrenBreakable, forAllChildrenMapped, getAllChildren, getChildCount, getChildren, getRootItem, hasChildren
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.tree.IBasicTree
getRootItem
-
-
-
-
Constructor Detail
-
BasicTreeWithGlobalUniqueID
public BasicTreeWithGlobalUniqueID(@Nonnull ITreeItemWithUniqueIDFactory<KEYTYPE,DATATYPE,ITEMTYPE> aFactory)
-
-
Method Detail
-
getFactory
@Nonnull protected final ITreeItemWithUniqueIDFactory<KEYTYPE,DATATYPE,ITEMTYPE> getFactory()
- Returns:
- The factory used for creation. For internal use only.
-
containsItemWithID
public final boolean containsItemWithID(@Nullable KEYTYPE aDataID)
Description copied from interface:ITreeWithGlobalUniqueIDCheck if a tree item corresponding to the given ID is present.- Specified by:
containsItemWithIDin interfaceITreeWithGlobalUniqueID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>- Parameters:
aDataID- The ID of the tree item to search.- Returns:
trueif such an item is present
-
getItemWithID
@Nullable public final ITEMTYPE getItemWithID(@Nullable KEYTYPE aDataID)
Description copied from interface:ITreeWithGlobalUniqueIDGet theITreeItemWithIDthat corresponds to the given ID.- Specified by:
getItemWithIDin interfaceITreeWithGlobalUniqueID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>- Parameters:
aDataID- The ID of the tree item to search.- Returns:
nullif no such tree item exists.
-
getItemDataWithID
@Nullable public final DATATYPE getItemDataWithID(@Nullable KEYTYPE aDataID)
Description copied from interface:ITreeWithGlobalUniqueIDGet the data of the tree item that corresponds to the given ID.- Specified by:
getItemDataWithIDin interfaceITreeWithGlobalUniqueID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>- Parameters:
aDataID- The ID of the tree item to search.- Returns:
nullif no such tree item exists.
-
getChildWithID
@Nullable public final ITEMTYPE getChildWithID(@Nullable ITEMTYPE aCurrentItem, @Nullable KEYTYPE aDataID)
-
getItemCount
@Nonnegative public final int getItemCount()
- Specified by:
getItemCountin interfaceITreeWithGlobalUniqueID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>- Returns:
- The number of all contained items. Always ≥ 0.
-
getAllItems
@Nonnull @ReturnsMutableCopy public final com.helger.commons.collection.impl.ICommonsCollection<ITEMTYPE> getAllItems()
- Specified by:
getAllItemsin interfaceITreeWithGlobalUniqueID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>- Returns:
- A non-
nullcollection of all items.
-
getAllItemDatas
@Nonnull @ReturnsMutableCopy public final com.helger.commons.collection.impl.ICommonsCollection<DATATYPE> getAllItemDatas()
- Specified by:
getAllItemDatasin interfaceITreeWithGlobalUniqueID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>- Returns:
- A non-
nullcollection of all item datas.
-
removeItemWithID
@Nonnull public final com.helger.commons.state.EChange removeItemWithID(@Nullable KEYTYPE aDataID)
Description copied from interface:ITreeWithGlobalUniqueIDRemove the item with the specified ID- Specified by:
removeItemWithIDin interfaceITreeWithGlobalUniqueID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>- Parameters:
aDataID- The ID of the item to be removed- Returns:
EChange.CHANGEDif the item was removed,EChange.UNCHANGEDotherwise. Nevernull.
-
isItemSameOrDescendant
public final boolean isItemSameOrDescendant(@Nullable KEYTYPE aParentItemID, @Nullable KEYTYPE aChildItemID)
Description copied from interface:ITreeWithGlobalUniqueIDCheck if one item is equal or a child of the other item. This relationship is checked not only for direct children but for all levels.- Specified by:
isItemSameOrDescendantin interfaceITreeWithGlobalUniqueID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>- Parameters:
aParentItemID- The parent item ID to a validate.aChildItemID- The item ID to check whether it is a child of the passed parent folder.- Returns:
trueif the child item is the same or a child of the parent item,falseif one of the IDs could not be resolved or they are not in a parent-child-relationship.
-
hasChildren
public boolean hasChildren(@Nullable ITEMTYPE aItem)
- Specified by:
hasChildrenin interfacecom.helger.commons.hierarchy.IChildrenProvider<KEYTYPE>
-
getChildCount
@Nonnegative public int getChildCount(@Nullable ITEMTYPE aItem)
- Specified by:
getChildCountin interfacecom.helger.commons.hierarchy.IChildrenProvider<KEYTYPE>
-
getAllChildren
@Nullable public com.helger.commons.collection.impl.ICommonsList<? extends ITEMTYPE> getAllChildren(@Nullable ITEMTYPE aItem)
- Specified by:
getAllChildrenin interfacecom.helger.commons.hierarchy.IChildrenProvider<KEYTYPE>
-
equals
public boolean equals(Object o)
- Overrides:
equalsin classBasicTreeWithID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classBasicTreeWithID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>
-
toString
public String toString()
- Overrides:
toStringin classBasicTreeWithID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>
-
-