Package org.mapsforge.poi.storage
Class DoubleLinkedPoiCategory
- java.lang.Object
-
- org.mapsforge.poi.storage.DoubleLinkedPoiCategory
-
- All Implemented Interfaces:
PoiCategory
public class DoubleLinkedPoiCategory extends java.lang.Object implements PoiCategory
A POI category representation that stores a node, its parent node and its child nodes.
-
-
Constructor Summary
Constructors Constructor Description DoubleLinkedPoiCategory(java.lang.String title, PoiCategory parent)Creates a new category without knowing its position in the final category tree.DoubleLinkedPoiCategory(java.lang.String title, PoiCategory parent, int id)Creates a new category.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static intcalculateCategoryIDs(DoubleLinkedPoiCategory rootNode, int maxValue)This method calculates a unique ID for all nodes in the tree.java.util.Collection<PoiCategory>deepChildren()java.util.Collection<PoiCategory>getChildren()static java.lang.StringgetGraphVizString(DoubleLinkedPoiCategory rootNode)Generates a GraphViz source representation as a tree having the current node as its root.intgetID()Make sure you callcalculateCategoryIDs(DoubleLinkedPoiCategory, int)first.PoiCategorygetParent()java.lang.StringgetTitle()voidsetParent(PoiCategory parent)Sets the category's parent category.java.lang.StringtoString()
-
-
-
Constructor Detail
-
DoubleLinkedPoiCategory
public DoubleLinkedPoiCategory(java.lang.String title, PoiCategory parent)Creates a new category without knowing its position in the final category tree. If all categories have been created you have to callcalculateCategoryIDs(DoubleLinkedPoiCategory, int)to assign the IDs.- Parameters:
title- The category's unique title.parent- The category's parent category. For creating a root node, set the parent to null.
-
DoubleLinkedPoiCategory
public DoubleLinkedPoiCategory(java.lang.String title, PoiCategory parent, int id)Creates a new category. This constructor should only be called fromPoiCategoryManagerwhen reading a category configuration from a database or XML file. Otherwise callDoubleLinkedPoiCategory(String, PoiCategory).- Parameters:
title- The category's unique title.parent- The category's parent category. For creating a root node, set the parent to null.id- The category's position in the tree determined by left-order-dfs-traversal.
-
-
Method Detail
-
calculateCategoryIDs
public static int calculateCategoryIDs(DoubleLinkedPoiCategory rootNode, int maxValue)
This method calculates a unique ID for all nodes in the tree. For each node's 'n' ID named 'ID_'n at depth 'd' the following invariants must be true:- ID > max(ID of all child nodes)
- All nodes' IDs left of n must be < ID_n.
- All nodes' IDs right of n must be > ID_n.
- Parameters:
rootNode- The tree's root node. (Any other node will result in invalid IDs!)maxValue- Global maximum ID.- Returns:
- The root node's ID.
-
deepChildren
public java.util.Collection<PoiCategory> deepChildren()
- Specified by:
deepChildrenin interfacePoiCategory- Returns:
- All child categories of the category, including their children.
-
getChildren
public java.util.Collection<PoiCategory> getChildren()
- Specified by:
getChildrenin interfacePoiCategory- Returns:
- All child categories of the category.
-
getGraphVizString
public static java.lang.String getGraphVizString(DoubleLinkedPoiCategory rootNode)
Generates a GraphViz source representation as a tree having the current node as its root.- Parameters:
rootNode- The resulting graph's root node. (You can use any sub node to get a sub-graph).- Returns:
- a GraphViz source representation as a tree having the current node as its root.
-
getID
public int getID()
Make sure you callcalculateCategoryIDs(DoubleLinkedPoiCategory, int)first.- Specified by:
getIDin interfacePoiCategory- Returns:
- The node's ID.
-
getParent
public PoiCategory getParent()
- Specified by:
getParentin interfacePoiCategory- Returns:
- The parent category of this category or null if this category has no parent.
-
getTitle
public java.lang.String getTitle()
- Specified by:
getTitlein interfacePoiCategory- Returns:
- The title of this category.
-
setParent
public void setParent(PoiCategory parent)
Sets the category's parent category.- Specified by:
setParentin interfacePoiCategory- Parameters:
parent- The category to be set as parent.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-