Skip to content

Commit

Permalink
add set support in java gremlin lang
Browse files Browse the repository at this point in the history
  • Loading branch information
xiazcy committed Aug 1, 2024
1 parent 418b2d1 commit 7510387
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,8 @@ private String argAsString(final Object arg) {
return asString((Map) arg);
}

// todo: add set handling here when will be implemented in Grammar
if (arg instanceof Set) {
return asParameter(arg);
return asString((Set) arg);
}

// handle all iterables in similar way
Expand Down Expand Up @@ -228,6 +227,20 @@ private String asString(final Iterator itty) {
return sb.append("]").toString();
}

private String asString(final Set<?> set) {
final StringBuilder sb = new StringBuilder().append("{");

final Iterator itty = asIterator(set);

while (itty.hasNext()) {
sb.append(argAsString(itty.next()));
if (itty.hasNext())
sb.append(",");
}

return sb.append("}").toString();
}

// borrowed from Groovy translator
private String asString(final P<?> p) {
final StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static Iterable<Object[]> generateTestParameters() {
"g.withStrategies(new SubgraphStrategy(checkAdjacentVertices:true,vertices:__.has(\"name\",P.within([\"josh\",\"lop\",\"ripple\"])))).V()"},
{g.inject(Parameter.var("x", "x")).V(Parameter.var("ids", new int[]{1, 2, 3})), "g.inject(x).V(ids)"},
{newG().inject(Parameter.value("test1"), Parameter.value("test2")), "g.inject(_0,_1)"},
{newG().inject(new HashSet<>(Arrays.asList(1, 2))), "g.inject(_0)"},
{newG().inject(new HashSet<>(Arrays.asList(1, 2))), "g.inject({1,2})"},
});
}

Expand Down

0 comments on commit 7510387

Please sign in to comment.