O
- Object type (arbitrary!)public class HashMapHierarchy<O> extends Object implements ModifiableHierarchy<O>
Modifier and Type | Class and Description |
---|---|
private class |
HashMapHierarchy.ItrAll
Iterator over all members of the hierarchy.
|
private class |
HashMapHierarchy.ItrAnc
Iterator over all Ancestors.
|
private class |
HashMapHierarchy.ItrDesc
Iterator to collect into the descendants.
|
private static class |
HashMapHierarchy.Rec<O>
Hierarchy pointers for an object.
|
Hierarchy.Iter<O>
Modifier and Type | Field and Description |
---|---|
private static Hierarchy.Iter<?> |
EMPTY_ITERATOR
Empty iterator.
|
private HashMap<O,HashMapHierarchy.Rec<O>> |
graph
Reference storage.
|
Constructor and Description |
---|
HashMapHierarchy()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(O entry)
Add an entry (initializes data structures).
|
void |
add(O parent,
O child)
Add a parent-child relationship.
|
Hierarchy.Iter<O> |
iterAll()
Iterate over all members.
|
Hierarchy.Iter<O> |
iterAncestors(O obj)
Iterate ancestors (recursive parents)
|
Hierarchy.Iter<O> |
iterChildren(O obj)
Iterate over the (direct) children.
|
Hierarchy.Iter<O> |
iterDescendants(O obj)
Iterate descendants (recursive children)
|
Hierarchy.Iter<O> |
iterParents(O obj)
Iterate over the (direct) parents.
|
int |
numChildren(O obj)
Get number of children
|
int |
numParents(O obj)
Get number of (direct) parents
|
void |
remove(O entry)
Remove an entry and all its parent-child relationships.
|
void |
remove(O parent,
O child)
Remove a parent-child relationship.
|
void |
removeSubtree(O entry)
Remove an entry and it's whole subtree (unless the elements are reachable
by a different path!)
|
int |
size()
Total size - number of objects contained.
|
private final HashMap<O,HashMapHierarchy.Rec<O>> graph
private static final Hierarchy.Iter<?> EMPTY_ITERATOR
public int size()
Hierarchy
public void add(O parent, O child)
ModifiableHierarchy
add
in interface ModifiableHierarchy<O>
parent
- Parentchild
- Childpublic void add(O entry)
ModifiableHierarchy
add
in interface ModifiableHierarchy<O>
entry
- Entrypublic void remove(O parent, O child)
ModifiableHierarchy
remove
in interface ModifiableHierarchy<O>
parent
- Parentchild
- Childpublic void remove(O entry)
ModifiableHierarchy
remove
in interface ModifiableHierarchy<O>
entry
- Entrypublic void removeSubtree(O entry)
ModifiableHierarchy
removeSubtree
in interface ModifiableHierarchy<O>
entry
- Entrypublic int numChildren(O obj)
Hierarchy
numChildren
in interface Hierarchy<O>
obj
- object to get number of children forpublic Hierarchy.Iter<O> iterChildren(O obj)
Hierarchy
iterChildren
in interface Hierarchy<O>
obj
- object to get children forpublic Hierarchy.Iter<O> iterDescendants(O obj)
Hierarchy
iterDescendants
in interface Hierarchy<O>
obj
- object to get descendants forpublic int numParents(O obj)
Hierarchy
numParents
in interface Hierarchy<O>
obj
- reference objectpublic Hierarchy.Iter<O> iterParents(O obj)
Hierarchy
iterParents
in interface Hierarchy<O>
obj
- object to get parents forpublic Hierarchy.Iter<O> iterAncestors(O obj)
Hierarchy
iterAncestors
in interface Hierarchy<O>
obj
- object to get ancestors for