public class Tree<E> extends Object implements Collection<E>
Modifier and Type | Class and Description |
---|---|
private class |
Tree.ElementIterator
An iterator that return elements for each node.
|
static class |
Tree.Entry<E>
Represents an entry for a node in the tree.
|
private class |
Tree.EntryIterator
An iterator that return entries for each node.
|
Modifier and Type | Field and Description |
---|---|
private Map<E,Tree.Entry<E>> |
entries |
private E |
root |
Constructor and Description |
---|
Tree(E root)
Create a new tree with the with the default initial capacity (16).
|
Tree(E root,
int initialCapacity)
Create a new tree with the with the specified initial capacity.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E o)
Not supported.
|
boolean |
addAll(Collection<? extends E> c)
Not supported.
|
private void |
addEntry(Tree.Entry<E> entry) |
void |
clear()
Clear all elements except the root element.
|
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
Iterator<Tree.Entry<E>> |
entryIterator()
Create an iterator for the tree that returns entry object.
|
Iterator<Tree.Entry<E>> |
entryIterator(E node)
Create an iterator for the tree starting at a specific node.
|
boolean |
equals(Object o)
Equality only tests if the object is the same instance of this tree.
|
Tree.Entry<E> |
getEntry(E node)
Get the entry for an arbitrary node.
|
Tree.Entry<E> |
getRootEntry()
Get the entry for the root node.
|
int |
hashCode() |
boolean |
isEmpty() |
Iterator<E> |
iterator() |
boolean |
remove(Object o)
Not supported.
|
boolean |
removeAll(Collection<?> c)
Not supported.
|
boolean |
retainAll(Collection<?> c)
Not supported.
|
int |
size() |
Object[] |
toArray()
Not supported.
|
<T> T[] |
toArray(T[] a)
Not supported.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
parallelStream, removeIf, spliterator, stream
private final E root
private final Map<E,Tree.Entry<E>> entries
public Tree(E root)
root
- The root node element of the treepublic Tree(E root, int initialCapacity)
root
- The root node element of the treeinitialCapacity
- The initial capacitypublic boolean add(E o)
add
in interface Collection<E>
UnsupportedOperationException
- AlwaysTree.Entry.addChild(Object)
public boolean addAll(Collection<? extends E> c)
addAll
in interface Collection<E>
UnsupportedOperationException
- Alwayspublic void clear()
clear
in interface Collection<E>
public boolean contains(Object o)
contains
in interface Collection<E>
public boolean containsAll(Collection<?> c)
containsAll
in interface Collection<E>
public boolean equals(Object o)
equals
in interface Collection<E>
equals
in class Object
public int hashCode()
hashCode
in interface Collection<E>
hashCode
in class Object
public boolean isEmpty()
isEmpty
in interface Collection<E>
public boolean remove(Object o)
remove
in interface Collection<E>
UnsupportedOperationException
- Alwayspublic boolean removeAll(Collection<?> c)
removeAll
in interface Collection<E>
UnsupportedOperationException
- Alwayspublic boolean retainAll(Collection<?> c)
retainAll
in interface Collection<E>
UnsupportedOperationException
- Alwayspublic int size()
size
in interface Collection<E>
public Object[] toArray()
toArray
in interface Collection<E>
UnsupportedOperationException
- Alwayspublic <T> T[] toArray(T[] a)
toArray
in interface Collection<E>
UnsupportedOperationException
- Alwayspublic Tree.Entry<E> getRootEntry()
Entry
object for the root node.public Tree.Entry<E> getEntry(E node)
node
- The node to get the entry for.Entry
object or null if the node isn't foundpublic Iterator<Tree.Entry<E>> entryIterator()
Iterator
objectiterator()
public Iterator<Tree.Entry<E>> entryIterator(E node)
node
- The node to start atIterator
objectiterator()
private void addEntry(Tree.Entry<E> entry)