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 |
|---|---|
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) |
Set<KEYTYPE> |
getAllChildDataIDs() |
List<DATATYPE> |
getAllChildDatas()
Get the data values of all contained children.
|
ITEMTYPE |
getChildAtIndex(int nIndex)
Get the child node at the specified index
|
int |
getChildCount() |
ITEMTYPE |
getChildItemOfDataID(KEYTYPE aDataID)
Find the direct child item with the given ID
|
List<ITEMTYPE> |
getChildren() |
DATATYPE |
getData() |
ITreeItemWithIDFactory<KEYTYPE,DATATYPE,ITEMTYPE> |
getFactory() |
ITEMTYPE |
getFirstChild()
Get the first child node or
null if no child is present |
KEYTYPE |
getID()
Get the unique ID of this object.
|
ITEMTYPE |
getLastChild()
Get the last child node or
null if no child is present |
ITEMTYPE |
getParent()
Get the parent object of this object.
|
DATATYPE |
getParentData() |
KEYTYPE |
getParentID() |
boolean |
hasChildren() |
int |
hashCode() |
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.
|
EChange |
removeAllChildren()
Remove all children from this node.
|
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() |
public 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()
IHasParentgetParent in interface IHasParent<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>null if this object has no
parent.@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.@Nullable public final KEYTYPE getID()
IHasIDString than the
returned value must match an XML NMToken expression (so e.g. no ':' in the
ID)!@Nullable public final DATATYPE getData()
getData in interface IBasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>null.public final boolean hasChildren()
hasChildren in interface IHasChildren<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>true if this item has direct children,
false otherwise.@Nonnegative public final int getChildCount()
getChildCount in interface IHasChildren<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>@Nullable @ReturnsMutableCopy public final List<ITEMTYPE> getChildren()
getChildren in interface IHasChildren<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>getChildren in interface IHasChildrenSorted<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>null if no
children are present.@Nullable @ReturnsMutableCopy public final Set<KEYTYPE> getAllChildDataIDs()
getAllChildDataIDs in interface ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>null if returned.@Nullable @ReturnsMutableCopy public final List<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)
IHasChildrenSortedgetChildAtIndex in interface IHasChildrenSorted<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>nIndex - The index to be queried. May not be < 0 or ≥ the number of
childrennull if the index
is invalid.@Nullable public ITEMTYPE getFirstChild()
IHasChildrenSortednull if no child is presentgetFirstChild in interface IHasChildrenSorted<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>null.@Nullable public ITEMTYPE getLastChild()
IHasChildrenSortednull if no child is presentgetLastChild in interface IHasChildrenSorted<ITEMTYPE extends ITreeItemWithID<KEYTYPE,DATATYPE,ITEMTYPE>>null.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 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 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 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
- Returns:
EChange@Nonnull public final 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 © 2006–2014 phloc systems. All rights reserved.