我露出一个枚举作为在序遍历树结构(迭代器使用这些枚举常数来决定如何遍历树)指南:隐藏的枚举常量
/**
* The result type of an {@link IVisitor} implementation.
*
* @author Johannes Lichtenberger, University of Konstanz
*/
public enum EVisitResult {
/** Continue without visiting the siblings of this node. */
SKIPSIBLINGS,
/** Continue without visiting the descendants of this node. */
SKIPSUBTREE,
/** Continue traversal. */
CONTINUE,
/** Terminate traversal. */
TERMINATE,
/** Pop from the right sibling stack. */
SKIPSUBTREEPOPSTACK
}
但是最后枚举常量仅用于内部访问者,不应该从使用公共API的用户使用。任何想法如何我可以隐藏“SKIPSUBTREEPOPSTACK”?
彼得的答案很可能是做的最简单的方法这个。但我的第一本能是看看是否有方法来重构代码,以避免需要私有枚举值。 – Alex
那时候我真的想过添加常量,但它是迭代器/迭代器在删除子树时工作的唯一方法(并且可能在删除后还可能合并相邻的TextNode)。 – Johannes