Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet#add()

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BulkSetTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldHaveProperHashAndEquality() {
    final BulkSet<String> a = new BulkSet<>();
    final BulkSet<String> b = new BulkSet<>();
    a.add("stephen", 12);
    a.add("marko", 32);
    a.add("daniel", 74);
    b.add("stephen", 12);
    b.add("marko", 32);
    b.add("daniel", 74);
    assertEquals(a, b);
    assertTrue(a.equals(b));
    assertEquals(a.hashCode(), b.hashCode());
    assertTrue(a.hashCode() == b.hashCode());
    assertEquals(12, a.get("stephen"));
    assertEquals(12, b.get("stephen"));
    a.add("matthias", 99);
    assertFalse(a.equals(b));
    assertFalse(a.hashCode() == b.hashCode());
    assertNotEquals(a.hashCode(), b.hashCode());
}
 
Example 2
Source File: BulkSetTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldHaveCorrectBulkCounts() {
    final BulkSet<String> set = new BulkSet<>();
    set.add("marko");
    set.add("matthias");
    set.add("marko", 7);
    set.add("stephen");
    set.add("stephen");
    assertEquals(8, set.get("marko"));
    assertEquals(1, set.get("matthias"));
    assertEquals(2, set.get("stephen"));
    final Iterator<String> iterator = set.iterator();
    for (int i = 0; i < 11; i++) {
        if (i < 8)
            assertEquals("marko", iterator.next());
        else if (i < 9)
            assertEquals("matthias", iterator.next());
        else
            assertEquals("stephen", iterator.next());
    }
    assertEquals(11, set.size());
}
 
Example 3
Source File: AggregateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@LoadGraphWith(MODERN)
public void g_V_hasLabelXpersonX_aggregateXxX_byXageX_capXxX_asXyX_selectXyX() {
    final Traversal<Vertex, Collection<Integer>> traversal = get_g_V_hasLabelXpersonX_aggregateXxX_byXageX_capXxX_asXyX_selectXyX();
    final Collection<Integer> ages = traversal.next();

    // in 3.3.x a BulkSet will coerce to List under GraphSON
    assumeThat(ages instanceof BulkSet, is(true));
    assertEquals(4, ages.size());
    assertTrue(ages.contains(29));
    assertTrue(ages.contains(27));
    assertTrue(ages.contains(32));
    assertTrue(ages.contains(35));
    final BulkSet<Integer> bulkSet = new BulkSet<>();
    bulkSet.add(29);
    bulkSet.add(27);
    bulkSet.add(32);
    bulkSet.add(35);
    assertEquals(bulkSet, ages); // ensure bulk set equality
    assertFalse(traversal.hasNext());
}
 
Example 4
Source File: ObjectQueryTest.java    From gremlin-ogm with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("cast")
public void testQueryByAnyTraversal() {
  when(traversal.hasLabel(anyString())).thenReturn(traversal);
  when(traversal.has(anyString(), (Object) any())).thenReturn(traversal);
  BulkSet<Vertex> bulkSet = BulkSetSupplier.<Vertex>instance().get();
  bulkSet.add(vertex);
  when(traversal.toBulkSet()).thenReturn(bulkSet);

  Person actual = query
      .by(g -> g.V().hasLabel(marko.label()).has("name", marko.name()))
      .one(Person.class);

  assertEquals(marko, actual);
}
 
Example 5
Source File: ObjectQueryTest.java    From gremlin-ogm with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("cast")
public void testQueryBySubTraversals() {
  when(traversal.hasLabel(anyString())).thenReturn(traversal);
  when(traversal.has(anyString(), (Object) any())).thenReturn(traversal);
  BulkSet<Vertex> bulkSet = BulkSetSupplier.<Vertex>instance().get();
  bulkSet.add(vertex);
  when(traversal.toBulkSet()).thenReturn(bulkSet);

  List<Person> actuals = query
      .by(HasKeys.of(marko, PrimaryKey.class))
      .list(Person.class);

  assertEquals(Arrays.asList(marko), actuals);
}
 
