{"id":17987786,"url":"https://github.com/dirkluijk/tree-api","last_synced_at":"2025-04-04T03:23:40.965Z","repository":{"id":30976587,"uuid":"34534836","full_name":"dirkluijk/tree-api","owner":"dirkluijk","description":"A small Tree library for Java","archived":false,"fork":false,"pushed_at":"2015-05-18T09:52:03.000Z","size":266,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-09T15:11:35.807Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dirkluijk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-24T18:27:59.000Z","updated_at":"2015-04-25T08:10:58.000Z","dependencies_parsed_at":"2022-09-09T01:54:19.228Z","dependency_job_id":null,"html_url":"https://github.com/dirkluijk/tree-api","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkluijk%2Ftree-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkluijk%2Ftree-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkluijk%2Ftree-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkluijk%2Ftree-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dirkluijk","download_url":"https://codeload.github.com/dirkluijk/tree-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247114223,"owners_count":20885897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-29T19:09:39.186Z","updated_at":"2025-04-04T03:23:40.945Z","avatar_url":"https://github.com/dirkluijk.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tree API\n\nA small Java library for creating tree structures.\n\n[![Build Status](https://travis-ci.org/dirkluijk/tree-api.svg?branch=master)](https://travis-ci.org/dirkluijk/tree-api) \n[![Coverage Status](https://coveralls.io/repos/dirkluijk/tree-api/badge.svg?branch=master)](https://coveralls.io/r/dirkluijk/tree-api?branch=master)\n\n## API Documentation\nFind the JavaDoc documentation at http://dirkluijk.github.io/tree-api/.\n\n## Features\n\n* A generic ``Node`` interface with a ``AbstractNode`` and a ``NameNode`` sample implementation\n* A ``Tree`` helper to store the nodes in and search for descendants\n* A ``TreeIterator`` to iterate over a tree\n* A ``NodeComparator`` to compare nodes and maintain the tree-based ordering inside a ``Tree``\n\n## How to use\n\nCreating your custom node:\n\n```java\nclass Employee implements Node\u003cEmployee\u003e {\n\n    private Employee manager;\n    private String name;\n    private int salary;\n\n    public Employee(String name) {\n        this(name, null);\n    }\n\n    public Employee(String name, Employee manager) {\n        this.name = name;\n        this.manager = manager;\n    }\n\n    @Override\n    public Employee getParent() {\n        return manager;\n    }\n\n    @Override\n    public void setParent(Employee parent) {\n        this.manager = parent;\n    }\n\n    @Override\n    public boolean isLeaf() {\n        return false;\n    }\n    \n    @Override\n    public String toString() {\n        return this.name;\n    }\n}\n```\n\nCreating nodes:\n\n```java\nEmployee dave = new Employee(\"Dave\");\nEmployee john = new Employee(\"John\", dave);\nEmployee charles = new Employee(\"Charles\", dave);\n```\n\nStoring nodes in a tree, e.g. using the included ``NodeTree``:\n\n```java\nTree\u003cEmployee\u003e employees = new NodeTree\u003c\u003e();\n\nemployees.add(john);\nemployees.add(dave);\nemployees.add(charles);\n```\n\nThe tree will be ordered automatically, using the parent-child structure. Siblings are ordered alphabetically by default (based on the ``toString`` implementation):\n\n* Dave\n* Charles\n* John\n\nThe tree provides some interesting features:\n\n```java\n// will return a new tree containing only john and charles\nemployees.descendantsOf(dave);\t\n\nemployees.descendantsCount(dave); // 2\nemployees.descendantsCount(charles); // 0\n\n```\n\nThere is also a special ``TreeIterator`` available:\n\n```java\nTreeIterator it = employees.iterator();\nwhile(it.hasNext() {\n\tEmployee current = it.next();\n\t\n\tit.level(); // the level of the current node\n\tit.path();  // the path, e.g. \"/dave/charles\"\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirkluijk%2Ftree-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdirkluijk%2Ftree-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirkluijk%2Ftree-api/lists"}