Generic tree implementation in Java

后端 未结 10 1278
甜味超标
甜味超标 2020-12-28 12:29

Is anyone aware of a generic tree (nodes may have multiple children) implementation for Java? It should come from a well trusted source and must be fully tested.

10条回答
  •  自闭症患者
    2020-12-28 13:20

    Use Guava

    Guava 15.0 introduces a nice API for tree traversal so you don't need to re-implement it for the gazillionth time in your codebase.

    Namely, TreeTraverser and some specialized implementations, like BinaryTreeTraverser.

    A very much welcome addition to avoid re-implementing something so simple and with added bonus:

    • with peace of mind (stability, supported library, etc...),
    • good design,
    • several traversal modes built-in.

    While You're There...

    Notice that Guava also provides now new methods to its Files utility class that make use of the TreeTraverser, e.g. Files.fileTreeTraverser() which gives you a TreeTraverser for your file-system traversal needs.

提交回复
热议问题