Esempio n. 1
0
 public static void clearCached() {
   DynamicArray<String> keys = DynamicArray.create();
   synchronized (cachedSet) {
     AddToLastAll.add(keys, cachedSet);
     cachedSet.clear();
   }
   for (String k : keys) Cache.remove(k);
 }
Esempio n. 2
0
  @Test
  public void testTraverse() {
    String[][] data = {{"A", "B"}, {"B", "C"}, {"A", "C"}, {"B", "D"}};
    Graph<String, DirectedEdge<String>> g = TestGraphFactory.createDirectedNew(data);
    final DynamicArray<String> log = DynamicArray.create();
    BFS.traverse(
        g,
        VarargsIterable.create("A"),
        new BFSVisitor<String, DirectedEdge<String>>() {
          @Override
          public void onDiscover(String vertex, int depth, VisitorStopper stopper) {
            log.addToLast(vertex + "(" + depth + ")");
          }

          @Override
          public void onWalk(DirectedEdge<String> e) {
            log.addToLast(e.toString());
          }
        });
    assertEquals("(A(0),A->B,B(1),A->C,C(1),B->D,D(2))", log.toString());
  }
Esempio n. 3
0
public class Polygon2D<T> implements EqualityTester<Polygon2D<T>> {

  public static <T> Polygon2D<T> create(Iterable<Point2D<T>> src) {
    return new Polygon2D<T>(src);
  }

  private final DynamicArray<Point2D<T>> points = DynamicArray.create();

  private Polygon2D(Iterable<Point2D<T>> src) {
    AddToLastAll.add(points, src);
  }

  public boolean equals(Object obj) {
    return StrictEqualityTester.areEqual(this, obj, this);
  }

  @Override
  public boolean areEqual(Polygon2D<T> o1, Polygon2D<T> o2) {
    return o1.points.equals(o2.points);
  }

  @Override
  public int hashCode() {
    return points.hashCode();
  }

  public int pointNumber() {
    return points.size();
  }

  public Point2D<T> get(int index) {
    return points.get(index);
  }

  public int size() {
    return points.size();
  }

  @Override
  public String toString() {
    return "Polygon" + points;
  }
}