Search in sources :

Example 6 with ConsoleGraphChangedListener

use of com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener in project blueprints by tinkerpop.

the class EventGraphTest method testManageListeners.

public void testManageListeners() {
    EventGraph graph = this.graph;
    ConsoleGraphChangedListener listener1 = new ConsoleGraphChangedListener(graph);
    ConsoleGraphChangedListener listener2 = new ConsoleGraphChangedListener(graph);
    graph.addListener(listener1);
    graph.addListener(listener2);
    Iterator<GraphChangedListener> itty = graph.getListenerIterator();
    int counter = 0;
    while (itty.hasNext()) {
        itty.next();
        counter++;
    }
    assertEquals(2, counter);
    graph.removeListener(listener2);
    itty = graph.getListenerIterator();
    counter = 0;
    while (itty.hasNext()) {
        itty.next();
        counter++;
    }
    assertEquals(1, counter);
    graph.removeAllListeners();
    itty = graph.getListenerIterator();
    counter = 0;
    while (itty.hasNext()) {
        itty.next();
        counter++;
    }
    assertEquals(0, counter);
}
Also used : StubGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.StubGraphChangedListener) ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener) GraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.GraphChangedListener) ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener)

Example 7 with ConsoleGraphChangedListener

use of com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener in project blueprints by tinkerpop.

the class EventGraphTest method testWrappedElementUniqueness.

public void testWrappedElementUniqueness() {
    graph.addListener(new ConsoleGraphChangedListener(graph));
    assertEquals(graph.getVertex(1), graph.getVertex(1));
    Set<Vertex> set = new HashSet<Vertex>();
    set.add(graph.getVertex(2));
    set.add(graph.getVertex(2));
    assertEquals(set.size(), 1);
    assertEquals(graph.getEdge(7).hashCode(), graph.getEdge(7).hashCode());
    assertEquals(graph.getEdge(8), graph.getEdge(8));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener) HashSet(java.util.HashSet)

Example 8 with ConsoleGraphChangedListener

use of com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener in project blueprints by tinkerpop.

the class EventTransactionalGraphTest method testManageListeners.

public void testManageListeners() {
    EventGraph graph = this.graph;
    ConsoleGraphChangedListener listener1 = new ConsoleGraphChangedListener(graph);
    ConsoleGraphChangedListener listener2 = new ConsoleGraphChangedListener(graph);
    graph.addListener(listener1);
    graph.addListener(listener2);
    Iterator<GraphChangedListener> itty = graph.getListenerIterator();
    int counter = 0;
    while (itty.hasNext()) {
        itty.next();
        counter++;
    }
    assertEquals(2, counter);
    graph.removeListener(listener2);
    itty = graph.getListenerIterator();
    counter = 0;
    while (itty.hasNext()) {
        itty.next();
        counter++;
    }
    assertEquals(1, counter);
    graph.removeAllListeners();
    itty = graph.getListenerIterator();
    counter = 0;
    while (itty.hasNext()) {
        itty.next();
        counter++;
    }
    assertEquals(0, counter);
}
Also used : GraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.GraphChangedListener) StubGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.StubGraphChangedListener) ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener) ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener)

Example 9 with ConsoleGraphChangedListener

use of com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener in project blueprints by tinkerpop.

the class EventTransactionalGraphTest method testEventedGraph.

public void testEventedGraph() {
    graph.addListener(new ConsoleGraphChangedListener(graph));
    assertTrue(graph.getVertices() instanceof EventVertexIterable);
    assertTrue(graph.getEdges() instanceof EventEdgeIterable);
    assertEquals(count(graph.getVertices()), 6);
    assertEquals(count(graph.getEdges()), 6);
    graph.removeVertex(graph.getVertex(1));
    assertNull(graph.getVertex(1));
    graph.removeEdge(graph.getEdge(10));
    assertNull(graph.getEdge(10));
    graph.shutdown();
}
Also used : ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener)

Aggregations

ConsoleGraphChangedListener (com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener)9 Vertex (com.tinkerpop.blueprints.Vertex)5 Edge (com.tinkerpop.blueprints.Edge)3 GraphChangedListener (com.tinkerpop.blueprints.util.wrappers.event.listener.GraphChangedListener)2 StubGraphChangedListener (com.tinkerpop.blueprints.util.wrappers.event.listener.StubGraphChangedListener)2 HashSet (java.util.HashSet)2