Java Code Examples for org.apache.tinkerpop.gremlin.structure.Direction#equals()

The following examples show how to use org.apache.tinkerpop.gremlin.structure.Direction#equals() . 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: TinkerHelper.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
public static Iterator<TinkerVertex> getVertices(final TinkerVertex vertex, final Direction direction, final String... edgeLabels) {
    final List<Vertex> vertices = new ArrayList<>();
    if (direction.equals(Direction.OUT) || direction.equals(Direction.BOTH)) {
        if (vertex.outEdges != null) {
            if (edgeLabels.length == 0)
                vertex.outEdges.values().forEach(set -> set.forEach(edge -> vertices.add(((TinkerEdge) edge).inVertex)));
            else if (edgeLabels.length == 1)
                vertex.outEdges.getOrDefault(edgeLabels[0], Collections.emptySet()).forEach(edge -> vertices.add(((TinkerEdge) edge).inVertex));
            else
                Stream.of(edgeLabels).map(vertex.outEdges::get).filter(Objects::nonNull).flatMap(Set::stream).forEach(edge -> vertices.add(((TinkerEdge) edge).inVertex));
        }
    }
    if (direction.equals(Direction.IN) || direction.equals(Direction.BOTH)) {
        if (vertex.inEdges != null) {
            if (edgeLabels.length == 0)
                vertex.inEdges.values().forEach(set -> set.forEach(edge -> vertices.add(((TinkerEdge) edge).outVertex)));
            else if (edgeLabels.length == 1)
                vertex.inEdges.getOrDefault(edgeLabels[0], Collections.emptySet()).forEach(edge -> vertices.add(((TinkerEdge) edge).outVertex));
            else
                Stream.of(edgeLabels).map(vertex.inEdges::get).filter(Objects::nonNull).flatMap(Set::stream).forEach(edge -> vertices.add(((TinkerEdge) edge).outVertex));
        }
    }
    return (Iterator) vertices.iterator();
}
 
Example 2
Source File: TinkerHelper.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
public static Iterator<TinkerEdge> getEdges(final TinkerVertex vertex, final Direction direction, final String... edgeLabels) {
    final List<Edge> edges = new ArrayList<>();
    if (direction.equals(Direction.OUT) || direction.equals(Direction.BOTH)) {
        if (vertex.outEdges != null) {
            if (edgeLabels.length == 0)
                vertex.outEdges.values().forEach(edges::addAll);
            else if (edgeLabels.length == 1)
                edges.addAll(vertex.outEdges.getOrDefault(edgeLabels[0], Collections.emptySet()));
            else
                Stream.of(edgeLabels).map(vertex.outEdges::get).filter(Objects::nonNull).forEach(edges::addAll);
        }
    }
    if (direction.equals(Direction.IN) || direction.equals(Direction.BOTH)) {
        if (vertex.inEdges != null) {
            if (edgeLabels.length == 0)
                vertex.inEdges.values().forEach(edges::addAll);
            else if (edgeLabels.length == 1)
                edges.addAll(vertex.inEdges.getOrDefault(edgeLabels[0], Collections.emptySet()));
            else
                Stream.of(edgeLabels).map(vertex.inEdges::get).filter(Objects::nonNull).forEach(edges::addAll);
        }
    }
    return (Iterator) edges.iterator();
}
 
Example 3
Source File: StarGraphSerializer.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
private <I extends InputShim> void readEdges(final KryoShim<I, ?> kryo, final I input, final StarGraph starGraph, final Direction direction) {
    if (kryo.readObject(input, Boolean.class)) {
        final int numberOfUniqueLabels = kryo.readObject(input, Integer.class);
        for (int i = 0; i < numberOfUniqueLabels; i++) {
            final String edgeLabel = kryo.readObject(input, String.class);
            final int numberOfEdgesWithLabel = kryo.readObject(input, Integer.class);
            for (int j = 0; j < numberOfEdgesWithLabel; j++) {
                final Object edgeId = kryo.readClassAndObject(input);
                final Object adjacentVertexId = kryo.readClassAndObject(input);
                if (this.graphFilter.checkEdgeLegality(direction, edgeLabel).positive()) {
                    if (direction.equals(Direction.OUT))
                        starGraph.starVertex.addOutEdge(edgeLabel, starGraph.addVertex(T.id, adjacentVertexId), T.id, edgeId);
                    else
                        starGraph.starVertex.addInEdge(edgeLabel, starGraph.addVertex(T.id, adjacentVertexId), T.id, edgeId);
                } else if (null != starGraph.edgeProperties) {
                    starGraph.edgeProperties.remove(edgeId);
                }
            }
        }
    }
}
 
