DATATYPE - tree item value typeITEMTYPE - tree item implementation type@NotThreadSafe public class BasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItem<DATATYPE,ITEMTYPE>> extends Object implements ITreeItem<DATATYPE,ITEMTYPE>
ITreeItem interface| Constructor and Description |
|---|
BasicTreeItem(ITEMTYPE aParent)
Constructor for normal elements.
|
BasicTreeItem(ITreeItemFactory<DATATYPE,ITEMTYPE> aFactory)
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).
|
ITEMTYPE |
createChildItem(DATATYPE aData)
Add a child item to this item.
|
boolean |
equals(Object o) |
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() |
List<ITEMTYPE> |
getChildren() |
DATATYPE |
getData() |
ITreeItemFactory<DATATYPE,ITEMTYPE> |
getFactory() |
ITEMTYPE |
getFirstChild()
Get the first child node or
null if no child is present |
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() |
boolean |
hasChildren() |
int |
hashCode() |
EChange |
internalAddChild(ITEMTYPE aChild)
Add an existing 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.
|
EChange |
removeChild(ITEMTYPE aChild)
Remove the passed node as a child node from this node.
|
void |
reorderChildItems(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 BasicTreeItem(@Nonnull ITreeItemFactory<DATATYPE,ITEMTYPE> aFactory)
aFactory - The factory to use for creating tree items. May not be
null.@Nonnull public final ITreeItemFactory<DATATYPE,ITEMTYPE> getFactory()
@OverrideOnDemand protected boolean isValidData(DATATYPE aData)
aData - The value to validate.true if the ID is valid, false otherwise.public final void setData(@Nullable DATATYPE aData)
IBasicTreeItempublic final boolean isRootItem()
isRootItem in interface IBasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItem<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()
IHasParent@Nullable public final DATATYPE getParentData()
getParentData in interface IBasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItem<DATATYPE,ITEMTYPE>>null.@Nonnull public final ITEMTYPE createChildItem(@Nullable DATATYPE aData)
public final boolean hasChildren()
hasChildren in interface IHasChildren<ITEMTYPE extends ITreeItem<DATATYPE,ITEMTYPE>>true if this item has direct children,
false otherwise.@Nullable @ReturnsMutableCopy public final List<ITEMTYPE> getChildren()
getChildren in interface IHasChildren<ITEMTYPE extends ITreeItem<DATATYPE,ITEMTYPE>>getChildren in interface IHasChildrenSorted<ITEMTYPE extends ITreeItem<DATATYPE,ITEMTYPE>>null if no
children are present.@Nullable public final List<DATATYPE> getAllChildDatas()
IBasicTreeItemgetAllChildDatas in interface IBasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItem<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 ITreeItem<DATATYPE,ITEMTYPE>>nIndex - The index to be queried. May not be < 0 or ≥ the number of
childrennull if the index
is invalid.@Nonnegative public final int getChildCount()
getChildCount in interface IHasChildren<ITEMTYPE extends ITreeItem<DATATYPE,ITEMTYPE>>@Nullable public ITEMTYPE getFirstChild()
IHasChildrenSortednull if no child is presentgetFirstChild in interface IHasChildrenSorted<ITEMTYPE extends ITreeItem<DATATYPE,ITEMTYPE>>null.@Nullable public ITEMTYPE getLastChild()
IHasChildrenSortednull if no child is presentgetLastChild in interface IHasChildrenSorted<ITEMTYPE extends ITreeItem<DATATYPE,ITEMTYPE>>null.public final boolean isSameOrChildOf(@Nonnull ITEMTYPE aParent)
IBasicTreeItemisSameOrChildOf in interface IBasicTreeItem<DATATYPE,ITEMTYPE extends ITreeItem<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 ITreeItem<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 ITEMTYPE aChild)
ITreeIteminternalAddChild in interface ITreeItem<DATATYPE,ITEMTYPE extends ITreeItem<DATATYPE,ITEMTYPE>>aChild - The child to be added. May not be null.EChange.UNCHANGED if the child is already contained,
EChange.CHANGED upon success.@Nonnull public final EChange removeChild(@Nonnull ITEMTYPE aChild)
ITreeItemremoveChild in interface ITreeItem<DATATYPE,ITEMTYPE extends ITreeItem<DATATYPE,ITEMTYPE>>aChild - The child to be removed. May not be null
- Returns:
EChange.CHANGED if the removal succeeded,
EChange.UNCHANGED otherwisepublic final void reorderChildItems(@Nonnull Comparator<? super ITEMTYPE> aComparator)
ITreeItemCopyright © 2006–2014 phloc systems. All rights reserved.