You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/02/12 14:01:53 UTC
[27/77] [partial] incubator-tinkerpop git commit: moved com/tinkerpop
directories to org/apache/tinkerpop
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1545201f/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/ElementHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/ElementHelper.java b/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/ElementHelper.java
deleted file mode 100644
index f057037..0000000
--- a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/ElementHelper.java
+++ /dev/null
@@ -1,461 +0,0 @@
-/*
- * 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 com.tinkerpop.gremlin.structure.util;
-
-import com.tinkerpop.gremlin.process.T;
-import com.tinkerpop.gremlin.structure.Edge;
-import com.tinkerpop.gremlin.structure.Element;
-import com.tinkerpop.gremlin.structure.Graph;
-import com.tinkerpop.gremlin.structure.Property;
-import com.tinkerpop.gremlin.structure.Vertex;
-import com.tinkerpop.gremlin.structure.VertexProperty;
-import org.javatuples.Pair;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-import java.util.stream.Stream;
-
-/**
- * Utility class supporting common functions for {@link com.tinkerpop.gremlin.structure.Element}.
- *
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public final class ElementHelper {
-
- private ElementHelper() {
- }
-
- /**
- * Determine whether the Element label can be legally set. This is typically used as a pre-condition check.
- *
- * @param label the element label
- * @throws IllegalArgumentException whether the label is legal and if not, a clear reason exception is provided
- */
- public static void validateLabel(final String label) throws IllegalArgumentException {
- if (null == label)
- throw Element.Exceptions.labelCanNotBeNull();
- if (label.isEmpty())
- throw Element.Exceptions.labelCanNotBeEmpty();
- if (Graph.Hidden.isHidden(label))
- throw Element.Exceptions.labelCanNotBeAHiddenKey(label);
- }
-
- /*public static void validateLabels(final String... labels) throws IllegalArgumentException {
- for (final String label : labels) {
- validateLabel(label);
- }
- }*/
-
- /**
- * Check if the vertex, by ID, exists. If it does return it, else create it and return it.
- *
- * @param graph the graph to check for the existence of the vertex
- * @param id the id of the vertex to look for
- * @param label the label of the vertex to set if the vertex does not exist
- * @return a pre-existing vertex or a newly created vertex
- */
- public static Vertex getOrAddVertex(final Graph graph, final Object id, final String label) {
- final Iterator<Vertex> iterator = graph.iterators().vertexIterator(id);
- return iterator.hasNext() ? iterator.next() : graph.addVertex(T.id, id, T.label, label);
- }
-
- /**
- * Determines whether the property key/value for the specified thing can be legally set. This is typically used as
- * a pre-condition check prior to setting a property.
- *
- * @param key the key of the property
- * @param value the value of the property
- * @throws IllegalArgumentException whether the key/value pair is legal and if not, a clear reason exception
- * message is provided
- */
- public static void validateProperty(final String key, final Object value) throws IllegalArgumentException {
- if (null == value)
- throw Property.Exceptions.propertyValueCanNotBeNull();
- if (null == key)
- throw Property.Exceptions.propertyKeyCanNotBeNull();
- if (key.isEmpty())
- throw Property.Exceptions.propertyKeyCanNotBeEmpty();
- if (Graph.Hidden.isHidden(key))
- throw Property.Exceptions.propertyKeyCanNotBeAHiddenKey(key);
- }
-
- /**
- * Determines whether a list of key/values are legal, ensuring that there are an even number of values submitted
- * and that the key values in the list of arguments are {@link String} or {@link com.tinkerpop.gremlin.structure.Element} objects.
- *
- * @param propertyKeyValues a list of key/value pairs
- * @throws IllegalArgumentException if something in the pairs is illegal
- */
- public static void legalPropertyKeyValueArray(final Object... propertyKeyValues) throws IllegalArgumentException {
- if (propertyKeyValues.length % 2 != 0)
- throw Element.Exceptions.providedKeyValuesMustBeAMultipleOfTwo();
- for (int i = 0; i < propertyKeyValues.length; i = i + 2) {
- if (!(propertyKeyValues[i] instanceof String) && !(propertyKeyValues[i] instanceof T))
- throw Element.Exceptions.providedKeyValuesMustHaveALegalKeyOnEvenIndices();
- }
- }
-
- /**
- * Extracts the value of the {@link com.tinkerpop.gremlin.process.T#id} key from the list of arguments.
- *
- * @param keyValues a list of key/value pairs
- * @return the value associated with {@link com.tinkerpop.gremlin.process.T#id}
- * @throws NullPointerException if the value for the {@link com.tinkerpop.gremlin.process.T#id} key is {@code null}
- */
- public static Optional<Object> getIdValue(final Object... keyValues) {
- for (int i = 0; i < keyValues.length; i = i + 2) {
- if (keyValues[i].equals(T.id))
- return Optional.of(keyValues[i + 1]);
- }
- return Optional.empty();
- }
-
- /**
- * Remove a key from the set of key value pairs. Assumes that validations have already taken place to
- * assure that key positions contain strings and that there are an even number of elements. If after removal
- * there are no values left, the key value list is returned as empty.
- */
- public static Optional<Object[]> remove(final String keyToRemove, final Object... keyValues) {
- return ElementHelper.remove((Object) keyToRemove, keyValues);
- }
-
- public static Optional<Object[]> remove(final T accessor, final Object... keyValues) {
- return ElementHelper.remove((Object) accessor, keyValues);
- }
-
-
- private static Optional<Object[]> remove(final Object keyToRemove, final Object... keyValues) {
- final List list = Arrays.asList(keyValues);
- final List revised = IntStream.range(0, list.size())
- .filter(i -> i % 2 == 0)
- .filter(i -> !keyToRemove.equals(list.get(i)))
- .flatMap(i -> IntStream.of(i, i + 1))
- .mapToObj(list::get)
- .collect(Collectors.toList());
- return revised.size() > 0 ? Optional.of(revised.toArray()) : Optional.empty();
- }
-
- /**
- * Append a key/value pair to a list of existing key/values. If the key already exists in the keyValues then
- * that value is overwritten with the provided value.
- */
- public static Object[] upsert(final Object[] keyValues, final String key, final Object val) {
- if (!getKeys(keyValues).contains(key))
- return Stream.concat(Stream.of(keyValues), Stream.of(key, val)).toArray();
- else {
- final Object[] kvs = new Object[keyValues.length];
- for (int i = 0; i < keyValues.length; i = i + 2) {
- kvs[i] = keyValues[i];
- if (keyValues[i].equals(key))
- kvs[i + 1] = val;
- else
- kvs[i + 1] = keyValues[i + 1];
- }
-
- return kvs;
- }
- }
-
- /**
- * Converts a set of key values to a Map. Assumes that validations have already taken place to
- * assure that key positions contain strings and that there are an even number of elements.
- */
- public static Map<String, Object> asMap(final Object... keyValues) {
- return asPairs(keyValues).stream().collect(Collectors.toMap(p -> p.getValue0(), p -> p.getValue1()));
- }
-
- /**
- * Convert a set of key values to a list of Pair objects. Assumes that validations have already taken place to
- * assure that key positions contain strings and that there are an even number of elements.
- */
- public static List<Pair<String, Object>> asPairs(final Object... keyValues) {
- final List list = Arrays.asList(keyValues);
- return IntStream.range(1, list.size())
- .filter(i -> i % 2 != 0)
- .mapToObj(i -> Pair.with(list.get(i - 1).toString(), list.get(i)))
- .collect(Collectors.toList());
- }
-
- /**
- * Gets the list of keys from the key values.
- *
- * @param keyValues a list of key/values pairs
- */
- public static Set<String> getKeys(final Object... keyValues) {
- final Set<String> keys = new HashSet<>();
- for (int i = 0; i < keyValues.length; i = i + 2) {
- keys.add(keyValues[i].toString());
- }
- return keys;
- }
-
- /**
- * Extracts the value of the {@link com.tinkerpop.gremlin.process.T#label} key from the list of arguments.
- *
- * @param keyValues a list of key/value pairs
- * @return the value associated with {@link com.tinkerpop.gremlin.process.T#label}
- * @throws ClassCastException if the value of the label is not a {@link String}
- * @throws NullPointerException if the value for the {@link com.tinkerpop.gremlin.process.T#label} key is {@code null}
- */
- public static Optional<String> getLabelValue(final Object... keyValues) {
- for (int i = 0; i < keyValues.length; i = i + 2) {
- if (keyValues[i].equals(T.label)) {
- ElementHelper.validateLabel((String) keyValues[i + 1]);
- return Optional.of((String) keyValues[i + 1]);
- }
- }
- return Optional.empty();
- }
-
- /**
- * Assign key/value pairs as properties to an {@link com.tinkerpop.gremlin.structure.Element}. If the value of {@link com.tinkerpop.gremlin.process.T#id} or
- * {@link com.tinkerpop.gremlin.process.T#label} is in the set of pairs, then they are ignored.
- *
- * @param element the graph element to assign the {@code propertyKeyValues}
- * @param propertyKeyValues the key/value pairs to assign to the {@code element}
- * @throws ClassCastException if the value of the key is not a {@link String}
- * @throws IllegalArgumentException if the value of {@code element} is null
- */
- public static void attachProperties(final Element element, final Object... propertyKeyValues) {
- if (null == element)
- throw Graph.Exceptions.argumentCanNotBeNull("element");
-
- for (int i = 0; i < propertyKeyValues.length; i = i + 2) {
- if (!propertyKeyValues[i].equals(T.id) && !propertyKeyValues[i].equals(T.label))
- element.property((String) propertyKeyValues[i], propertyKeyValues[i + 1]);
- }
- }
-
- /**
- * Assign key/value pairs as properties to an {@link com.tinkerpop.gremlin.structure.Vertex}. If the value of {@link com.tinkerpop.gremlin.process.T#id} or
- * {@link com.tinkerpop.gremlin.process.T#label} is in the set of pairs, then they are ignored.
- *
- * @param vertex the vertex to assign the {@code propertyKeyValues}
- * @param propertyKeyValues the key/value pairs to assign to the {@code vertex}
- * @throws ClassCastException if the value of the key is not a {@link String}
- * @throws IllegalArgumentException if the value of {@code vertex} is null
- */
- public static void attachSingleProperties(final Vertex vertex, final Object... propertyKeyValues) {
- if (null == vertex)
- throw Graph.Exceptions.argumentCanNotBeNull("vertex");
-
- for (int i = 0; i < propertyKeyValues.length; i = i + 2) {
- if (!propertyKeyValues[i].equals(T.id) && !propertyKeyValues[i].equals(T.label))
- vertex.property(VertexProperty.Cardinality.single, (String) propertyKeyValues[i], propertyKeyValues[i + 1]);
- }
- }
-
- /**
- * Retrieve the properties associated with a particular element.
- * The result is a Object[] where odd indices are String keys and even indices are the values.
- *
- * @param element the element to retrieve properties from
- * @param includeId include Element.ID in the key/value list
- * @param includeLabel include Element.LABEL in the key/value list
- * @param propertiesToCopy the properties to include with an empty list meaning copy all properties
- * @return a key/value array of properties where odd indices are String keys and even indices are the values.
- */
- public static Object[] getProperties(final Element element, final boolean includeId, final boolean includeLabel, final Set<String> propertiesToCopy) {
- final List<Object> keyValues = new ArrayList<>();
- if (includeId) {
- keyValues.add(T.id);
- keyValues.add(element.id());
- }
- if (includeLabel) {
- keyValues.add(T.label);
- keyValues.add(element.label());
- }
- element.keys().forEach(key -> {
- if (propertiesToCopy.isEmpty() || propertiesToCopy.contains(key)) {
- keyValues.add(key);
- keyValues.add(element.value(key));
- }
- });
- return keyValues.toArray(new Object[keyValues.size()]);
- }
-
- /**
- * A standard method for determining if two {@link com.tinkerpop.gremlin.structure.Element} objects are equal. This method should be used by any
- * {@link Object#equals(Object)} implementation to ensure consistent behavior. This method is used for Vertex, Edge, and VertexProperty.
- *
- * @param a The first {@link com.tinkerpop.gremlin.structure.Element}
- * @param b The second {@link com.tinkerpop.gremlin.structure.Element} (as an {@link Object})
- * @return true if elements and equal and false otherwise
- * @throws IllegalArgumentException if either argument is null
- */
- public static boolean areEqual(final Element a, final Object b) {
- if (null == a)
- throw Graph.Exceptions.argumentCanNotBeNull("a");
- if (null == b)
- throw Graph.Exceptions.argumentCanNotBeNull("b");
-
- if (a == b)
- return true;
- if (!((a instanceof Vertex && b instanceof Vertex) ||
- (a instanceof Edge && b instanceof Edge) ||
- (a instanceof VertexProperty && b instanceof VertexProperty)))
- return false;
- return haveEqualIds(a, (Element) b);
- }
-
- /**
- * A standard method for determining if two {@link com.tinkerpop.gremlin.structure.VertexProperty} objects are equal. This method should be used by any
- * {@link Object#equals(Object)} implementation to ensure consistent behavior.
- *
- * @param a the first {@link com.tinkerpop.gremlin.structure.VertexProperty}
- * @param b the second {@link com.tinkerpop.gremlin.structure.VertexProperty}
- * @return true if equal and false otherwise
- */
- public static boolean areEqual(final VertexProperty a, final Object b) {
- return ElementHelper.areEqual((Element) a, b);
- }
-
- /**
- * Simply tests if the value returned from {@link com.tinkerpop.gremlin.structure.Element#id()} are {@code equal()}.
- *
- * @param a the first {@link com.tinkerpop.gremlin.structure.Element}
- * @param b the second {@link com.tinkerpop.gremlin.structure.Element}
- * @return true if ids are equal and false otherwise
- */
- public static boolean haveEqualIds(final Element a, final Element b) {
- return a.id().equals(b.id());
- }
-
- /**
- * If two {@link Element} instances are equal, then they must have the same hash codes. This methods ensures consistent hashCode values.
- *
- * @param element the element to get the hashCode for
- * @return the hash code of the element
- */
- public static int hashCode(final Element element) {
- return element.id().hashCode();
- }
-
- /**
- * If two {@link Property} instances are equal, then they must have the same hash codes. This methods ensures consistent hashCode values.
- * For {@link VertexProperty} use {@link ElementHelper#hashCode(com.tinkerpop.gremlin.structure.Element)}.
- *
- * @param property the property to get the hashCode for
- * @return the hash code of the property
- */
- public static int hashCode(final Property property) {
- return property.key().hashCode() + property.value().hashCode();
- }
-
- /**
- * A standard method for determining if two {@link com.tinkerpop.gremlin.structure.Property} objects are equal. This method should be used by any
- * {@link Object#equals(Object)} implementation to ensure consistent behavior.
- *
- * @param a the first {@link com.tinkerpop.gremlin.structure.Property}
- * @param b the second {@link com.tinkerpop.gremlin.structure.Property}
- * @return true if equal and false otherwise
- */
- public static boolean areEqual(final Property a, final Object b) {
- if (null == a)
- throw Graph.Exceptions.argumentCanNotBeNull("a");
- if (null == b)
- throw Graph.Exceptions.argumentCanNotBeNull("b");
-
- if (a == b)
- return true;
- if (!(b instanceof Property))
- return false;
- if (!a.isPresent() && !((Property) b).isPresent())
- return true;
- if (!a.isPresent() && ((Property) b).isPresent() || a.isPresent() && !((Property) b).isPresent())
- return false;
- return a.key().equals(((Property) b).key()) && a.value().equals(((Property) b).value()) && areEqual(a.element(), ((Property) b).element());
-
- }
-
- public static Map<String, Object> propertyValueMap(final Element element, final String... propertyKeys) {
- final Map<String, Object> values = new HashMap<>();
- element.iterators().propertyIterator(propertyKeys).forEachRemaining(property -> values.put(property.key(), property.value()));
- return values;
- }
-
- public static Map<String, Property> propertyMap(final Element element, final String... propertyKeys) {
- final Map<String, Property> propertyMap = new HashMap<>();
- element.iterators().propertyIterator(propertyKeys).forEachRemaining(property -> propertyMap.put(property.key(), property));
- return propertyMap;
- }
-
- public static Map<String, List> vertexPropertyValueMap(final Vertex vertex, final String... propertyKeys) {
- final Map<String, List> valueMap = new HashMap<>();
- vertex.iterators().propertyIterator(propertyKeys).forEachRemaining(property -> {
- if (valueMap.containsKey(property.key()))
- valueMap.get(property.key()).add(property.value());
- else {
- final List list = new ArrayList();
- list.add(property.value());
- valueMap.put(property.key(), list);
- }
- });
- return valueMap;
- }
-
- public static Map<String, List<VertexProperty>> vertexPropertyMap(final Vertex vertex, final String... propertyKeys) {
- final Map<String, List<VertexProperty>> propertyMap = new HashMap<>();
- vertex.iterators().propertyIterator(propertyKeys).forEachRemaining(property -> {
- if (propertyMap.containsKey(property.key()))
- propertyMap.get(property.key()).add(property);
- else {
- final List<VertexProperty> list = new ArrayList<>();
- list.add(property);
- propertyMap.put(property.key(), list);
- }
- });
- return propertyMap;
- }
-
- public static boolean keyExists(final String key, final String... providedKeys) {
- if (Graph.Hidden.isHidden(key)) return false;
- if (0 == providedKeys.length) return true;
- if (1 == providedKeys.length) return key.equals(providedKeys[0]);
- else {
- for (final String temp : providedKeys) {
- if (temp.equals(key))
- return true;
- }
- return false;
- }
- }
-
- public static boolean idExists(final Object id, final Object... providedIds) {
- if (0 == providedIds.length) return true;
- if (1 == providedIds.length) return id.equals(providedIds[0]);
- else {
- for (final Object temp : providedIds) {
- if (temp.equals(id))
- return true;
- }
- return false;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1545201f/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/FeatureDescriptor.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/FeatureDescriptor.java b/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/FeatureDescriptor.java
deleted file mode 100644
index 01e9c70..0000000
--- a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/FeatureDescriptor.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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 com.tinkerpop.gremlin.structure.util;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * A annotation for feature methods.
- *
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.METHOD)
-public @interface FeatureDescriptor {
- /**
- * The name of the feature which is represented as the text of the method it is annotating after the "supports"
- * prefix
- */
- String name();
-
- /**
- * A description of the feature that will be useful to implementers if a Gremlin test fails around
- * proper feature support.
- */
- String description() default "";
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1545201f/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/GraphFactory.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/GraphFactory.java b/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/GraphFactory.java
deleted file mode 100644
index af8c383..0000000
--- a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/GraphFactory.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * 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 com.tinkerpop.gremlin.structure.util;
-
-import com.tinkerpop.gremlin.structure.Graph;
-import com.tinkerpop.gremlin.util.config.YamlConfiguration;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.MapConfiguration;
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import java.io.File;
-import java.util.Map;
-
-/**
- * Factory to construct new {@link com.tinkerpop.gremlin.structure.Graph} instances from a
- * {@link org.apache.commons.configuration.Configuration} object or properties file.
- *
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public class GraphFactory {
-
- /**
- * Open a graph. See each {@link com.tinkerpop.gremlin.structure.Graph} instance for its configuration options.
- *
- * @param configuration A configuration object that specifies the minimally required properties for a I
- * {@link com.tinkerpop.gremlin.structure.Graph} instance. This minimum is determined by the
- * {@link com.tinkerpop.gremlin.structure.Graph} instance itself.
- * @return A {@link com.tinkerpop.gremlin.structure.Graph} instance.
- * @throws IllegalArgumentException if {@code configuration}
- */
- public static Graph open(final Configuration configuration) {
- if (null == configuration)
- throw Graph.Exceptions.argumentCanNotBeNull("configuration");
-
- final String clazz = configuration.getString(Graph.GRAPH, null);
- if (null == clazz)
- throw new RuntimeException("Configuration must contain a valid 'gremlin.graph' setting");
-
- final Class graphClass;
- try {
- graphClass = Class.forName(clazz);
- } catch (final ClassNotFoundException e) {
- throw new RuntimeException(String.format("GraphFactory could not find [%s] - Ensure that the jar is in the classpath", clazz));
- }
-
- final Graph g;
- try {
- // will basically use Graph.open(Configuration c) to instantiate, but could
- // technically use any method on any class with the same signature.
- g = (Graph) graphClass.getMethod("open", Configuration.class).invoke(null, configuration);
- } catch (final NoSuchMethodException e1) {
- throw new RuntimeException(String.format("GraphFactory can only instantiate Graph implementations from classes that have a static open() method that takes a single Apache Commons Configuration argument - [%s] does not seem to have one", clazz));
- } catch (final Exception e2) {
- throw new RuntimeException(String.format("GraphFactory could not instantiate this Graph implementation [%s]", clazz), e2);
- }
-
- return g;
- }
-
- /**
- * Open a graph. See each {@link com.tinkerpop.gremlin.structure.Graph} instance for its configuration options. This file may be XML, YAML,
- * or a standard properties file. How the configuration is used (and which kind is required) is dependent on
- * the implementation.
- *
- * @param configurationFile The location of a configuration file that specifies the minimally required properties
- * for a {@link com.tinkerpop.gremlin.structure.Graph} instance. This minimum is determined by the {@link com.tinkerpop.gremlin.structure.Graph} instance
- * itself.
- * @return A {@link com.tinkerpop.gremlin.structure.Graph} instance.
- * @throws IllegalArgumentException if {@code configurationFile} is null
- */
- public static Graph open(final String configurationFile) {
- if (null == configurationFile) throw Graph.Exceptions.argumentCanNotBeNull("configurationFile");
- return open(getConfiguration(new File(configurationFile)));
- }
-
- /**
- * Open a graph. See each {@link com.tinkerpop.gremlin.structure.Graph} instance for its configuration options.
- *
- * @param configuration A {@link java.util.Map} based configuration that will be converted to an {@link org.apache.commons.configuration.Configuration} object
- * via {@link org.apache.commons.configuration.MapConfiguration} and passed to the appropriate overload.
- * @return A Graph instance.
- */
- public static Graph open(final Map configuration) {
- return open(new MapConfiguration(configuration));
- }
-
- private static Configuration getConfiguration(final File configurationFile) {
- if (null == configurationFile)
- throw Graph.Exceptions.argumentCanNotBeNull("configurationFile");
-
- if (!configurationFile.isFile())
- throw new IllegalArgumentException(String.format("The location configuration must resolve to a file and [%s] does not", configurationFile));
-
- try {
- final String fileName = configurationFile.getName();
- final String fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1);
-
- switch (fileExtension) {
- case "yml":
- case "yaml":
- return new YamlConfiguration(configurationFile);
- case "xml":
- return new XMLConfiguration(configurationFile);
- default:
- return new PropertiesConfiguration(configurationFile);
- }
- } catch (final ConfigurationException e) {
- throw new IllegalArgumentException(String.format("Could not load configuration at: %s", configurationFile), e);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1545201f/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/GraphVariableHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/GraphVariableHelper.java b/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/GraphVariableHelper.java
deleted file mode 100644
index 46a22ce..0000000
--- a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/GraphVariableHelper.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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 com.tinkerpop.gremlin.structure.util;
-
-import com.tinkerpop.gremlin.structure.Graph;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class GraphVariableHelper {
-
- public static void validateVariable(final String variable, final Object value) throws IllegalArgumentException {
- if (null == value)
- throw Graph.Variables.Exceptions.variableValueCanNotBeNull();
- if (null == variable)
- throw Graph.Variables.Exceptions.variableKeyCanNotBeNull();
- if (variable.isEmpty())
- throw Graph.Variables.Exceptions.variableKeyCanNotBeEmpty();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1545201f/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/StringFactory.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/StringFactory.java b/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/StringFactory.java
deleted file mode 100644
index 0655e16..0000000
--- a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/StringFactory.java
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * 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 com.tinkerpop.gremlin.structure.util;
-
-import com.tinkerpop.gremlin.process.TraversalSideEffects;
-import com.tinkerpop.gremlin.process.TraversalStrategies;
-import com.tinkerpop.gremlin.process.TraversalStrategy;
-import com.tinkerpop.gremlin.process.computer.ComputerResult;
-import com.tinkerpop.gremlin.process.computer.GraphComputer;
-import com.tinkerpop.gremlin.process.computer.MapReduce;
-import com.tinkerpop.gremlin.process.computer.Memory;
-import com.tinkerpop.gremlin.process.computer.VertexProgram;
-import com.tinkerpop.gremlin.structure.Direction;
-import com.tinkerpop.gremlin.structure.Edge;
-import com.tinkerpop.gremlin.structure.Graph;
-import com.tinkerpop.gremlin.structure.Property;
-import com.tinkerpop.gremlin.structure.Vertex;
-import com.tinkerpop.gremlin.structure.VertexProperty;
-import com.tinkerpop.gremlin.structure.strategy.GraphStrategy;
-import com.tinkerpop.gremlin.structure.strategy.StrategyElement;
-import com.tinkerpop.gremlin.structure.strategy.StrategyProperty;
-import com.tinkerpop.gremlin.structure.strategy.StrategyVariables;
-import com.tinkerpop.gremlin.util.function.FunctionUtils;
-import org.javatuples.Pair;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.function.Function;
-import java.util.function.Predicate;
-import java.util.stream.Stream;
-
-
-/**
- * A collection of helpful methods for creating standard {@link Object#toString()} representations of graph-related
- * objects.
- *
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class StringFactory {
-
- private static final String V = "v";
- private static final String E = "e";
- private static final String P = "p";
- private static final String VP = "vp";
- private static final String L_BRACKET = "[";
- private static final String R_BRACKET = "]";
- private static final String COMMA_SPACE = ", ";
- private static final String COLON = ":";
- private static final String EMPTY_MAP = "{}";
- private static final String DOTS = "...";
- private static final String DASH = "-";
- private static final String ARROW = "->";
- private static final String STAR = "*";
- private static final String EMPTY_PROPERTY = "p[empty]";
- private static final String EMPTY_VERTEX_PROPERTY = "vp[empty]";
- private static final String LINE_SEPARATOR = System.getProperty("line.separator");
-
- private static final String featuresStartWith = "supports";
- private static final int prefixLength = featuresStartWith.length();
-
- private StringFactory() {
- }
-
- /**
- * Construct the representation for a {@link com.tinkerpop.gremlin.structure.Vertex}.
- */
- public static String vertexString(final Vertex vertex) {
- return V + L_BRACKET + vertex.id() + R_BRACKET;
- }
-
- /**
- * Construct the representation for a {@link com.tinkerpop.gremlin.structure.Edge}.
- */
- public static String edgeString(final Edge edge) {
- final Vertex inV = edge.iterators().vertexIterator(Direction.IN).next();
- final Vertex outV = edge.iterators().vertexIterator(Direction.OUT).next();
- return E + L_BRACKET + edge.id() + R_BRACKET + L_BRACKET + outV.id() + DASH + edge.label() + ARROW + inV.id() + R_BRACKET;
- }
-
- /**
- * Construct the representation for a {@link com.tinkerpop.gremlin.structure.Property} or {@link com.tinkerpop.gremlin.structure.VertexProperty}.
- */
- public static String propertyString(final Property property) {
- if (property instanceof VertexProperty) {
- if (!property.isPresent()) return EMPTY_VERTEX_PROPERTY;
- final String valueString = String.valueOf(property.value());
- return VP + L_BRACKET + property.key() + ARROW + valueString.substring(0, Math.min(valueString.length(), 20)) + R_BRACKET;
- } else {
- if (!property.isPresent()) return EMPTY_PROPERTY;
- final String valueString = String.valueOf(property.value());
- return P + L_BRACKET + property.key() + ARROW + valueString.substring(0, Math.min(valueString.length(), 20)) + R_BRACKET;
- }
- }
-
- /**
- * Construct the representation for a {@link com.tinkerpop.gremlin.structure.Graph}.
- *
- * @param internalString a mapper {@link String} that appends to the end of the standard representation
- */
- public static String graphString(final Graph graph, final String internalString) {
- return graph.getClass().getSimpleName().toLowerCase() + L_BRACKET + internalString + R_BRACKET;
- }
-
- /**
- * Construct the representation for a {@link com.tinkerpop.gremlin.structure.strategy.GraphStrategy}.
- */
-
- public static String graphStrategyString(final GraphStrategy graphStrategy) {
- return graphStrategy.getClass().getSimpleName().toLowerCase();
- }
-
- public static String graphStrategyString(final GraphStrategy graphStrategy, final Graph graph) {
- return graphStrategy.getClass().getSimpleName().toLowerCase() + L_BRACKET + graph.toString() + R_BRACKET;
- }
-
- public static String graphStrategyElementString(final StrategyElement element) {
- return element.getBaseElement() + STAR;
- }
-
- public static String graphStrategyPropertyString(final StrategyProperty property) {
- return property.getBaseProperty() + STAR;
- }
-
- public static String graphStrategyVariables(final StrategyVariables variables) {
- return variables.getBaseVariables() + STAR;
- }
-
- public static String graphVariablesString(final Graph.Variables variables) {
- return "variables" + L_BRACKET + "size:" + variables.keys().size() + R_BRACKET;
- }
-
- public static String memoryString(final Memory memory) {
- return "memory" + L_BRACKET + "size:" + memory.keys().size() + R_BRACKET;
- }
-
- public static String computeResultString(final ComputerResult computerResult) {
- return "result" + L_BRACKET + computerResult.graph() + ',' + computerResult.memory() + R_BRACKET;
- }
-
- public static String graphComputerString(final GraphComputer graphComputer) {
- return graphComputer.getClass().getSimpleName().toLowerCase();
- }
-
- public static String featureString(final Graph.Features features) {
- final StringBuilder sb = new StringBuilder("FEATURES");
- final Predicate<Method> supportMethods = (m) -> m.getModifiers() == Modifier.PUBLIC && m.getName().startsWith(featuresStartWith) && !m.getName().equals(featuresStartWith);
- sb.append(LINE_SEPARATOR);
-
- Stream.of(Pair.with(Graph.Features.GraphFeatures.class, features.graph()),
- Pair.with(Graph.Features.VariableFeatures.class, features.graph().variables()),
- Pair.with(Graph.Features.VertexFeatures.class, features.vertex()),
- Pair.with(Graph.Features.VertexPropertyFeatures.class, features.vertex().properties()),
- Pair.with(Graph.Features.EdgeFeatures.class, features.edge()),
- Pair.with(Graph.Features.EdgePropertyFeatures.class, features.edge().properties())).forEach(p -> {
- printFeatureTitle(p.getValue0(), sb);
- Stream.of(p.getValue0().getMethods())
- .filter(supportMethods)
- .map(createTransform(p.getValue1()))
- .forEach(sb::append);
- });
-
- return sb.toString();
- }
-
- public static String traversalSideEffectsString(final TraversalSideEffects traversalSideEffects) {
- return "sideEffects" + L_BRACKET + "size:" + traversalSideEffects.keys().size() + R_BRACKET;
- }
-
- public static String traversalStrategiesString(final TraversalStrategies traversalStrategies) {
- return "strategies" + traversalStrategies.toList();
- }
-
- public static String traversalStrategyString(final TraversalStrategy traversalStrategy) {
- return traversalStrategy.getClass().getSimpleName();
- }
-
- public static String vertexProgramString(final VertexProgram vertexProgram, final String internalString) {
- return vertexProgram.getClass().getSimpleName() + L_BRACKET + internalString + R_BRACKET;
- }
-
- public static String vertexProgramString(final VertexProgram vertexProgram) {
- return vertexProgram.getClass().getSimpleName();
- }
-
- public static String mapReduceString(final MapReduce mapReduce, final String internalString) {
- return mapReduce.getClass().getSimpleName() + L_BRACKET + internalString + R_BRACKET;
- }
-
- public static String mapReduceString(final MapReduce mapReduce) {
- return mapReduce.getClass().getSimpleName();
- }
-
- private static Function<Method, String> createTransform(final Graph.Features.FeatureSet features) {
- return FunctionUtils.wrapFunction((m) -> ">-- " + m.getName().substring(prefixLength) + ": " + m.invoke(features).toString() + LINE_SEPARATOR);
- }
-
- private static void printFeatureTitle(final Class<? extends Graph.Features.FeatureSet> featureClass, final StringBuilder sb) {
- sb.append("> ");
- sb.append(featureClass.getSimpleName());
- sb.append(LINE_SEPARATOR);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1545201f/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/BatchFeatures.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/BatchFeatures.java b/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/BatchFeatures.java
deleted file mode 100644
index 3ab0e79..0000000
--- a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/BatchFeatures.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * 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 com.tinkerpop.gremlin.structure.util.batch;
-
-import com.tinkerpop.gremlin.structure.Graph;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-class BatchFeatures implements Graph.Features {
-
- private final Graph.Features baseFeatures;
- private final BatchGraphFeatures graphFeatures = new BatchGraphFeatures();
-
- private final VertexFeatures vertexFeatures = new VertexFeatures() {
- @Override
- public boolean supportsUserSuppliedIds() {
- // batch loading supports user supplied ids
- return true;
- }
-
- @Override
- public VertexPropertyFeatures properties() {
- return vertexPropertyFeatures;
- }
- };
-
- private final EdgeFeatures edgeFeatures = new EdgeFeatures() {
- @Override
- public boolean supportsUserSuppliedIds() {
- // batch loading supports user supplied identifiers
- return true;
- }
-
- @Override
- public EdgePropertyFeatures properties() {
- return edgePropertyFeatures;
- }
- };
-
- private final EdgePropertyFeatures edgePropertyFeatures = new BatchEdgePropertyFeatures();
- private final VertexPropertyFeatures vertexPropertyFeatures = new BatchVertexPropertyFeatures();
-
- public BatchFeatures(final Graph.Features baseFeatures) {
- this.baseFeatures = baseFeatures;
- }
-
- @Override
- public GraphFeatures graph() {
- return graphFeatures;
- }
-
- @Override
- public VertexFeatures vertex() {
- return vertexFeatures;
- }
-
- @Override
- public EdgeFeatures edge() {
- return edgeFeatures;
- }
-
- class BatchVertexPropertyFeatures extends BatchDataTypeFeature implements VertexPropertyFeatures {
- @Override
- public boolean supportsProperties() {
- return baseFeatures.vertex().properties().supportsProperties();
- }
- }
-
- class BatchEdgePropertyFeatures extends BatchDataTypeFeature implements EdgePropertyFeatures {
- @Override
- public boolean supportsProperties() {
- return baseFeatures.edge().properties().supportsProperties();
- }
- }
-
- class BatchGraphFeatures implements GraphFeatures {
-
- @Override
- public boolean supportsComputer() {
- return false;
- }
-
- @Override
- public boolean supportsPersistence() {
- return baseFeatures.graph().supportsPersistence();
- }
-
- @Override
- public boolean supportsTransactions() {
- // the transaction is true because as a wrapper the BatchGraph will check the features of the
- // underlying graph and not let it fail if the underlying graph does not support tx.
- return true;
- }
-
- @Override
- public boolean supportsThreadedTransactions() {
- return false;
- }
-
- @Override
- public VariableFeatures variables() {
- return new BatchVariableFeatures();
- }
- }
-
- class BatchVariableFeatures extends BatchDataTypeFeature implements VariableFeatures {
- @Override
- public boolean supportsVariables() {
- return baseFeatures.graph().variables().supportsVariables();
- }
- }
-
- class BatchDataTypeFeature implements DataTypeFeatures {
- @Override
- public boolean supportsBooleanValues() {
- return baseFeatures.graph().variables().supportsBooleanValues();
- }
-
- @Override
- public boolean supportsDoubleValues() {
- return baseFeatures.graph().variables().supportsDoubleValues();
- }
-
- @Override
- public boolean supportsFloatValues() {
- return baseFeatures.graph().variables().supportsFloatValues();
- }
-
- @Override
- public boolean supportsIntegerValues() {
- return baseFeatures.graph().variables().supportsIntegerValues();
- }
-
- @Override
- public boolean supportsLongValues() {
- return baseFeatures.graph().variables().supportsLongValues();
- }
-
- @Override
- public boolean supportsMapValues() {
- return baseFeatures.graph().variables().supportsMapValues();
- }
-
- @Override
- public boolean supportsByteValues() {
- return baseFeatures.graph().variables().supportsByteValues();
- }
-
- @Override
- public boolean supportsMixedListValues() {
- return baseFeatures.graph().variables().supportsMixedListValues();
- }
-
- @Override
- public boolean supportsBooleanArrayValues() {
- return baseFeatures.graph().variables().supportsBooleanArrayValues();
- }
-
- @Override
- public boolean supportsByteArrayValues() {
- return baseFeatures.graph().variables().supportsByteArrayValues();
- }
-
- @Override
- public boolean supportsDoubleArrayValues() {
- return baseFeatures.graph().variables().supportsDoubleArrayValues();
- }
-
- @Override
- public boolean supportsFloatArrayValues() {
- return baseFeatures.graph().variables().supportsFloatArrayValues();
- }
-
- @Override
- public boolean supportsIntegerArrayValues() {
- return baseFeatures.graph().variables().supportsIntegerArrayValues();
- }
-
- @Override
- public boolean supportsLongArrayValues() {
- return baseFeatures.graph().variables().supportsLongArrayValues();
- }
-
- @Override
- public boolean supportsSerializableValues() {
- return baseFeatures.graph().variables().supportsSerializableValues();
- }
-
- @Override
- public boolean supportsStringValues() {
- return baseFeatures.graph().variables().supportsStringValues();
- }
-
- @Override
- public boolean supportsUniformListValues() {
- return baseFeatures.graph().variables().supportsUniformListValues();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1545201f/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/BatchGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/BatchGraph.java b/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/BatchGraph.java
deleted file mode 100644
index 4820501..0000000
--- a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/BatchGraph.java
+++ /dev/null
@@ -1,656 +0,0 @@
-/*
- * 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 com.tinkerpop.gremlin.structure.util.batch;
-
-import com.tinkerpop.gremlin.process.T;
-import com.tinkerpop.gremlin.process.Traversal;
-import com.tinkerpop.gremlin.process.computer.GraphComputer;
-import com.tinkerpop.gremlin.process.graph.traversal.GraphTraversal;
-import com.tinkerpop.gremlin.process.graph.traversal.VertexTraversal;
-import com.tinkerpop.gremlin.structure.Direction;
-import com.tinkerpop.gremlin.structure.Edge;
-import com.tinkerpop.gremlin.structure.Element;
-import com.tinkerpop.gremlin.structure.Graph;
-import com.tinkerpop.gremlin.structure.Property;
-import com.tinkerpop.gremlin.structure.Transaction;
-import com.tinkerpop.gremlin.structure.Vertex;
-import com.tinkerpop.gremlin.structure.VertexProperty;
-import com.tinkerpop.gremlin.structure.util.ElementHelper;
-import com.tinkerpop.gremlin.structure.util.batch.cache.VertexCache;
-import com.tinkerpop.gremlin.util.iterator.IteratorUtils;
-import org.apache.commons.configuration.BaseConfiguration;
-import org.apache.commons.configuration.Configuration;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-import java.util.Optional;
-import java.util.Set;
-import java.util.function.BiConsumer;
-import java.util.function.Consumer;
-import java.util.function.Function;
-
-/**
- * {@code BatchGraph} is a wrapper that enables batch loading of a large number of edges and vertices by chunking the entire
- * load into smaller batches and maintaining a sideEffects-efficient vertex cache so that the entire transactional state can
- * be flushed after each chunk is loaded.
- * <br />
- * {@code BatchGraph} is ONLY meant for loading data and does not support any retrieval or removal operations.
- * That is, BatchGraph only supports the following methods:
- * - {@link #addVertex(Object...)} for adding vertices
- * - {@link Vertex#addEdge(String, com.tinkerpop.gremlin.structure.Vertex, Object...)} for adding edges
- * - {@link #V(Object...)} to be used when adding edges
- * - Property getter, setter and removal methods for vertices and edges.
- * <br />
- * An important limitation of BatchGraph is that edge properties can only be set immediately after the edge has been added.
- * If other vertices or edges have been created in the meantime, setting, getting or removing properties will throw
- * exceptions. This is done to avoid caching of edges which would require a great amount of sideEffects.
- * <br />
- * {@code BatchGraph} can also automatically set the provided element ids as properties on the respective element. Use
- * {@link Builder#vertexIdKey(String)} and {@link Builder#edgeIdKey(String)} to set the keys
- * for the vertex and edge properties respectively. This allows to make the loaded baseGraph compatible for later
- * operation with {@link com.tinkerpop.gremlin.structure.strategy.IdStrategy}.
- * <br/>
- * Note that {@code BatchGraph} itself is not a {@link com.tinkerpop.gremlin.structure.strategy.GraphStrategy} because
- * it requires that the {@link Vertex} implementation not hold on to the underlying {@link Vertex} reference and
- * {@link com.tinkerpop.gremlin.structure.strategy.StrategyVertex} does that by it's very nature. While it might
- * be possible to work around this issue, it is likely better for performance to simply leave this as a "half-wrapper"
- * implementation, instead of forcing it into a {@link com.tinkerpop.gremlin.structure.strategy.GraphStrategy}.
- *
- * @author Matthias Broecheler (http://www.matthiasb.com)
- * @author Stephen Mallette (http://stephen.genoprime.com)
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class BatchGraph<G extends Graph> implements Graph, Graph.Iterators {
- /**
- * Default buffer size is 10000.
- */
- public static final long DEFAULT_BUFFER_SIZE = 10000;
-
- private final G baseGraph;
-
- private final String vertexIdKey;
- private final String edgeIdKey;
- private final boolean incrementalLoading;
- private final boolean baseSupportsSuppliedVertexId;
- private final boolean baseSupportsSuppliedEdgeId;
- private final boolean baseSupportsTransactions;
- private final BiConsumer<Element, Object[]> existingVertexStrategy;
- private final BiConsumer<Element, Object[]> existingEdgeStrategy;
-
- private final VertexCache cache;
-
- private final long bufferSize;
- private long remainingBufferSize;
-
- private BatchEdge currentEdge = null;
- private Edge currentEdgeCached = null;
-
- private Object previousOutVertexId = null;
-
- private final BatchFeatures batchFeatures;
-
- private final Transaction batchTransaction;
-
- /**
- * Constructs a BatchGraph wrapping the provided baseGraph, using the specified buffer size and expecting vertex
- * ids of the specified IdType. Supplying vertex ids which do not match this type will throw exceptions.
- *
- * @param graph Graph to be wrapped
- * @param type Type of vertex id expected. This information is used to apply the vertex cache
- * sideEffects footprint.
- * @param bufferSize Defines the number of vertices and edges loaded before starting a new transaction. The
- * larger this value, the more sideEffects is required but the faster the loading process.
- */
- private BatchGraph(final G graph, final VertexIdType type, final long bufferSize, final String vertexIdKey,
- final String edgeIdKey, final boolean incrementalLoading,
- final BiConsumer<Element, Object[]> existingVertexStrategy,
- final BiConsumer<Element, Object[]> existingEdgeStrategy) {
- this.baseGraph = graph;
- this.batchTransaction = new BatchTransaction();
- this.batchFeatures = new BatchFeatures(graph.features());
- this.bufferSize = bufferSize;
- this.cache = type.getVertexCache();
- this.remainingBufferSize = this.bufferSize;
- this.vertexIdKey = vertexIdKey;
- this.edgeIdKey = edgeIdKey;
- this.incrementalLoading = incrementalLoading;
- this.baseSupportsSuppliedEdgeId = this.baseGraph.features().edge().supportsUserSuppliedIds();
- this.baseSupportsSuppliedVertexId = this.baseGraph.features().vertex().supportsUserSuppliedIds();
- this.baseSupportsTransactions = this.baseGraph.features().graph().supportsTransactions();
- this.existingEdgeStrategy = existingEdgeStrategy;
- this.existingVertexStrategy = existingVertexStrategy;
- }
-
- private void nextElement() {
- currentEdge = null;
- currentEdgeCached = null;
- if (remainingBufferSize <= 0) {
- if (this.baseSupportsTransactions) baseGraph.tx().commit();
- cache.newTransaction();
- remainingBufferSize = bufferSize;
- }
- remainingBufferSize--;
- }
-
- private Vertex retrieveFromCache(final Object externalID) {
- final Object internal = cache.getEntry(externalID);
- if (internal instanceof Vertex) {
- return (Vertex) internal;
- } else if (internal != null) { //its an internal id
- final Vertex v = baseGraph.V(internal).next();
- cache.set(v, externalID);
- return v;
- } else return null;
- }
-
- private Vertex getCachedVertex(final Object externalID) {
- final Vertex v = retrieveFromCache(externalID);
- if (v == null) throw new IllegalArgumentException("Vertex for given ID cannot be found: " + externalID);
- return v;
- }
-
- @Override
- public Vertex addVertex(final Object... keyValues) {
- final Object id = ElementHelper.getIdValue(keyValues).orElseThrow(() -> new IllegalArgumentException("Vertex id value cannot be null"));
- if (!incrementalLoading && retrieveFromCache(id) != null)
- throw new IllegalArgumentException("Vertex id already exists");
- nextElement();
-
- // if the vertexIdKey is not the T.id then append it as a name/value pair. this will overwrite what
- // is present in that field already
- final Object[] keysVals = T.id.getAccessor().equals(vertexIdKey) ? keyValues : ElementHelper.upsert(keyValues, vertexIdKey, id);
-
- // if the graph doesn't support vertex ids or the vertex id is not the T.id then remove that key
- // value pair as it will foul up insertion (i.e. an exception for graphs that don't support it and the
- // id will become the value of the vertex id which might not be expected.
- final Optional<Object[]> kvs = this.baseSupportsSuppliedVertexId && T.id.getAccessor().equals(vertexIdKey) ?
- Optional.ofNullable(keyValues) : ElementHelper.remove(T.id, keysVals);
-
- Vertex currentVertex;
- if (!incrementalLoading)
- currentVertex = kvs.isPresent() ? baseGraph.addVertex(kvs.get()) : baseGraph.addVertex();
- else {
- final Traversal<Vertex, Vertex> traversal = baseGraph.V().has(vertexIdKey, id);
- if (traversal.hasNext()) {
- final Vertex v = traversal.next();
- if (traversal.hasNext())
- throw new IllegalStateException(String.format("There is more than one vertex identified by %s=%s", vertexIdKey, id));
-
- // let the caller decide how to handle conflict
- kvs.ifPresent(keyvals -> existingVertexStrategy.accept(v, keyvals));
- currentVertex = v;
- } else
- currentVertex = kvs.isPresent() ? baseGraph.addVertex(kvs.get()) : baseGraph.addVertex();
- }
-
- cache.set(currentVertex, id);
-
- return new BatchVertex(id);
- }
-
- @Override
- public GraphTraversal<Edge, Edge> E(final Object... edgeIds) {
- throw retrievalNotSupported();
- }
-
- @Override
- public Iterators iterators() {
- return this;
- }
-
- @Override
- public Iterator<Vertex> vertexIterator(final Object... vertexIds) {
- if (vertexIds.length > 1)
- throw new IllegalArgumentException("BatchGraph only allows a single vertex id at one time");
- if ((this.previousOutVertexId != null) && (this.previousOutVertexId.equals(vertexIds[0]))) {
- return IteratorUtils.of(new BatchVertex(this.previousOutVertexId));
- } else {
- Vertex vertex = retrieveFromCache(vertexIds[0]);
- if (null == vertex) {
- if (!this.incrementalLoading) return Collections.emptyIterator();
- else {
- final Iterator<Vertex> iterator = this.baseGraph.V().has(this.vertexIdKey, vertexIds[0]);
- if (!iterator.hasNext()) return Collections.emptyIterator();
- vertex = iterator.next();
- if (iterator.hasNext())
- throw new IllegalStateException("There are multiple vertices with the provided id in the graph: " + vertexIds[0]);
- this.cache.set(vertex, vertexIds[0]);
- }
- }
- return IteratorUtils.of(new BatchVertex(vertexIds[0]));
- }
- }
-
- @Override
- public Iterator<Edge> edgeIterator(final Object... edgeIds) {
- throw retrievalNotSupported();
- }
-
- @Override
- public <T extends Traversal<S, S>, S> T of(final Class<T> traversalClass) {
- throw retrievalNotSupported();
- }
-
- @Override
- public GraphComputer compute(final Class... graphComputerClass) {
- throw Exceptions.graphComputerNotSupported();
- }
-
- @Override
- public Transaction tx() {
- return this.batchTransaction;
- }
-
- @Override
- public Variables variables() {
- throw Exceptions.variablesNotSupported();
- }
-
- @Override
- public Configuration configuration() {
- return new BaseConfiguration();
- }
-
- @Override
- public Features features() {
- return this.batchFeatures;
- }
-
- @Override
- public void close() throws Exception {
- baseGraph.close();
-
- // call reset after the close in case the close behavior fails
- reset();
- }
-
- private void reset() {
- currentEdge = null;
- currentEdgeCached = null;
- remainingBufferSize = 0;
- }
-
- public static <T extends Graph> Builder build(final T g) {
- return new Builder<>(g);
- }
-
- private class BatchTransaction implements Transaction {
- private final boolean supportsTx;
-
- public BatchTransaction() {
- supportsTx = baseGraph.features().graph().supportsTransactions();
- }
-
- @Override
- public Transaction onClose(final Consumer<Transaction> consumer) {
- throw new UnsupportedOperationException("Transaction behavior cannot be altered in batch mode - set the behavior on the base graph");
- }
-
- @Override
- public Transaction onReadWrite(final Consumer<Transaction> consumer) {
- throw new UnsupportedOperationException("Transaction behavior cannot be altered in batch mode - set the behavior on the base graph");
- }
-
- @Override
- public void close() {
- if (supportsTx) baseGraph.tx().close();
-
- // call reset after the close in case the close behavior fails
- reset();
- }
-
- @Override
- public void readWrite() {
- if (supportsTx) baseGraph.tx().readWrite();
- }
-
- @Override
- public boolean isOpen() {
- return !supportsTx || baseGraph.tx().isOpen();
- }
-
- @Override
- public <G extends Graph> G create() {
- throw new UnsupportedOperationException("Cannot start threaded transaction during batch loading");
- }
-
- @Override
- public <R> Workload<R> submit(final Function<Graph, R> work) {
- throw new UnsupportedOperationException("Cannot submit a workload during batch loading");
- }
-
- @Override
- public void rollback() {
- throw new UnsupportedOperationException("Cannot issue a rollback during batch loading");
- }
-
- @Override
- public void commit() {
- if (supportsTx) baseGraph.tx().commit();
-
- // call reset after the close in case the close behavior fails
- reset();
- }
-
- @Override
- public void open() {
- if (supportsTx) baseGraph.tx().open();
- }
- }
-
- private class BatchVertex implements Vertex, Vertex.Iterators, VertexTraversal {
-
- private final Object externalID;
-
- BatchVertex(final Object id) {
- if (id == null) throw new IllegalArgumentException("External id may not be null");
- externalID = id;
- }
-
- @Override
- public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) {
- if (!BatchVertex.class.isInstance(inVertex))
- throw new IllegalArgumentException("Given element was not created in this baseGraph");
- nextElement();
-
- final Vertex ov = getCachedVertex(externalID);
- final Vertex iv = getCachedVertex(inVertex.id());
-
- previousOutVertexId = externalID; //keep track of the previous out vertex id
-
- if (!incrementalLoading) {
- final Optional<Object[]> kvs = baseSupportsSuppliedEdgeId && T.id.getAccessor().equals(edgeIdKey) ?
- Optional.ofNullable(keyValues) : ElementHelper.remove(T.id, keyValues);
- currentEdgeCached = kvs.isPresent() ? ov.addEdge(label, iv, kvs.get()) : ov.addEdge(label, iv);
- } else {
- final Optional<Object> id = ElementHelper.getIdValue(keyValues);
- // if the edgeIdKey is not the Element.ID then append it as a name/value pair. this will overwrite what
- // is present in that field already
- final Object[] keysVals = id.isPresent() && T.id.getAccessor().equals(edgeIdKey) ? keyValues :
- id.isPresent() ? ElementHelper.upsert(keyValues, edgeIdKey, id.get()) : keyValues;
-
- // if the graph doesn't support edge ids or the edge id is not the Element.ID then remove that key
- // value pair as it will foul up insertion (i.e. an exception for graphs that don't support it and the
- // id will become the value of the edge id which might not be expected.
- final Optional<Object[]> kvs = baseSupportsSuppliedEdgeId && T.id.getAccessor().equals(edgeIdKey) ?
- Optional.ofNullable(keyValues) : ElementHelper.remove(T.id, keysVals);
-
- if (id.isPresent()) {
- final Traversal<Edge, Edge> traversal = baseGraph.E().has(edgeIdKey, id.get());
- if (traversal.hasNext()) {
- final Edge e = traversal.next();
- // let the user decide how to handle conflict
- kvs.ifPresent(keyvals -> existingEdgeStrategy.accept(e, keyvals));
- currentEdgeCached = e;
- } else
- currentEdgeCached = kvs.isPresent() ? ov.addEdge(label, iv, kvs.get()) : ov.addEdge(label, iv);
- } else {
- currentEdgeCached = kvs.isPresent() ? ov.addEdge(label, iv, kvs.get()) : ov.addEdge(label, iv);
- }
- }
-
- currentEdge = new BatchEdge();
-
- return currentEdge;
- }
-
- @Override
- public Object id() {
- return this.externalID;
- }
-
- @Override
- public Graph graph() {
- return getCachedVertex(externalID).graph();
- }
-
- @Override
- public String label() {
- return getCachedVertex(externalID).label();
- }
-
- @Override
- public void remove() {
- throw removalNotSupported();
- }
-
- @Override
- public Set<String> keys() {
- return getCachedVertex(externalID).keys();
- }
-
- @Override
- public <V> VertexProperty<V> property(final String key, final V value, final Object... keyValues) {
- return getCachedVertex(externalID).property(key, value, keyValues);
- }
-
- @Override
- public <V> VertexProperty<V> property(final String key) {
- return getCachedVertex(externalID).property(key);
- }
-
- @Override
- public <V> VertexProperty<V> property(final String key, final V value) {
- return getCachedVertex(externalID).property(key, value);
- }
-
- @Override
- public <V> V value(final String key) throws NoSuchElementException {
- return getCachedVertex(externalID).value(key);
- }
-
- @Override
- public Vertex.Iterators iterators() {
- return this;
- }
-
- @Override
- public Iterator<Edge> edgeIterator(final Direction direction, final String... edgeLabels) {
- throw retrievalNotSupported();
- }
-
- @Override
- public Iterator<Vertex> vertexIterator(final Direction direction, final String... labels) {
- throw retrievalNotSupported();
- }
-
- @Override
- public <V> Iterator<VertexProperty<V>> propertyIterator(final String... propertyKeys) {
- return getCachedVertex(externalID).iterators().propertyIterator(propertyKeys);
- }
- }
-
- private class BatchEdge implements Edge, Edge.Iterators {
-
-
- @Override
- public Graph graph() {
- return getWrappedEdge().graph();
- }
-
- @Override
- public Object id() {
- return getWrappedEdge().label();
- }
-
- @Override
- public String label() {
- return getWrappedEdge().label();
- }
-
- @Override
- public void remove() {
- throw removalNotSupported();
- }
-
- @Override
- public <V> Property<V> property(final String key) {
- return getWrappedEdge().property(key);
- }
-
- @Override
- public <V> Property<V> property(final String key, final V value) {
- return getWrappedEdge().property(key, value);
- }
-
- @Override
- public Set<String> keys() {
- return getWrappedEdge().keys();
- }
-
- @Override
- public <V> V value(final String key) throws NoSuchElementException {
- return getWrappedEdge().value(key);
- }
-
- private Edge getWrappedEdge() {
- if (this != currentEdge) {
- throw new UnsupportedOperationException("This edge is no longer in scope");
- }
- return currentEdgeCached;
- }
-
- @Override
- public Edge.Iterators iterators() {
- return this;
- }
-
- @Override
- public <V> Iterator<Property<V>> propertyIterator(final String... propertyKeys) {
- return getWrappedEdge().iterators().propertyIterator(propertyKeys);
- }
-
- @Override
- public Iterator<Vertex> vertexIterator(final Direction direction) {
- return getWrappedEdge().iterators().vertexIterator(direction);
- }
- }
-
- private static UnsupportedOperationException retrievalNotSupported() {
- return new UnsupportedOperationException("Retrieval operations are not supported during batch loading");
- }
-
- private static UnsupportedOperationException removalNotSupported() {
- return new UnsupportedOperationException("Removal operations are not supported during batch loading");
- }
-
- public static class Builder<G extends Graph> {
- private final G graphToLoad;
- private boolean incrementalLoading = false;
- private String vertexIdKey = T.id.getAccessor();
- private String edgeIdKey = T.id.getAccessor();
- private long bufferSize = DEFAULT_BUFFER_SIZE;
- private VertexIdType vertexIdType = VertexIdType.OBJECT;
- private BiConsumer<Element, Object[]> existingVertexStrategy = Exists.IGNORE;
- private BiConsumer<Element, Object[]> existingEdgeStrategy = Exists.IGNORE;
-
- private Builder(final G g) {
- if (null == g) throw new IllegalArgumentException("Graph may not be null");
- if (g instanceof BatchGraph)
- throw new IllegalArgumentException("BatchGraph cannot wrap another BatchGraph instance");
- this.graphToLoad = g;
- }
-
- /**
- * Sets the key to be used when setting the vertex id as a property on the respective vertex. If this
- * value is not set it defaults to {@link T#id}.
- *
- * @param key Key to be used.
- */
- public Builder vertexIdKey(final String key) {
- if (null == key) throw new IllegalArgumentException("Key cannot be null");
- this.vertexIdKey = key;
- return this;
- }
-
- /**
- * Sets the key to be used when setting the edge id as a property on the respective edge.
- * If the key is null, then no property will be set.
- *
- * @param key Key to be used.
- */
- public Builder edgeIdKey(final String key) {
- if (null == key) throw new IllegalArgumentException("Optional value for key cannot be null");
- this.edgeIdKey = key;
- return this;
- }
-
- /**
- * Number of mutations to perform between calls to {@link com.tinkerpop.gremlin.structure.Transaction#commit}.
- */
- public Builder bufferSize(long bufferSize) {
- if (bufferSize <= 0) throw new IllegalArgumentException("BufferSize must be positive");
- this.bufferSize = bufferSize;
- return this;
- }
-
- /**
- * Sets the type of the id used for the vertex which in turn determines the cache type that is used.
- */
- public Builder vertexIdType(final VertexIdType type) {
- if (null == type) throw new IllegalArgumentException("Type may not be null");
- this.vertexIdType = type;
- return this;
- }
-
- /**
- * Sets whether the graph loaded through this instance of {@link BatchGraph} is loaded from scratch
- * (i.e. the wrapped graph is initially empty) or whether graph is loaded incrementally into an
- * existing graph.
- * <p/>
- * In the former case, BatchGraph does not need to check for the existence of vertices with the wrapped
- * graph but only needs to consult its own cache which can be significantly faster. In the latter case,
- * the cache is checked first but an additional check against the wrapped graph may be necessary if
- * the vertex does not exist.
- * <p/>
- * By default, BatchGraph assumes that the data is loaded from scratch.
- */
- public Builder incrementalLoading(final boolean incrementalLoading) {
- this.incrementalLoading = incrementalLoading;
- return this;
- }
-
- /**
- * Sets whether the graph loaded through this instance of {@link BatchGraph} is loaded from scratch
- * (i.e. the wrapped graph is initially empty) or whether graph is loaded incrementally into an
- * existing graph.
- * <p/>
- * In the former case, BatchGraph does not need to check for the existence of vertices with the wrapped
- * graph but only needs to consult its own cache which can be significantly faster. In the latter case,
- * the cache is checked first but an additional check against the wrapped graph may be necessary if
- * the vertex does not exist.
- * <p/>
- * By default, BatchGraph assumes that the data is loaded from scratch.
- */
- public Builder incrementalLoading(final boolean incrementalLoading,
- final BiConsumer<Element, Object[]> existingVertexStrategy,
- final BiConsumer<Element, Object[]> existingEdgeStrategy) {
- this.incrementalLoading = incrementalLoading;
- this.existingVertexStrategy = existingVertexStrategy;
- this.existingEdgeStrategy = existingEdgeStrategy;
- return this;
- }
-
- public BatchGraph<G> create() {
- return new BatchGraph<>(graphToLoad, vertexIdType, bufferSize, vertexIdKey, edgeIdKey,
- incrementalLoading, this.existingVertexStrategy, this.existingEdgeStrategy);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1545201f/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/Exists.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/Exists.java b/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/Exists.java
deleted file mode 100644
index 08d5ee1..0000000
--- a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/Exists.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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 com.tinkerpop.gremlin.structure.util.batch;
-
-import com.tinkerpop.gremlin.structure.Element;
-import com.tinkerpop.gremlin.structure.Vertex;
-import com.tinkerpop.gremlin.structure.util.ElementHelper;
-
-import java.util.function.BiConsumer;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public enum Exists implements BiConsumer<Element, Object[]> {
- IGNORE {
- @Override
- public void accept(final Element element, final Object[] objects) {
- // do nothing
- }
- },
- THROW {
- @Override
- public void accept(final Element element, final Object[] objects) {
- throw new IllegalStateException(String.format(
- "Element of type %s with id of [%s] was not expected to exist in target graph",
- element.getClass().getSimpleName(), element.id()));
- }
- },
- OVERWRITE {
- @Override
- public void accept(final Element element, final Object[] keyValues) {
- ElementHelper.attachProperties(element, keyValues);
- }
- },
- OVERWRITE_SINGLE {
- @Override
- public void accept(final Element element, final Object[] keyValues) {
- if (element instanceof Vertex)
- ElementHelper.attachSingleProperties((Vertex) element, keyValues);
- else
- ElementHelper.attachProperties(element, keyValues);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1545201f/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/VertexIdType.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/VertexIdType.java b/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/VertexIdType.java
deleted file mode 100644
index 30eb2f8..0000000
--- a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/VertexIdType.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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 com.tinkerpop.gremlin.structure.util.batch;
-
-import com.tinkerpop.gremlin.structure.util.batch.cache.LongIDVertexCache;
-import com.tinkerpop.gremlin.structure.util.batch.cache.ObjectIDVertexCache;
-import com.tinkerpop.gremlin.structure.util.batch.cache.StringIDVertexCache;
-import com.tinkerpop.gremlin.structure.util.batch.cache.URLCompression;
-import com.tinkerpop.gremlin.structure.util.batch.cache.VertexCache;
-
-/**
- * Type of vertex ids expected by BatchGraph. The default is IdType.OBJECT.
- * Use the IdType that best matches the used vertex id types in order to save sideEffects.
- *
- * @author Matthias Broecheler (http://www.matthiasb.com)
- */
-public enum VertexIdType {
-
- OBJECT {
- @Override
- public VertexCache getVertexCache() {
- return new ObjectIDVertexCache();
- }
- },
-
- NUMBER {
- @Override
- public VertexCache getVertexCache() {
- return new LongIDVertexCache();
- }
- },
-
- STRING {
- @Override
- public VertexCache getVertexCache() {
- return new StringIDVertexCache();
- }
- },
-
- URL {
- @Override
- public VertexCache getVertexCache() {
- return new StringIDVertexCache(new URLCompression());
-
- }
- };
-
- public abstract VertexCache getVertexCache();
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1545201f/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/cache/AbstractIDVertexCache.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/cache/AbstractIDVertexCache.java b/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/cache/AbstractIDVertexCache.java
deleted file mode 100644
index 4dbb618..0000000
--- a/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/batch/cache/AbstractIDVertexCache.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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 com.tinkerpop.gremlin.structure.util.batch.cache;
-
-import com.tinkerpop.gremlin.structure.Vertex;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @author Matthias Broecheler (http://www.matthiasb.com)
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-abstract class AbstractIDVertexCache implements VertexCache {
-
- static final int INITIAL_CAPACITY = 1000;
- static final int INITIAL_TX_CAPACITY = 100;
-
- private final Map<Object, Object> map;
- private final Set<Object> mapKeysInCurrentTx;
-
- AbstractIDVertexCache() {
- map = new HashMap<>(INITIAL_CAPACITY);
- mapKeysInCurrentTx = new HashSet<>(INITIAL_TX_CAPACITY);
- }
-
- @Override
- public Object getEntry(final Object externalId) {
- return map.get(externalId);
- }
-
- @Override
- public void set(final Vertex vertex, final Object externalId) {
- setId(vertex, externalId);
- }
-
- @Override
- public void setId(final Object vertexId, final Object externalId) {
- map.put(externalId, vertexId);
- mapKeysInCurrentTx.add(externalId);
- }
-
- @Override
- public boolean contains(final Object externalId) {
- return map.containsKey(externalId);
- }
-
- @Override
- public void newTransaction() {
- for (Object id : mapKeysInCurrentTx) {
- Object o = map.get(id);
- assert null != o;
- if (o instanceof Vertex) {
- Vertex v = (Vertex) o;
- map.put(id, v.id());
- }
- }
- mapKeysInCurrentTx.clear();
- }
-}