This project provides a Java library for filtering a hierarchical structure of nodes based on a given predicate. It includes the Hierarchy
interface for representing hierarchical data, the Filter
class for node filtering, and a set of test cases.
-
Read and understand the Hierarchy data structure Provided code here.
-
Implement filter() function
-
Implement more test cases
-
Filter a hierarchical structure of nodes based on a given predicate.
-
Support for representing hierarchical data with the Hierarchy interface.
-
Includes test cases to ensure the correctness of the filtering.
To filter a hierarchy of nodes, you can use the Filter.filter method, providing a Hierarchy and a predicate. Here's an example of how to use it:
Hierarchy unfiltered = new ArrayBasedHierarchy(/* Node and depth data here */);
Hierarchy filtered = Filter.filter(unfiltered, nodeId -> nodeId % 2 == 0);
To run the test cases for the Hierarchy Filtering library, you can use your favorite Java testing framework. We've provided a sample set of test cases in the FilterTest class.