Example 4
Source File: StarGraph.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public Iterator<Edge> edges(final Direction direction, final String... edgeLabels) {
    if (direction.equals(Direction.OUT)) {
        return null == this.outEdges ? Collections.emptyIterator() : edgeLabels.length == 0 ?
                IteratorUtils.flatMap(this.outEdges.values().iterator(), List::iterator) :
                this.outEdges.entrySet().stream()
                        .filter(entry -> ElementHelper.keyExists(entry.getKey(), edgeLabels))
                        .map(Map.Entry::getValue)
                        .flatMap(List::stream)
                        .iterator();
    } else if (direction.equals(Direction.IN)) {
        return null == this.inEdges ? Collections.emptyIterator() : edgeLabels.length == 0 ?
                IteratorUtils.flatMap(this.inEdges.values().iterator(), List::iterator) :
                this.inEdges.entrySet().stream()
                        .filter(entry -> ElementHelper.keyExists(entry.getKey(), edgeLabels))
                        .map(Map.Entry::getValue)
                        .flatMap(List::stream)
                        .iterator();
    } else
        return IteratorUtils.concat(this.edges(Direction.IN, edgeLabels), this.edges(Direction.OUT, edgeLabels));
}
 
Example 5
Source File: TinkerHelper.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
public static Iterator<TinkerVertex> getVertices(final TinkerVertex vertex, final Direction direction, final String... edgeLabels) {
    final List<Vertex> vertices = new ArrayList<>();
    if (direction.equals(Direction.OUT) || direction.equals(Direction.BOTH)) {
        if (vertex.outEdges != null) {
            if (edgeLabels.length == 0)
                vertex.outEdges.values().forEach(set -> set.forEach(edge -> vertices.add(((TinkerEdge) edge).inVertex)));
            else if (edgeLabels.length == 1)
                vertex.outEdges.getOrDefault(edgeLabels[0], Collections.emptySet()).forEach(edge -> vertices.add(((TinkerEdge) edge).inVertex));
            else
                Stream.of(edgeLabels).map(vertex.outEdges::get).filter(Objects::nonNull).flatMap(Set::stream).forEach(edge -> vertices.add(((TinkerEdge) edge).inVertex));
        }
    }
    if (direction.equals(Direction.IN) || direction.equals(Direction.BOTH)) {
        if (vertex.inEdges != null) {
            if (edgeLabels.length == 0)
                vertex.inEdges.values().forEach(set -> set.forEach(edge -> vertices.add(((TinkerEdge) edge).outVertex)));
            else if (edgeLabels.length == 1)
                vertex.inEdges.getOrDefault(edgeLabels[0], Collections.emptySet()).forEach(edge -> vertices.add(((TinkerEdge) edge).outVertex));
            else
                Stream.of(edgeLabels).map(vertex.inEdges::get).filter(Objects::nonNull).flatMap(Set::stream).forEach(edge -> vertices.add(((TinkerEdge) edge).outVertex));
        }
    }
    return (Iterator) vertices.iterator();
}
 
Example 6
Source File: TinkerHelper.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
public static Iterator<TinkerEdge> getEdges(final TinkerVertex vertex, final Direction direction, final String... edgeLabels) {
    final List<Edge> edges = new ArrayList<>();
    if (direction.equals(Direction.OUT) || direction.equals(Direction.BOTH)) {
        if (vertex.outEdges != null) {
            if (edgeLabels.length == 0)
                vertex.outEdges.values().forEach(edges::addAll);
            else if (edgeLabels.length == 1)
                edges.addAll(vertex.outEdges.getOrDefault(edgeLabels[0], Collections.emptySet()));
            else
                Stream.of(edgeLabels).map(vertex.outEdges::get).filter(Objects::nonNull).forEach(edges::addAll);
        }
    }
    if (direction.equals(Direction.IN) || direction.equals(Direction.BOTH)) {
        if (vertex.inEdges != null) {
            if (edgeLabels.length == 0)
                vertex.inEdges.values().forEach(edges::addAll);
            else if (edgeLabels.length == 1)
                edges.addAll(vertex.inEdges.getOrDefault(edgeLabels[0], Collections.emptySet()));
            else
                Stream.of(edgeLabels).map(vertex.inEdges::get).filter(Objects::nonNull).forEach(edges::addAll);
        }
    }
    return (Iterator) edges.iterator();
}
 
Example 7
Source File: SqlgEdge.java    From sqlg with MIT License 5 votes vote down vote up
private Iterator<Vertex> internalGetVertices(Direction direction) {
    final List<Vertex> vertices = new ArrayList<>();
    if (direction.equals(Direction.OUT) || direction.equals(Direction.BOTH))
        vertices.add(getOutVertex());
    if (direction.equals(Direction.IN) || direction.equals(Direction.BOTH))
        vertices.add(getInVertex());
    return vertices.iterator();
}
 
Example 8
Source File: Neo4jHelper.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
public static org.neo4j.tinkerpop.api.Neo4jDirection mapDirection(final Direction direction) {
    if (direction.equals(Direction.OUT))
        return org.neo4j.tinkerpop.api.Neo4jDirection.OUTGOING;
    else if (direction.equals(Direction.IN))
        return org.neo4j.tinkerpop.api.Neo4jDirection.INCOMING;
    else
        return org.neo4j.tinkerpop.api.Neo4jDirection.BOTH;
}
 