Example 6
Source File: TypeSerializerFailureTests.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Parameterized.Parameters(name = "Value={0}")
public static Collection input() {
    final Bytecode.Binding b = new Bytecode.Binding(null, "b");

    final ReferenceVertex vertex = new ReferenceVertex("a vertex", null);

    final Bytecode bytecode = new Bytecode();
    bytecode.addStep(null);

    final BulkSet<Object> bulkSet = new BulkSet<>();
    bulkSet.add(vertex, 1L);

    final MutableMetrics metrics = new MutableMetrics("a metric", null);

    final Tree<Vertex> tree = new Tree<>();
    tree.put(vertex, null);

    // Provide instances that are malformed for serialization to fail
    return Arrays.asList(
            b,
            vertex,
            Collections.singletonMap("one", b),
            bulkSet,
            bytecode,
            Collections.singletonList(vertex),
            new ReferenceEdge("an edge", null, vertex, vertex),
            Lambda.supplier(null),
            metrics,
            new DefaultTraversalMetrics(1L, Collections.singletonList(metrics)),
            new DefaultRemoteTraverser<>(new Object(), 1L),
            tree,
            new ReferenceVertexProperty<>("a prop", null, "value"),
            new InvalidPath()
    );
}
 
Example 7
Source File: TraversalSerializersV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public BulkSet deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {

    final BulkSet<Object> bulkSet = new BulkSet<>();

    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
        final Object key = deserializationContext.readValue(jsonParser, Object.class);
        jsonParser.nextToken();
        final Long val = deserializationContext.readValue(jsonParser, Long.class);
        bulkSet.add(key, val);
    }

    return bulkSet;
}
 
Example 8
Source File: BulkSetSerializer.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
protected BulkSet readValue(final Buffer buffer, final GraphBinaryReader context) throws IOException {
    final int length = buffer.readInt();

    final BulkSet result = new BulkSet();
    for (int i = 0; i < length; i++) {
        result.add(context.read(buffer), buffer.readLong());
    }

    return result;
}
 
Example 9
Source File: AggregateGlobalStep.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void processAllStarts() {
    if (this.starts.hasNext()) {
        final BulkSet<Object> bulkSet = new BulkSet<>();
        while (this.starts.hasNext()) {
            final Traverser.Admin<S> traverser = this.starts.next();
            bulkSet.add(TraversalUtil.applyNullable(traverser, this.aggregateTraversal), traverser.bulk());
            traverser.setStepId(this.getNextStep().getId()); // when barrier is reloaded, the traversers should be at the next step
            this.barrier.add(traverser);
        }
        this.getTraversal().getSideEffects().add(this.sideEffectKey, bulkSet);
    }
}
 
Example 10
Source File: GraphSONMapperEmbeddedTypeTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHandleBulkSet() throws Exception {
    // only supported on V3
    assumeThat(version, not(anyOf(startsWith("v1"), startsWith("v2"))));

    final BulkSet<String> bs = new BulkSet<>();
    bs.add("test1", 1);
    bs.add("test2", 2);
    bs.add("test3", 3);

    assertEquals(bs, serializeDeserialize(mapper, bs, BulkSet.class));
}
 
Example 11
Source File: ProgramTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(MODERN)
public void g_V_outXcreatedX_aggregateXxX_byXlangX_groupCount_programXTestProgramX_asXaX_selectXa_xX() {
    final Traversal<Vertex, Map<String, Object>> traversal = get_g_V_outXcreatedX_aggregateXxX_byXlangX_groupCount_programXTestProgramX_asXaX_selectXa_xX();
    final List<Map<String, Object>> results = traversal.toList();
    assertFalse(traversal.hasNext());
    assertEquals(6, results.size());
    final BulkSet<String> bulkSet = new BulkSet<>();
    bulkSet.add("java", 4);
    for (int i = 0; i < 4; i++) {
        assertEquals(bulkSet, results.get(i).get("x"));
    }
    final Set<String> strings = new HashSet<>();
    strings.add((String) results.get(0).get("a"));
    strings.add((String) results.get(1).get("a"));
    strings.add((String) results.get(2).get("a"));
    strings.add((String) results.get(3).get("a"));
    strings.add((String) results.get(4).get("a"));
    strings.add((String) results.get(5).get("a"));
    assertEquals(6, strings.size());
    assertTrue(strings.contains("hello"));
    assertTrue(strings.contains("gremlin"));
    assertTrue(strings.contains("lop"));
    assertTrue(strings.contains("ripple"));
    assertTrue(strings.contains("marko-is-my-name"));
    assertTrue(strings.contains("the-v-o-double-g"));
}
 
Example 12
Source File: AggregateLocalStep.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
protected void sideEffect(final Traverser.Admin<S> traverser) {
    final BulkSet<Object> bulkSet = new BulkSet<>();
    bulkSet.add(TraversalUtil.applyNullable(traverser, this.storeTraversal), traverser.bulk());
    this.getTraversal().getSideEffects().add(this.sideEffectKey, bulkSet);
}