T
- data typepublic class TreeData<T> extends Object implements Serializable
Typically used as a backing data source for TreeDataProvider
.
Constructor and Description |
---|
TreeData()
Creates an initially empty hierarchical data representation to which
items can be added or removed.
|
Modifier and Type | Method and Description |
---|---|
TreeData<T> |
addItem(T parent,
T item)
Adds a data item as a child of
parent . |
TreeData<T> |
addItems(Collection<T> rootItems,
ValueProvider<T,Collection<T>> childItemProvider)
Adds the given items as root items and uses the given value provider to
recursively populate children of the root items.
|
TreeData<T> |
addItems(Stream<T> rootItems,
ValueProvider<T,Stream<T>> childItemProvider)
Adds the given items as root items and uses the given value provider to
recursively populate children of the root items.
|
TreeData<T> |
addItems(T parent,
Collection<T> items)
Adds a list of data items as children of
parent . |
TreeData<T> |
addItems(T parent,
Stream<T> items)
Adds data items contained in a stream as children of
parent . |
TreeData<T> |
addItems(T parent,
T... items)
Adds a list of data items as children of
parent . |
TreeData<T> |
addRootItems(Collection<T> items)
Adds the items of the given collection as root items to this structure.
|
TreeData<T> |
addRootItems(Stream<T> items)
Adds the items of the given stream as root items to this structure.
|
TreeData<T> |
addRootItems(T... items)
Adds the items as root items to this structure.
|
TreeData<T> |
clear()
Clear all items from this structure.
|
boolean |
contains(T item)
Check whether the given item is in this hierarchy.
|
List<T> |
getChildren(T item)
Get the immediate child items for the given item.
|
T |
getParent(T item)
Get the parent item for the given item.
|
List<T> |
getRootItems()
Gets the root items of this structure.
|
void |
moveAfterSibling(T item,
T sibling)
Moves an item to the position immediately after a sibling item.
|
TreeData<T> |
removeItem(T item)
Remove a given item from this structure.
|
void |
setParent(T item,
T parent)
Moves an item to become a child of the given parent item.
|
public TreeData()
public TreeData<T> addRootItems(T... items)
items
- the items to addIllegalArgumentException
- if any of the given items have already been added to this
structureNullPointerException
- if any of the items are {code null}public TreeData<T> addRootItems(Collection<T> items)
items
- the collection of items to addIllegalArgumentException
- if any of the given items have already been added to this
structureNullPointerException
- if any of the items are {code null}public TreeData<T> addRootItems(Stream<T> items)
items
- the stream of root items to addIllegalArgumentException
- if any of the given items have already been added to this
structureNullPointerException
- if any of the items are {code null}public TreeData<T> addItem(T parent, T item)
parent
. Call with null
as
parent to add a root level item. The given parent item must already exist
in this structure, and an item can only be added to this structure once.parent
- the parent item for which the items are added as childrenitem
- the item to addIllegalArgumentException
- if parent is not null and not already added to this structureIllegalArgumentException
- if the item has already been added to this structureNullPointerException
- if item is nullpublic TreeData<T> addItems(T parent, T... items)
parent
. Call with
null
as parent to add root level items. The given parent item
must already exist in this structure, and an item can only be added to
this structure once.parent
- the parent item for which the items are added as childrenitems
- the list of items to addIllegalArgumentException
- if parent is not null and not already added to this structureIllegalArgumentException
- if any of the given items have already been added to this
structureNullPointerException
- if any of the items are nullpublic TreeData<T> addItems(T parent, Collection<T> items)
parent
. Call with
null
as parent to add root level items. The given parent item
must already exist in this structure, and an item can only be added to
this structure once.parent
- the parent item for which the items are added as childrenitems
- the collection of items to addIllegalArgumentException
- if parent is not null and not already added to this structureIllegalArgumentException
- if any of the given items have already been added to this
structureNullPointerException
- if any of the items are nullpublic TreeData<T> addItems(T parent, Stream<T> items)
parent
. Call
with null
as parent to add root level items. The given parent
item must already exist in this structure, and an item can only be added
to this structure once.parent
- the parent item for which the items are added as childrenitems
- stream of items to addIllegalArgumentException
- if parent is not null and not already added to this structureIllegalArgumentException
- if any of the given items have already been added to this
structureNullPointerException
- if any of the items are nullpublic TreeData<T> addItems(Collection<T> rootItems, ValueProvider<T,Collection<T>> childItemProvider)
rootItems
- the root items to addchildItemProvider
- the value provider used to recursively populate this TreeData
from the given root itemspublic TreeData<T> addItems(Stream<T> rootItems, ValueProvider<T,Stream<T>> childItemProvider)
rootItems
- the root items to addchildItemProvider
- the value provider used to recursively populate this TreeData
from the given root itemspublic TreeData<T> removeItem(T item)
item
- the item to remove, or null to clear all dataIllegalArgumentException
- if the item does not exist in this structurepublic TreeData<T> clear()
removeItem(Object)
with null.public List<T> getRootItems()
public List<T> getChildren(T item)
item
- the item for which to retrieve child items for, null to
retrieve all root itemsIllegalArgumentException
- if the item does not exist in this structurepublic T getParent(T item)
item
- the item for which to retrieve the parent item fornull
if the item is a
root item.IllegalArgumentException
- if the item does not exist in this structurepublic void setParent(T item, T parent)
null
makes the item a root item. After making changes to the tree data,
AbstractDataProvider.refreshAll()
should be called.item
- the item to be set as the child of parent
parent
- the item to be set as parent or null
to set the item
as rootpublic void moveAfterSibling(T item, T sibling)
AbstractDataProvider.refreshAll()
should be called.item
- the item to be movedsibling
- the item after which the moved item will be located, or null
to move item to first positionpublic boolean contains(T item)
item
- the item to checktrue
if the item is in this hierarchy, false
if
notCopyright © 2018. All rights reserved.