diff --git a/java/src/main/java/org/softwareheritage/graph/NodesFiltering.java b/java/src/main/java/org/softwareheritage/graph/NodesFiltering.java --- a/java/src/main/java/org/softwareheritage/graph/NodesFiltering.java +++ b/java/src/main/java/org/softwareheritage/graph/NodesFiltering.java @@ -3,19 +3,42 @@ import java.util.ArrayList; /** + *

NodesFiltering

+ *

* class that manages the filtering of nodes that have been returned after a visit of the graph. - * parameterized by a string that represents either no filtering (*) or a set of node types + * parameterized by a string that represents either no filtering (*) or a set of node types. + *

* - * Exemples of query : + * + * + * How to use NodesFiltering : + * + *
+ * {@code
+ *  Long id1 = .... // graph.getNodeType(id1) == CNT
+ *  Long id2 = .... // graph.getNodeType(id2) == SNP
+ *  Long id3 = .... // graph.getNodeType(id3) == ORI
+ *  ArrayList nodeIds = nez ArrayList();
+ *  nodeIds.add(id1); nodeIds.add(id2); nodeIds.add(id3);
+ *
+ *  NodeFiltering nds = new NodesFiltering("snp,ori"); // we allow only snp node types to be shown
+ *  System.out.println(nds.filterByNodeTypes(nodeIds,graph)); // will print id2, id3
+ *
+ *  nds = NodesFiltering("*");
+ *  System.out.println(nds.filterByNodeTypes(nodeIds,graph)); // will print id1, id2 id3
+ *
+ * }
+ * 
*/ public class NodesFiltering { @@ -25,7 +48,7 @@ /** * Default constructor, in order to handle the * case (all types of nodes are allowed to be - * returned) + * returned). allowedNodesTypes will contains [SNP,CNT....] all types of nodes. * */ public NodesFiltering() { @@ -34,6 +57,12 @@ } /** + * Constructor + * + * @param strTypes a formatted string describing the types of nodes we want to allow to be shown. + * + * NodesFilterind("cnt,snp") will set allowedNodesTypes to [CNT,SNP] + * */ public NodesFiltering(String strTypes) { restricted = true; @@ -44,16 +73,27 @@ } } + /** + * Check if the type given in parameter is in the list of allowed types. + * + * @param typ the type of the node. + */ public boolean typeIsAllowed(Node.Type typ) { return this.allowedNodesTypes.contains(typ); } /** + *

* the function that filters the nodes returned, we browse the list of nodes found after a visit and * we create a new list with only the nodes that have a type that is contained in the list of * allowed types (allowedNodesTypes) + *

+ * + * @param nodeIds the nodes founded during the visit + * @param g the graph in order to find the types of nodes from their id in nodeIds + * @return a new list with the id of node which have a type in allowedTypes + * * - * We need the graph in order to find the types of nodes. */ public ArrayList filterByNodeTypes(ArrayList nodeIds, Graph g) { ArrayList filteredNodes = new ArrayList();