<commit_before>package com.tinkerpop.blueprints.tinkergraph;

import com.tinkerpop.blueprints.Annotations;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.Property;
import com.tinkerpop.blueprints.Strategy;
import com.tinkerpop.blueprints.Transaction;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.computer.GraphComputer;
import com.tinkerpop.blueprints.query.GraphQuery;
import com.tinkerpop.blueprints.strategy.GraphStrategy;
import com.tinkerpop.blueprints.util.ElementHelper;
import com.tinkerpop.blueprints.util.StringFactory;
import org.apache.commons.configuration.Configuration;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

/**
 * An in-memory, reference implementation of the property graph interfaces provided by Blueprints.
 *
 * @author <NAME> (http://markorodriguez.com)
 * @author <NAME> (http://stephen.genoprime.com)
 */
public class TinkerGraph implements Graph, Serializable {

    protected Long currentId = -1l;
    protected Map<String, Vertex> vertices = new HashMap<>();
    protected Map<String, Edge> edges = new HashMap<>();
    protected Annotations annotations = new TinkerAnnotations();

    protected TinkerIndex<TinkerVertex> vertexIndex = new TinkerIndex<>(this, TinkerVertex.class);
    protected TinkerIndex<TinkerEdge> edgeIndex = new TinkerIndex<>(this, TinkerEdge.class);

    protected transient Strategy strategy = new Strategy.Simple();

    private transient Strategy.Context<Graph> graphContext = new Strategy.Context<Graph>(this, this);

    /**
     * An empty private constructor that initializes {@link TinkerGraph} with no {@link GraphStrategy}.  Primarily
     * used for purposes of serialization issues.
     */
    private TinkerGraph() {
        this(Optional.empty());
    }

    /**
     * Internally create a new {@link TinkerGraph} instance.
     * <p/>
     * <b>Reference Implementation Help:</b> All Graph implementations are to be constructed through the open() method
     * and therefore {@link Graph} implementations should maintain a private or protected constructor.  This rule is
     * enforced by the Blueprints Test suite.<commit_msg>Add javadoc and reference implementation help.<commit_after>package com.tinkerpop.blueprints.tinkergraph;

import com.tinkerpop.blueprints.Annotations;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.Property;
import com.tinkerpop.blueprints.Strategy;
import com.tinkerpop.blueprints.Transaction;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.computer.GraphComputer;
import com.tinkerpop.blueprints.query.GraphQuery;
import com.tinkerpop.blueprints.strategy.GraphStrategy;
import com.tinkerpop.blueprints.util.ElementHelper;
import com.tinkerpop.blueprints.util.StringFactory;
import org.apache.commons.configuration.Configuration;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

/**
 * An in-memory, reference implementation of the property graph interfaces provided by Blueprints.
 *
 * @author <NAME> (http://markorodriguez.com)
 * @author <NAME> (http://stephen.genoprime.com)
 */
public class TinkerGraph implements Graph, Serializable {

    protected Long currentId = -1l;
    protected Map<String, Vertex> vertices = new HashMap<>();
    protected Map<String, Edge> edges = new HashMap<>();
    protected Annotations annotations = new TinkerAnnotations();

    protected TinkerIndex<TinkerVertex> vertexIndex = new TinkerIndex<>(this, TinkerVertex.class);
    protected TinkerIndex<TinkerEdge> edgeIndex = new TinkerIndex<>(this, TinkerEdge.class);

    /**
     * Define the method by which {@link GraphStrategy} implementations are executed.
     * <p/>
     * <b>Reference Implementation Help:</b> Implementers may use the existing implementations on the {@link Strategy}
     * class or write their own if deemed necessary.
     */
    protected transient Strategy strategy = new Strategy.Simple();

    /**
     * The context to be passed to the {@link GraphStrategy} when triggered.  The context wraps the {@link Graph}
     * instance providing that reference to the {@link GraphStrategy}.
     * <p/>
     * <b>Reference Implementation Help:</b> It is best to declare this field once and re-use for the life of the
     * {@link Graph} rather than construct the new instances at the time they are needed.
     */
    private transient Strategy.Context<Graph> graphContext = new Strategy.Context<Graph>(this, this);

    /**
     * An empty private constructor that initializes {@link TinkerGraph} with no {@link GraphStrategy}.  Primarily
     * used for purposes of serialization issues.
     */
    private TinkerGraph() {
        this(Optional.empty());
    }

    /**
     * Internally create a new {@link TinkerGraph} instance.
     * <p/>
     * <b>Reference Implementation Help:</b> All Graph implementations are to be constructed through the open() method
     * and therefore {@link Graph} implementations should maintain a private or protected constructor.  This rule is
     * enforced by the Blueprints Test suite.
{'fraction_non_alphanumeric': 0.09783393501805054, 'fraction_numerical': 0.00036101083032490973, 'mean_word_length': 4.453740157480315, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2503263', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1484, 'n_words': 456}