Java Code Examples for org.apache.tinkerpop.gremlin.structure.util.ElementHelper#validateMixedElementIds()

The following examples show how to use org.apache.tinkerpop.gremlin.structure.util.ElementHelper#validateMixedElementIds() . 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: BlazeGraph.java    From tinkerpop3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper to parse URIs from a list of element ids for lookup of
 * vertices or edges.
 * 
 * @see #vertices(Object...)
 * @see #edges(Object...)
 */
private List<URI> validateIds(final Object... elementIds) {
    ElementHelper.validateMixedElementIds(Element.class, elementIds);
    return Stream.of(elementIds)
            .map(elementId -> {
                if (elementId instanceof String) {
                    return (String) elementId;
                } else if (elementId instanceof Element) {
                    final Object id = ((Element) elementId).id();
                    if (id instanceof String) {
                        return (String) id;
                    }
                }
                throw new IllegalArgumentException(
                        "Unknown element id type: " + elementId + 
                        " ("+ elementId.getClass()+")");
            })
            .map(vf::elementURI)
            .collect(Collectors.toList());
}
 
Example 2
Source File: Neo4jGraph.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Vertex> vertices(final Object... vertexIds) {
    this.tx().readWrite();
    if (0 == vertexIds.length) {
        return IteratorUtils.stream(this.getBaseGraph().allNodes())
                .map(node -> (Vertex) new Neo4jVertex(node, this)).iterator();
    } else {
        ElementHelper.validateMixedElementIds(Vertex.class, vertexIds);
        return Stream.of(vertexIds)
                .map(id -> {
                    if (id instanceof Number)
                        return ((Number) id).longValue();
                    else if (id instanceof String)
                        return Long.valueOf(id.toString());
                    else if (id instanceof Vertex) {
                        return (Long) ((Vertex) id).id();
                    } else
                        throw new IllegalArgumentException("Unknown vertex id type: " + id);
                })
                .flatMap(id -> {
                    try {
                        return Stream.of(this.baseGraph.getNodeById(id));
                    } catch (final RuntimeException e) {
                        if (Neo4jHelper.isNotFound(e)) return Stream.empty();
                        throw e;
                    }
                })
                .map(node -> (Vertex) new Neo4jVertex(node, this)).iterator();
    }
}
 
Example 3
Source File: Neo4jGraph.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Edge> edges(final Object... edgeIds) {
    this.tx().readWrite();
    if (0 == edgeIds.length) {
        return IteratorUtils.stream(this.getBaseGraph().allRelationships())
                .map(relationship -> (Edge) new Neo4jEdge(relationship, this)).iterator();
    } else {
        ElementHelper.validateMixedElementIds(Edge.class, edgeIds);
        return Stream.of(edgeIds)
                .map(id -> {
                    if (id instanceof Number)
                        return ((Number) id).longValue();
                    else if (id instanceof String)
                        return Long.valueOf(id.toString());
                    else if (id instanceof Edge) {
                        return (Long) ((Edge) id).id();
                    } else
                        throw new IllegalArgumentException("Unknown edge id type: " + id);
                })
                .flatMap(id -> {
                    try {
                        return Stream.of(this.baseGraph.getRelationshipById(id));
                    } catch (final RuntimeException e) {
                        if (Neo4jHelper.isNotFound(e)) return Stream.empty();
                        throw e;
                    }
                })
                .map(relationship -> (Edge) new Neo4jEdge(relationship, this)).iterator();
    }
}