0

ツリー構造を優先順序でトラバースするためのガイドとして列挙を公開しています (イテレータはこれらの列挙型定数を使用して、ツリーをトラバースする方法を決定します)。

/**
 * 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」を非表示にする方法はありますか?

4

2 に答える 2

3

あなたができることは、それが使用されるべきではないことを文書化することだけです.

別の方法は、インターフェイスを使用することです

public interface EVisitResult {
}

public enum PublicEVisitResult implements 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,
}

enum LocalEVisitResult implements EVisitResult {
  /** Pop from the right sibling stack. */
  SKIPSUBTREEPOPSTACK
}
于 2012-10-01T17:12:27.260 に答える
1

パブリック API と内部実装の両方に列挙型が必要な場合は、2 つの列挙型を持つことができます

private enum InternalFoo
    foo1
    foo2
    foox

private void doFoo(InternalFoo foo)
    switch(foo)
        case foo1
        ...


-----


public enum Foo
    foo1(InternalFoo.foo1)
    foo2(InternalFoo.foo2)
    // no foox

    InternalFoo internal;
    Foo(InternalFoo internal){ this.internal=internal; }

public void doFoo(Foo foo)
    doFoo(foo.internal);
于 2012-10-01T17:44:49.920 に答える