Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tinkerpop.gremlin.tinkergraph.structure;
import org.apache.tinkerpop.gremlin.process.computer.GraphFilter;
import org.apache.tinkerpop.gremlin.process.computer.VertexComputeKey;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.tinkergraph.process.computer.TinkerGraphComputerView;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
import java.util.regex.Pattern;
import java.util.stream.Stream;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public final class TinkerHelper {
private TinkerHelper() {
}
public static Map> getProperties(final TinkerVertex vertex) {
return null == vertex.properties ? Collections.emptyMap() : vertex.properties;
}
public static boolean inComputerMode(final AbstractTinkerGraph graph) {
return null != graph.graphComputerView;
}
public static TinkerGraphComputerView createGraphComputerView(final AbstractTinkerGraph graph, final GraphFilter graphFilter, final Set computeKeys) {
return graph.graphComputerView = new TinkerGraphComputerView(graph, graphFilter, computeKeys);
}
public static TinkerGraphComputerView getGraphComputerView(final AbstractTinkerGraph graph) {
return graph.graphComputerView;
}
public static void dropGraphComputerView(final AbstractTinkerGraph graph) {
graph.graphComputerView = null;
}
public static Iterator getEdges(final TinkerVertex vertex, final Direction direction, final String... edgeLabels) {
final List 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();
}
public static Iterator getEdgesTx(final TinkerVertex vertex, final Direction direction, final String... edgeLabels) {
final List