public class Tree<E>
extends java.lang.Object
implements java.util.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 java.util.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(java.util.Collection<? extends E> c)
Not supported.
|
private void |
addEntry(Tree.Entry<E> entry) |
void |
clear()
Clear all elements except the root element.
|
boolean |
contains(java.lang.Object o) |
boolean |
containsAll(java.util.Collection<?> c) |
java.util.Iterator<Tree.Entry<E>> |
entryIterator()
Create an iterator for the tree that returns entry object.
|
java.util.Iterator<Tree.Entry<E>> |
entryIterator(E node)
Create an iterator for the tree starting at a specific node.
|
boolean |
equals(java.lang.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() |
java.util.Iterator<E> |
iterator() |
boolean |
remove(java.lang.Object o)
Not supported.
|
boolean |
removeAll(java.util.Collection<?> c)
Not supported.
|
boolean |
retainAll(java.util.Collection<?> c)
Not supported.
|
int |
size() |
java.lang.Object[] |
toArray()
Not supported.
|
<T> T[] |
toArray(T[] a)
Not supported.
|
private final E root
private final java.util.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 java.util.Collection<E>
java.lang.UnsupportedOperationException
- AlwaysTree.Entry.addChild(Object)
public boolean addAll(java.util.Collection<? extends E> c)
addAll
in interface java.util.Collection<E>
java.lang.UnsupportedOperationException
- Alwayspublic void clear()
clear
in interface java.util.Collection<E>
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection<E>
public boolean containsAll(java.util.Collection<?> c)
containsAll
in interface java.util.Collection<E>
public boolean equals(java.lang.Object o)
equals
in interface java.util.Collection<E>
equals
in class java.lang.Object
public int hashCode()
hashCode
in interface java.util.Collection<E>
hashCode
in class java.lang.Object
public boolean isEmpty()
isEmpty
in interface java.util.Collection<E>
public java.util.Iterator<E> iterator()
public boolean remove(java.lang.Object o)
remove
in interface java.util.Collection<E>
java.lang.UnsupportedOperationException
- Alwayspublic boolean removeAll(java.util.Collection<?> c)
removeAll
in interface java.util.Collection<E>
java.lang.UnsupportedOperationException
- Alwayspublic boolean retainAll(java.util.Collection<?> c)
retainAll
in interface java.util.Collection<E>
java.lang.UnsupportedOperationException
- Alwayspublic int size()
size
in interface java.util.Collection<E>
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection<E>
java.lang.UnsupportedOperationException
- Alwayspublic <T> T[] toArray(T[] a)
toArray
in interface java.util.Collection<E>
java.lang.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 java.util.Iterator<Tree.Entry<E>> entryIterator()
Iterator
objectiterator()
public java.util.Iterator<Tree.Entry<E>> entryIterator(E node)
node
- The node to start atIterator
objectiterator()
private void addEntry(Tree.Entry<E> entry)