示例#1
0
  private static void checkAnnotations(Graph<String, String> graph, Annotatable a, Annotatable b) {
    final Annotation A = new Annotation() {};
    final Annotation B = new Annotation() {};

    // Initially null.
    assertNull(a.getAnnotation());
    assertNull(b.getAnnotation());

    // Test basic setting.
    a.setAnnotation(A);
    b.setAnnotation(B);
    assertSame(A, a.getAnnotation());
    assertSame(B, b.getAnnotation());

    // Test clearing.
    graph.clearEdgeAnnotations();
    graph.clearNodeAnnotations();
    assertNull(a.getAnnotation());
    assertNull(b.getAnnotation());

    a.setAnnotation(A);
    b.setAnnotation(B);
    // Pushing clears.
    graph.pushEdgeAnnotations();
    graph.pushNodeAnnotations();
    assertNull(a.getAnnotation());
    assertNull(b.getAnnotation());
    a.setAnnotation(B);
    b.setAnnotation(B);
    graph.pushEdgeAnnotations();
    graph.pushNodeAnnotations();
    a.setAnnotation(B);
    b.setAnnotation(A);

    // Test restoring then restoring old values with pop.
    assertSame(B, a.getAnnotation());
    assertSame(A, b.getAnnotation());
    graph.popEdgeAnnotations();
    graph.popNodeAnnotations();
    assertSame(B, a.getAnnotation());
    assertSame(B, b.getAnnotation());
    graph.popEdgeAnnotations();
    graph.popNodeAnnotations();
    assertSame(A, a.getAnnotation());
    assertSame(B, b.getAnnotation());
  }