Example 9
Source File: TinkerVertex.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels) {
    return TinkerHelper.inComputerMode(this.graph) ?
            direction.equals(Direction.BOTH) ?
                    IteratorUtils.concat(
                            IteratorUtils.map(this.edges(Direction.OUT, edgeLabels), Edge::inVertex),
                            IteratorUtils.map(this.edges(Direction.IN, edgeLabels), Edge::outVertex)) :
                    IteratorUtils.map(this.edges(direction, edgeLabels), edge -> edge.vertices(direction.opposite()).next()) :
            (Iterator) TinkerHelper.getVertices(this, direction, edgeLabels);
}
 
Example 10
Source File: ComputerGraph.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Vertex> vertices(final Direction direction) {
    if (direction.equals(Direction.OUT))
        return IteratorUtils.of(this.outVertex());
    if (direction.equals(Direction.IN))
        return IteratorUtils.of(this.inVertex());
    else
        return IteratorUtils.of(this.outVertex(), this.inVertex());
}
 
Example 11
Source File: IncidentToAdjacentStrategy.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether a given step is optimizable or not.
 *
 * @param step1 an edge-emitting step
 * @param step2 a vertex-emitting step
 * @return <code>true</code> if step1 is not labeled and emits edges and step2 emits vertices,
 * otherwise <code>false</code>
 */
private static boolean isOptimizable(final Step step1, final Step step2) {
    if (step1 instanceof VertexStep && ((VertexStep) step1).returnsEdge() && step1.getLabels().isEmpty()) {
        final Direction step1Dir = ((VertexStep) step1).getDirection();
        if (step1Dir.equals(Direction.BOTH)) {
            return step2 instanceof EdgeOtherVertexStep;
        }
        return step2 instanceof EdgeOtherVertexStep || (step2 instanceof EdgeVertexStep &&
                ((EdgeVertexStep) step2).getDirection().equals(step1Dir.opposite()));
    }
    return false;
}
 
Example 12
Source File: ReferenceEdge.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Vertex> vertices(final Direction direction) {
    if (direction.equals(Direction.OUT))
        return IteratorUtils.of(this.outVertex);
    else if (direction.equals(Direction.IN))
        return IteratorUtils.of(this.inVertex);
    else
        return IteratorUtils.of(this.outVertex, this.inVertex);
}
 
Example 13
Source File: StarGraph.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Vertex> vertices(final Direction direction) {
    if (direction.equals(Direction.OUT))
        return IteratorUtils.of(this.outVertex());
    else if (direction.equals(Direction.IN))
        return IteratorUtils.of(this.inVertex());
    else
        return IteratorUtils.of(this.outVertex(), this.inVertex());
}
 
Example 14
Source File: StarGraph.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels) {
    if (direction.equals(Direction.OUT))
        return IteratorUtils.map(this.edges(direction, edgeLabels), Edge::inVertex);
    else if (direction.equals(Direction.IN))
        return IteratorUtils.map(this.edges(direction, edgeLabels), Edge::outVertex);
    else
        return IteratorUtils.concat(this.vertices(Direction.IN, edgeLabels), this.vertices(Direction.OUT, edgeLabels));
}
 
Example 15
Source File: StarGraph.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
public void dropEdges(final Direction direction, final String edgeLabel) {
    if (null != this.outEdges && (direction.equals(Direction.OUT) || direction.equals(Direction.BOTH))) {
        this.outEdges.remove(edgeLabel);

        if (this.outEdges.isEmpty())
            this.outEdges = null;
    }
    if (null != this.inEdges && (direction.equals(Direction.IN) || direction.equals(Direction.BOTH))) {
        this.inEdges.remove(edgeLabel);

        if (this.inEdges.isEmpty())
            this.inEdges = null;
    }
}
 
Example 16
Source File: StarGraph.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
public void dropEdges(final Direction direction) {
    if ((direction.equals(Direction.OUT) || direction.equals(Direction.BOTH)) && null != this.outEdges) {
        this.outEdges.clear();
        this.outEdges = null;
    }
    if ((direction.equals(Direction.IN) || direction.equals(Direction.BOTH)) && null != this.inEdges) {
        this.inEdges.clear();
        this.inEdges = null;
    }
}
 
Example 17
Source File: TinkerVertex.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels) {
    return TinkerHelper.inComputerMode(this.graph) ?
            direction.equals(Direction.BOTH) ?
                    IteratorUtils.concat(
                            IteratorUtils.map(this.edges(Direction.OUT, edgeLabels), Edge::inVertex),
                            IteratorUtils.map(this.edges(Direction.IN, edgeLabels), Edge::outVertex)) :
                    IteratorUtils.map(this.edges(direction, edgeLabels), edge -> edge.vertices(direction.opposite()).next()) :
            (Iterator) TinkerHelper.getVertices(this, direction, edgeLabels);
}