Package net.sf.basedb.util
Class Tree<E>
- java.lang.Object
-
- net.sf.basedb.util.Tree<E>
-
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
public class Tree<E> extends Object implements Collection<E>
- Version:
- 2.0
- Author:
- Nicklas
- Last modified
- $Date: 2015-05-12 11:27:08 +0200 (ti, 12 maj 2015) $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
-
-
-
-
Field Detail
-
root
private final E root
-
entries
private final Map<E,Tree.Entry<E>> entries
-
-
Constructor Detail
-
Tree
public Tree(E root)
Create a new tree with the with the default initial capacity (16).- Parameters:
root
- The root node element of the tree
-
Tree
public Tree(E root, int initialCapacity)
Create a new tree with the with the specified initial capacity.- Parameters:
root
- The root node element of the treeinitialCapacity
- The initial capacity
-
-
Method Detail
-
add
public boolean add(E o)
Not supported.- Specified by:
add
in interfaceCollection<E>
- Throws:
UnsupportedOperationException
- Always- See Also:
Tree.Entry.addChild(Object)
-
addAll
public boolean addAll(Collection<? extends E> c)
Not supported.- Specified by:
addAll
in interfaceCollection<E>
- Throws:
UnsupportedOperationException
- Always
-
clear
public void clear()
Clear all elements except the root element.- Specified by:
clear
in interfaceCollection<E>
-
contains
public boolean contains(Object o)
- Specified by:
contains
in interfaceCollection<E>
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAll
in interfaceCollection<E>
-
equals
public boolean equals(Object o)
Equality only tests if the object is the same instance of this tree. Note! In the future, the implementation may change to also check the entire tree structure.- Specified by:
equals
in interfaceCollection<E>
- Overrides:
equals
in classObject
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfaceCollection<E>
- Overrides:
hashCode
in classObject
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<E>
-
remove
public boolean remove(Object o)
Not supported.- Specified by:
remove
in interfaceCollection<E>
- Throws:
UnsupportedOperationException
- Always
-
removeAll
public boolean removeAll(Collection<?> c)
Not supported.- Specified by:
removeAll
in interfaceCollection<E>
- Throws:
UnsupportedOperationException
- Always
-
retainAll
public boolean retainAll(Collection<?> c)
Not supported.- Specified by:
retainAll
in interfaceCollection<E>
- Throws:
UnsupportedOperationException
- Always
-
size
public int size()
- Specified by:
size
in interfaceCollection<E>
-
toArray
public Object[] toArray()
Not supported.- Specified by:
toArray
in interfaceCollection<E>
- Throws:
UnsupportedOperationException
- Always
-
toArray
public <T> T[] toArray(T[] a)
Not supported.- Specified by:
toArray
in interfaceCollection<E>
- Throws:
UnsupportedOperationException
- Always
-
getRootEntry
public Tree.Entry<E> getRootEntry()
Get the entry for the root node.- Returns:
- The
Entry
object for the root node.
-
getEntry
public Tree.Entry<E> getEntry(E node)
Get the entry for an arbitrary node.- Parameters:
node
- The node to get the entry for.- Returns:
- An
Entry
object or null if the node isn't found
-
entryIterator
public Iterator<Tree.Entry<E>> entryIterator()
Create an iterator for the tree that returns entry object. The iterator starts at the root.- Returns:
- An
Iterator
object - See Also:
iterator()
-
entryIterator
public Iterator<Tree.Entry<E>> entryIterator(E node)
Create an iterator for the tree starting at a specific node.- Parameters:
node
- The node to start at- Returns:
- An
Iterator
object - See Also:
iterator()
-
addEntry
private void addEntry(Tree.Entry<E> entry)
-
-