public class MrTreeMap<K,V>
extends java.lang.Object
implements java.lang.Iterable<V>
MrMapFuncion
Modifier and Type | Field and Description |
---|---|
static int |
BREADTH_TRAVERSAL
Breadth first traversal mode
|
static int |
DEPTH_TRAVERSAL
Depth first traversal mode
|
Constructor and Description |
---|
MrTreeMap(MrMapFunction<K,V> mapFunction)
Creates an empty MrTreeMap
|
MrTreeMap(V root,
MrMapFunction<K,V> mapFunction)
Creates a MrTreeMap with a root element
|
Modifier and Type | Method and Description |
---|---|
boolean |
addChild(V parent,
V data)
Adds a child to the node
|
boolean |
addChildByKey(K parentKey,
V data)
Adds a child to the node
|
java.util.Iterator<V> |
breadthTraversal() |
java.util.Iterator<V> |
breadthTraversal(V data) |
java.util.Iterator<V> |
breadthTraversalByKey(K key) |
void |
clear()
Clears all elements
|
boolean |
contains(V data)
Checks if the key returned by map-function is in inside the tree
|
boolean |
containsKey(K key)
Checks if key exists
|
java.util.Iterator<V> |
depthTraversal() |
java.util.Iterator<V> |
depthTraversal(V data) |
java.util.Iterator<V> |
depthTraversalByKey(K key) |
V |
findByKey(K key)
Finds an object in this tree using its key
|
java.util.List<V> |
getChildrenOf(V data)
Gets the children of an element
|
java.util.List<V> |
getChildrenOfByKey(K key)
Gets the children of an object using its key
|
MrMapFunction<K,V> |
getMapFunction()
Gets the current map function of this tree
|
V |
getParentOf(V data)
Returns the parent of the element
|
V |
getParentOfByKey(K key)
Gets the parent of an element using its key
|
V |
getRoot()
Gets the root object of this tree
|
MrTreeMap<K,V> |
getSubTree(V data)
Gets the subtree from key element
|
MrTreeMap<K,V> |
getSubTreeByKey(K key)
Gets the subtree from key element using key
|
int |
getTraversalMode()
Gets the current traversal mode
|
java.util.Iterator<V> |
iterator() |
java.util.Collection<K> |
keys()
Gets the keys collection
|
java.util.Iterator<java.util.Map.Entry<K,V>> |
parentKeyChildValueTraversal() |
java.util.Iterator<java.util.Map.Entry<K,V>> |
parentKeyChildValueTraversal(V data) |
java.util.Iterator<java.util.Map.Entry<K,V>> |
parentKeyChildValueTraversalByKey(K key) |
java.util.Iterator<V> |
parentTraversal(V data) |
java.util.Iterator<V> |
parentTraversalByKey(K key) |
boolean |
remove(V data)
Removes a certain element from this tree
|
boolean |
removeByKey(K key)
Removes a certain element in this tree
|
void |
setTraversalMode(int traversalMode)
Sets the current traversal mode
|
int |
size()
Number of elements in this tree
|
public static final int BREADTH_TRAVERSAL
public static final int DEPTH_TRAVERSAL
public MrTreeMap(MrMapFunction<K,V> mapFunction)
mapFunction
- map-function used for this treepublic MrTreeMap(V root, MrMapFunction<K,V> mapFunction)
root
- root element of treemapFunction
- map-function used for this treepublic int getTraversalMode()
public void setTraversalMode(int traversalMode)
traversalMode
- public MrMapFunction<K,V> getMapFunction()
public V getRoot()
public V findByKey(K key)
key
- object key, this is the result of tree's map-functionpublic boolean containsKey(K key)
key
- public boolean contains(V data)
data
- public void clear()
public java.util.Collection<K> keys()
public int size()
public boolean addChildByKey(K parentKey, V data)
parentKey
- parent node keydata
- data to be used as a childpublic boolean addChild(V parent, V data)
parent
- parent objectdata
- child object to be insertedpublic boolean removeByKey(K key)
key
- of the elementpublic boolean remove(V data)
data
- data object to be removedpublic java.util.List<V> getChildrenOfByKey(K key)
key
- nodepublic V getParentOf(V data)
data
- elementpublic V getParentOfByKey(K key)
key
- key of the elementpublic java.util.List<V> getChildrenOf(V data)
data
- the objectpublic MrTreeMap<K,V> getSubTreeByKey(K key)
key
- key of objectpublic MrTreeMap<K,V> getSubTree(V data)
data
- objectpublic java.util.Iterator<java.util.Map.Entry<K,V>> parentKeyChildValueTraversalByKey(K key)
public java.util.Iterator<java.util.Map.Entry<K,V>> parentKeyChildValueTraversal(V data)
public java.util.Iterator<V> breadthTraversal()
public java.util.Iterator<V> depthTraversal()
public java.util.Iterator<java.util.Map.Entry<K,V>> parentKeyChildValueTraversal()