我露出一個枚舉作爲在序遍歷樹結構(迭代器使用這些枚舉常數來決定如何遍歷樹)指南:隱藏的枚舉常量
/**
* 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