本文整理汇总了Java中org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils.list方法的典型用法代码示例。如果您正苦于以下问题:Java IteratorUtils.list方法的具体用法?Java IteratorUtils.list怎么用?Java IteratorUtils.list使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils
的用法示例。
在下文中一共展示了IteratorUtils.list方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldSerializeEdgeProperty
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Test
public void shouldSerializeEdgeProperty() throws Exception {
final Graph g = TinkerGraph.open();
final Vertex v1 = g.addVertex();
final Vertex v2 = g.addVertex();
final Edge e = v1.addEdge("test", v2);
e.property("abc", 123);
final Iterable<Property<Object>> iterable = IteratorUtils.list(e.properties("abc"));
final String results = SERIALIZER.serializeResponseAsString(ResponseMessage.build(msg).result(iterable).create());
final JsonNode json = mapper.readTree(results);
assertNotNull(json);
assertEquals(msg.getRequestId().toString(), json.get(SerTokens.TOKEN_REQUEST).asText());
final JsonNode converted = json.get(SerTokens.TOKEN_RESULT).get(SerTokens.TOKEN_DATA);
assertNotNull(converted);
assertEquals(1, converted.size());
final JsonNode propertyAsJson = converted.get(0);
assertNotNull(propertyAsJson);
assertEquals(123, propertyAsJson.get("value").asInt());
}
示例2: shouldSerializeEdgeProperty
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Test
public void shouldSerializeEdgeProperty() throws Exception {
final Graph graph = TinkerGraph.open();
final Vertex v1 = graph.addVertex();
final Vertex v2 = graph.addVertex();
final Edge e = v1.addEdge("test", v2);
e.property("abc", 123);
final Iterable<Property<Object>> iterable = IteratorUtils.list(e.properties("abc"));
final ResponseMessage response = convert(iterable);
assertCommon(response);
final List<Map<String, Object>> propertyList = (List<Map<String, Object>>) response.getResult().getData();
assertEquals(1, propertyList.size());
assertEquals(123, propertyList.get(0).get("value"));
}
示例3: shouldSerializeEdge
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Test
public void shouldSerializeEdge() throws Exception {
final Graph g = TinkerGraph.open();
final Vertex v1 = g.addVertex();
final Vertex v2 = g.addVertex();
final Edge e = v1.addEdge("test", v2);
e.property("abc", 123);
final Iterable<Edge> iterable = IteratorUtils.list(g.edges());
final ResponseMessage response = convertBinary(iterable);
assertCommon(response);
final List<ReferenceEdge> edgeList = (List<ReferenceEdge>) response.getResult().getData();
assertEquals(1, edgeList.size());
final ReferenceEdge deserializedEdge = edgeList.get(0);
assertEquals(e.id(), deserializedEdge.id());
assertEquals("test", deserializedEdge.label());
assertEquals(0, IteratorUtils.count(deserializedEdge.properties()));
assertEquals(v1.id(), deserializedEdge.outVertex().id());
assertEquals("", deserializedEdge.outVertex().label());
assertEquals(v2.id(), deserializedEdge.inVertex().id());
assertEquals("", deserializedEdge.inVertex().label());
}
示例4: readGraphRDD
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Override
public JavaPairRDD<Object, VertexWritable> readGraphRDD(final Configuration configuration, final JavaSparkContext sparkContext) {
KryoShimServiceLoader.applyConfiguration(TinkerGraph.open().configuration());
final List<VertexWritable> vertices;
if (configuration.getString(Constants.GREMLIN_HADOOP_INPUT_LOCATION).contains("modern"))
vertices = IteratorUtils.list(IteratorUtils.map(TinkerFactory.createModern().vertices(), VertexWritable::new));
else if (configuration.getString(Constants.GREMLIN_HADOOP_INPUT_LOCATION).contains("classic"))
vertices = IteratorUtils.list(IteratorUtils.map(TinkerFactory.createClassic().vertices(), VertexWritable::new));
else if (configuration.getString(Constants.GREMLIN_HADOOP_INPUT_LOCATION).contains("crew"))
vertices = IteratorUtils.list(IteratorUtils.map(TinkerFactory.createTheCrew().vertices(), VertexWritable::new));
else if (configuration.getString(Constants.GREMLIN_HADOOP_INPUT_LOCATION).contains("grateful")) {
try {
final Graph graph = TinkerGraph.open();
final GraphReader reader = GryoReader.build().mapper(graph.io(GryoIo.build()).mapper().create()).create();
try (final InputStream stream = GryoResourceAccess.class.getResourceAsStream("grateful-dead.kryo")) {
reader.readGraph(stream, graph);
}
vertices = IteratorUtils.list(IteratorUtils.map(graph.vertices(), VertexWritable::new));
} catch (final IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
} else
throw new IllegalArgumentException("No legal toy graph was provided to load: " + configuration.getProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION));
return sparkContext.parallelize(vertices).mapToPair(vertex -> new Tuple2<>(vertex.get().id(), vertex));
}
示例5: g_withSideEffectXx__g_V_toListX_addOutEXexistsWith_x_time_nowX
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Test
@Ignore
@LoadGraphWith(MODERN)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
public void g_withSideEffectXx__g_V_toListX_addOutEXexistsWith_x_time_nowX() {
final Traversal<Vertex, Edge> traversal = get_g_withSideEffectXx__g_V_toListX_addOutEXexistsWith_x_time_nowX();
printTraversalForm(traversal);
int count = 0;
while (traversal.hasNext()) {
final Edge edge = traversal.next();
assertEquals("existsWith", edge.label());
assertEquals("now", edge.value("time"));
assertEquals(1, IteratorUtils.count(edge.properties()));
count++;
}
assertEquals(36, count);
assertEquals(42, IteratorUtils.count(g.E()));
for (final Vertex vertex : IteratorUtils.list(g.V())) {
assertEquals(6, IteratorUtils.count(vertex.edges(Direction.OUT, "existsWith")));
assertEquals(6, IteratorUtils.count(vertex.edges(Direction.IN, "existsWith")));
}
assertEquals(6, IteratorUtils.count(g.V()));
}
示例6: shouldTraverseInOutFromVertexWithMultipleEdgeLabelFilter
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Test
public void shouldTraverseInOutFromVertexWithMultipleEdgeLabelFilter() {
final Vertex a = graph.addVertex();
final Vertex b = graph.addVertex();
final Vertex c = graph.addVertex();
final String labelFriend = graphProvider.convertLabel("friend");
final String labelHate = graphProvider.convertLabel("hate");
final Edge aFriendB = a.addEdge(labelFriend, b);
final Edge aFriendC = a.addEdge(labelFriend, c);
final Edge aHateC = a.addEdge(labelHate, c);
final Edge cHateA = c.addEdge(labelHate, a);
final Edge cHateB = c.addEdge(labelHate, b);
List<Edge> results = IteratorUtils.list(a.edges(Direction.OUT, labelFriend, labelHate));
assertEquals(3, results.size());
assertTrue(results.contains(aFriendB));
assertTrue(results.contains(aFriendC));
assertTrue(results.contains(aHateC));
results = IteratorUtils.list(a.edges(Direction.IN, labelFriend, labelHate));
assertEquals(1, results.size());
assertTrue(results.contains(cHateA));
results = IteratorUtils.list(b.edges(Direction.IN, labelFriend, labelHate));
assertEquals(2, results.size());
assertTrue(results.contains(aFriendB));
assertTrue(results.contains(cHateB));
results = IteratorUtils.list(b.edges(Direction.IN, graphProvider.convertLabel("blah1"), graphProvider.convertLabel("blah2")));
assertEquals(0, results.size());
}
示例7: shouldSerializeEdge
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Test
public void shouldSerializeEdge() throws Exception {
final Graph g = TinkerGraph.open();
final Vertex v1 = g.addVertex();
final Vertex v2 = g.addVertex();
final Edge e = v1.addEdge("test", v2);
e.property("abc", 123);
final Iterable<Edge> iterable = IteratorUtils.list(g.edges());
final String results = SERIALIZER.serializeResponseAsString(ResponseMessage.build(msg).result(iterable).create());
final JsonNode json = mapper.readTree(results);
assertNotNull(json);
assertEquals(msg.getRequestId().toString(), json.get(SerTokens.TOKEN_REQUEST).asText());
final JsonNode converted = json.get(SerTokens.TOKEN_RESULT).get(SerTokens.TOKEN_DATA);
assertNotNull(converted);
assertEquals(1, converted.size());
final JsonNode edgeAsJson = converted.get(0);
assertNotNull(edgeAsJson);
assertEquals(((Long) e.id()).intValue(), edgeAsJson.get(GraphSONTokens.ID).asLong()); // lossy
assertEquals(((Long) v1.id()).intValue(), edgeAsJson.get(GraphSONTokens.OUT).asLong());// lossy
assertEquals(((Long) v2.id()).intValue(), edgeAsJson.get(GraphSONTokens.IN).asLong()); // lossy
assertEquals(e.label(), edgeAsJson.get(GraphSONTokens.LABEL).asText());
assertEquals(GraphSONTokens.EDGE, edgeAsJson.get(GraphSONTokens.TYPE).asText());
final JsonNode properties = edgeAsJson.get(GraphSONTokens.PROPERTIES);
assertNotNull(properties);
assertEquals(123, properties.get("abc").asInt());
}
示例8: shouldSerializeEdge
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Test
public void shouldSerializeEdge() throws Exception {
final Graph graph = TinkerGraph.open();
final Vertex v1 = graph.addVertex();
final Vertex v2 = graph.addVertex();
final Edge e = v1.addEdge("test", v2);
e.property("abc", 123);
final Iterable<Edge> iterable = IteratorUtils.list(graph.edges());
final ResponseMessage response = convert(iterable);
assertCommon(response);
final List<Map<String, Object>> edgeList = (List<Map<String, Object>>) response.getResult().getData();
assertEquals(1, edgeList.size());
final Map<String, Object> deserializedEdge = edgeList.get(0);
assertEquals(e.id(), deserializedEdge.get(GraphSONTokens.ID));
assertEquals(v1.id(), deserializedEdge.get(GraphSONTokens.OUT));
assertEquals(v2.id(), deserializedEdge.get(GraphSONTokens.IN));
assertEquals(v1.label(), deserializedEdge.get(GraphSONTokens.OUT_LABEL));
assertEquals(v2.label(), deserializedEdge.get(GraphSONTokens.IN_LABEL));
assertEquals(e.label(), deserializedEdge.get(GraphSONTokens.LABEL));
assertEquals(GraphSONTokens.EDGE, deserializedEdge.get(GraphSONTokens.TYPE));
final Map<String, Object> properties = (Map<String, Object>) deserializedEdge.get(GraphSONTokens.PROPERTIES);
assertNotNull(properties);
assertEquals(123, properties.get("abc"));
}
示例9: shouldSerializeVertexWithEmbeddedMap
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Test
public void shouldSerializeVertexWithEmbeddedMap() throws Exception {
final Graph g = TinkerGraph.open();
final Vertex v = g.addVertex();
final Map<String, Object> map = new HashMap<>();
map.put("x", 500);
map.put("y", "some");
final ArrayList<Object> friends = new ArrayList<>();
friends.add("x");
friends.add(5);
friends.add(map);
v.property(VertexProperty.Cardinality.single, "friends", friends);
final List list = IteratorUtils.list(g.vertices());
final ResponseMessage response = convertBinary(list);
assertCommon(response);
final List<ReferenceVertex> vertexList = (List<ReferenceVertex>) response.getResult().getData();
assertEquals(1, vertexList.size());
final ReferenceVertex deserializedVertex = vertexList.get(0);
assertEquals(0L, deserializedVertex.id());
assertEquals("", deserializedVertex.label());
assertEquals(0, IteratorUtils.count(deserializedVertex.properties()));
}
示例10: shouldSerializeEdge
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Test
public void shouldSerializeEdge() throws Exception {
final Graph g = TinkerGraph.open();
final Vertex v1 = g.addVertex();
final Vertex v2 = g.addVertex();
final Edge e = v1.addEdge("test", v2);
e.property("abc", 123);
final Iterable<Edge> iterable = IteratorUtils.list(g.edges());
final ResponseMessage response = convertBinary(iterable);
assertCommon(response);
final List<DetachedEdge> edgeList = (List<DetachedEdge>) response.getResult().getData();
assertEquals(1, edgeList.size());
final DetachedEdge deserializedEdge = edgeList.get(0);
assertEquals(e.id(), deserializedEdge.id());
assertEquals("test", deserializedEdge.label());
assertEquals(123, deserializedEdge.values("abc").next());
assertEquals(1, IteratorUtils.count(deserializedEdge.properties()));
assertEquals(v1.id(), deserializedEdge.outVertex().id());
assertEquals(Vertex.DEFAULT_LABEL, deserializedEdge.outVertex().label());
assertEquals(v2.id(), deserializedEdge.inVertex().id());
assertEquals(Vertex.DEFAULT_LABEL, deserializedEdge.inVertex().label());
}
示例11: shouldSerializeVertexWithEmbeddedMap
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Test
public void shouldSerializeVertexWithEmbeddedMap() throws Exception {
final Graph g = TinkerGraph.open();
final Vertex v = g.addVertex();
final Map<String, Object> map = new HashMap<>();
map.put("x", 500);
map.put("y", "some");
final ArrayList<Object> friends = new ArrayList<>();
friends.add("x");
friends.add(5);
friends.add(map);
v.property(VertexProperty.Cardinality.single, "friends", friends);
final List list = IteratorUtils.list(g.vertices());
final ResponseMessage response = convertBinary(list);
assertCommon(response);
final List<DetachedVertex> vertexList = (List<DetachedVertex>) response.getResult().getData();
assertEquals(1, vertexList.size());
final DetachedVertex deserializedVertex = vertexList.get(0);
assertEquals(0l, deserializedVertex.id());
assertEquals(Vertex.DEFAULT_LABEL, deserializedVertex.label());
assertEquals(1, IteratorUtils.count(deserializedVertex.properties()));
final List<Object> deserializedInnerList = (List<Object>) deserializedVertex.values("friends").next();
assertEquals(3, deserializedInnerList.size());
assertEquals("x", deserializedInnerList.get(0));
assertEquals(5, deserializedInnerList.get(1));
final Map<String, Object> deserializedInnerInnerMap = (Map<String, Object>) deserializedInnerList.get(2);
assertEquals(2, deserializedInnerInnerMap.size());
assertEquals(500, deserializedInnerInnerMap.get("x"));
assertEquals("some", deserializedInnerInnerMap.get("y"));
}
示例12: writeProperties
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
private void writeProperties(final Vertex vertex, final JsonGenerator jsonGenerator,
final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException {
jsonGenerator.writeObjectFieldStart(GraphSONTokens.PROPERTIES);
if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());
final List<String> keys = normalize ?
IteratorUtils.list(vertex.keys().iterator(), Comparator.naturalOrder()) : new ArrayList<>(vertex.keys());
for (String key : keys) {
final Iterator<VertexProperty<Object>> vertexProperties = normalize ?
IteratorUtils.list(vertex.properties(key), Comparators.PROPERTY_COMPARATOR).iterator() : vertex.properties(key);
if (vertexProperties.hasNext()) {
jsonGenerator.writeArrayFieldStart(key);
if (typeSerializer != null) {
jsonGenerator.writeString(ArrayList.class.getName());
jsonGenerator.writeStartArray();
}
while (vertexProperties.hasNext()) {
serializerVertexProperty(vertexProperties.next(), jsonGenerator, serializerProvider, typeSerializer, normalize, false);
}
jsonGenerator.writeEndArray();
if (typeSerializer != null) jsonGenerator.writeEndArray();
}
}
jsonGenerator.writeEndObject();
}
示例13: Builder
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
private Builder(final Graph g) {
super(Builder.class);
this.g = g;
final List<Vertex> allVertices = IteratorUtils.list(g.vertices());
this.vertices = allVertices;
this.expectedNumEdges = allVertices.size() * 2;
}
示例14: validateVertexEquality
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
public static void validateVertexEquality(final Vertex originalVertex, final Vertex otherVertex, boolean testEdges) {
assertEquals(originalVertex, otherVertex);
assertEquals(otherVertex, originalVertex);
assertEquals(originalVertex.id(), otherVertex.id());
assertEquals(originalVertex.label(), otherVertex.label());
assertEquals(originalVertex.keys().size(), otherVertex.keys().size());
for (final String key : originalVertex.keys()) {
final List<VertexProperty<Object>> originalVertexProperties = IteratorUtils.list(originalVertex.properties(key));
final List<VertexProperty<Object>> otherVertexProperties = IteratorUtils.list(otherVertex.properties(key));
assertEquals(originalVertexProperties.size(), otherVertexProperties.size());
for (VertexProperty<Object> originalVertexProperty : originalVertexProperties) {
final VertexProperty<Object> otherVertexProperty = otherVertexProperties.parallelStream().filter(vp -> vp.equals(originalVertexProperty)).findAny().get();
validateVertexPropertyEquality(originalVertexProperty, otherVertexProperty);
}
}
if (testEdges) {
Iterator<Edge> originalEdges = IteratorUtils.list(originalVertex.edges(Direction.OUT), Comparators.ELEMENT_COMPARATOR).iterator();
Iterator<Edge> otherEdges = IteratorUtils.list(otherVertex.edges(Direction.OUT), Comparators.ELEMENT_COMPARATOR).iterator();
while (originalEdges.hasNext()) {
validateEdgeEquality(originalEdges.next(), otherEdges.next());
}
assertFalse(otherEdges.hasNext());
originalEdges = IteratorUtils.list(originalVertex.edges(Direction.IN), Comparators.ELEMENT_COMPARATOR).iterator();
otherEdges = IteratorUtils.list(otherVertex.edges(Direction.IN), Comparators.ELEMENT_COMPARATOR).iterator();
while (originalEdges.hasNext()) {
validateEdgeEquality(originalEdges.next(), otherEdges.next());
}
assertFalse(otherEdges.hasNext());
}
}
示例15: shouldTraverseInOutFromVertexWithMultipleEdgeLabelFilter
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldTraverseInOutFromVertexWithMultipleEdgeLabelFilter() {
final Vertex a = graph.addVertex();
final Vertex b = graph.addVertex();
final Vertex c = graph.addVertex();
final String labelFriend = graphProvider.convertLabel("friend");
final String labelHate = graphProvider.convertLabel("hate");
final Edge aFriendB = a.addEdge(labelFriend, b);
final Edge aFriendC = a.addEdge(labelFriend, c);
final Edge aHateC = a.addEdge(labelHate, c);
final Edge cHateA = c.addEdge(labelHate, a);
final Edge cHateB = c.addEdge(labelHate, b);
List<Edge> results = IteratorUtils.list(a.edges(Direction.OUT, labelFriend, labelHate));
assertEquals(3, results.size());
assertTrue(results.contains(aFriendB));
assertTrue(results.contains(aFriendC));
assertTrue(results.contains(aHateC));
results = IteratorUtils.list(a.edges(Direction.IN, labelFriend, labelHate));
assertEquals(1, results.size());
assertTrue(results.contains(cHateA));
results = IteratorUtils.list(b.edges(Direction.IN, labelFriend, labelHate));
assertEquals(2, results.size());
assertTrue(results.contains(aFriendB));
assertTrue(results.contains(cHateB));
results = IteratorUtils.list(b.edges(Direction.IN, graphProvider.convertLabel("blah1"), graphProvider.convertLabel("blah2")));
assertEquals(0, results.size());
}