Package com.helger.tree.withid.unique
Class AbstractTreeItemWithUniqueIDFactory<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>
- java.lang.Object
-
- com.helger.tree.withid.unique.AbstractTreeItemWithUniqueIDFactory<KEYTYPE,DATATYPE,ITEMTYPE>
-
- Type Parameters:
KEYTYPE- The key type.DATATYPE- The value type to be contained in tree items.ITEMTYPE- tree item type
- All Implemented Interfaces:
ITreeItemWithIDFactory<KEYTYPE,DATATYPE,ITEMTYPE>,ITreeItemWithUniqueIDFactory<KEYTYPE,DATATYPE,ITEMTYPE>
- Direct Known Subclasses:
AbstractFolderTreeItemFactory,DefaultTreeItemWithUniqueIDFactory
@NotThreadSafe public abstract class AbstractTreeItemWithUniqueIDFactory<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>> extends Object implements ITreeItemWithUniqueIDFactory<KEYTYPE,DATATYPE,ITEMTYPE>
An abstract tree item factory that maintains a unique ID over all items. It does not put the root item in the data store!- Author:
- Philip Helger
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractTreeItemWithUniqueIDFactory()protectedAbstractTreeItemWithUniqueIDFactory(com.helger.commons.collection.impl.ICommonsMap<KEYTYPE,ITEMTYPE> aItemStore)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected ITEMTYPEaddToItemStore(KEYTYPE aDataID, ITEMTYPE aItem)booleancontainsItemWithDataID(KEYTYPE aDataID)Check if an item with the given ID is contained.ITEMTYPEcreate(ITEMTYPE aParent, KEYTYPE aDataID)Create a child entry.booleanequals(Object o)com.helger.commons.collection.impl.ICommonsList<DATATYPE>getAllItemDatas()com.helger.commons.collection.impl.ICommonsList<ITEMTYPE>getAllItems()intgetItemCount()ITEMTYPEgetItemOfDataID(KEYTYPE aDataID)Try to retrieve the stored item with the given ID.inthashCode()protected abstract ITEMTYPEinternalCreate(ITEMTYPE aParent, KEYTYPE aDataID)protected KEYTYPEinternalGetItemID(ITEMTYPE aItem)Get the ID of the passed tree item to use for internal storage.voidonAddItem(ITEMTYPE aTreeItem)To be called once a tree item is added to the owning tree.voidonRemoveItem(ITEMTYPE aTreeItem)To be called once a tree item is removed from the owning tree.StringtoString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.tree.withid.ITreeItemWithIDFactory
createRoot
-
-
-
-
Method Detail
-
addToItemStore
@Nonnull protected final ITEMTYPE addToItemStore(@Nonnull KEYTYPE aDataID, @Nonnull ITEMTYPE aItem)
-
internalCreate
@Nonnull protected abstract ITEMTYPE internalCreate(@Nonnull ITEMTYPE aParent, @Nonnull KEYTYPE aDataID)
-
internalGetItemID
@Nonnull @OverrideOnDemand protected KEYTYPE internalGetItemID(@Nonnull ITEMTYPE aItem)
Get the ID of the passed tree item to use for internal storage.- Parameters:
aItem- The item who's ID is to be resolved.- Returns:
- The ID of the item
-
create
@Nonnull public final ITEMTYPE create(@Nonnull ITEMTYPE aParent, @Nonnull KEYTYPE aDataID)
Description copied from interface:ITreeItemWithIDFactoryCreate a child entry.- Specified by:
createin interfaceITreeItemWithIDFactory<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>- Parameters:
aParent- The parent entry to use. May not benull.aDataID- The data ID of the new element- Returns:
- The created non-root entry. May not be
null.
-
onRemoveItem
public final void onRemoveItem(@Nonnull ITEMTYPE aTreeItem)
Description copied from interface:ITreeItemWithIDFactoryTo be called once a tree item is removed from the owning tree. This method is mainly important for the tree with globally unique IDs.- Specified by:
onRemoveItemin interfaceITreeItemWithIDFactory<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>- Parameters:
aTreeItem- The item that was removed.
-
onAddItem
public final void onAddItem(@Nonnull ITEMTYPE aTreeItem)
Description copied from interface:ITreeItemWithIDFactoryTo be called once a tree item is added to the owning tree. This method is mainly important for the tree with globally unique IDs.- Specified by:
onAddItemin interfaceITreeItemWithIDFactory<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>- Parameters:
aTreeItem- The item that was added.
-
containsItemWithDataID
public final boolean containsItemWithDataID(@Nullable KEYTYPE aDataID)
Description copied from interface:ITreeItemWithUniqueIDFactoryCheck if an item with the given ID is contained.- Specified by:
containsItemWithDataIDin interfaceITreeItemWithUniqueIDFactory<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>- Parameters:
aDataID- The data ID to look up.- Returns:
trueif such an item is contained,falseotherwise.
-
getItemOfDataID
@Nullable public final ITEMTYPE getItemOfDataID(@Nullable KEYTYPE aDataID)
Description copied from interface:ITreeItemWithUniqueIDFactoryTry to retrieve the stored item with the given ID.- Specified by:
getItemOfDataIDin interfaceITreeItemWithUniqueIDFactory<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>- Parameters:
aDataID- The data ID to look up.- Returns:
nullif no such item is contained, the item otherwise.
-
getItemCount
@Nonnegative public final int getItemCount()
- Specified by:
getItemCountin interfaceITreeItemWithUniqueIDFactory<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.ICommonsList<ITEMTYPE> getAllItems()
- Specified by:
getAllItemsin interfaceITreeItemWithUniqueIDFactory<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>- Returns:
- A collection that contains all items created by this factory instance.
-
getAllItemDatas
@Nonnull @ReturnsMutableCopy public final com.helger.commons.collection.impl.ICommonsList<DATATYPE> getAllItemDatas()
- Specified by:
getAllItemDatasin interfaceITreeItemWithUniqueIDFactory<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>- Returns:
- A collection that contains all item datas created by this factory instance.
-
-