<commit_before>/*
 * 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.structure.io;

import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage;
import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
import org.apache.tinkerpop.gremlin.process.traversal.Operator;
import org.apache.tinkerpop.gremlin.process.traversal.Order;
import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.Pop;
import org.apache.tinkerpop.gremlin.process.traversal.SackFunctions;
import org.apache.tinkerpop.gremlin.process.traversal.Scope;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalOptionParent;
import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalMetrics;
import org.apache.tinkerpop.gremlin.process.traversal.util.MutableMetrics;
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics;
import org.apache.tinkerpop.gremlin.structure.Column;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONCompatibility;
import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoCompatibility;
import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;

import java.io.File;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.InetAddress;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.MonthDay;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.Period;
import java.time.Year;
import java.time.YearMonth;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Defines the supported types for IO and the versions (and configurations) to which they apply and are tested.
 *
 * @author <NAME> (http://stephen.genoprime.com)
 */
public class Model {

    private static final List<Compatibility> ALL = Collections.unmodifiableList(new ArrayList<Compatibility>() {{
        addAll(Arrays.asList(GraphSONCompatibility.values()));
        addAll(Arrays.asList(GryoCompatibility.values()));
    }});

    private static final List<Compatibility> GRAPHSON_ONLY = Collections.unmodifiableList(new ArrayList<Compatibility>() {{
        addAll(Arrays.asList(GraphSONCompatibility.values()));
    }});

    private static final List<Compatibility> UNTYPED_GRAPHSON_ONLY = Collections.unmodifiableList(new ArrayList<Compatibility>() {{
        add(GraphSONCompatibility.V1D0_3_2_3);
        add(GraphSONCompatibility.V1D0_3_3_0);
        add(GraphSONCompatibility.V2D0_NO_TYPE_3_2_3);
        add(GraphSONCompatibility.V2D0_NO_TYPE_3_3_0);
    }});

    private static final List<Compatibility> GRYO_ONLY = Collections.unmodifiableList(new ArrayList<Compatibility>() {{
        addAll(Arrays.asList(GryoCompatibility.values()));
    }});

    private static final Model model = new Model();

    private final Map<String, List<Entry>> entries = new HashMap<>();
    
    private Model() {
        final Graph graph = TinkerFactory.createTheCrew();
        final GraphTraversalSource g = graph.traversal();

        // IMPORTANT - the "title" or name of the Entry needs to be unique
        addCoreEntry(File.class, "Class", GryoCompatibility.V1D0_3_2_3, GryoCompatibility.V1D0_3_3_0);
        addCoreEntry(new Date(1481750076295L), "Date");
        addCoreEntry(100.00d, "Double");
        addCoreEntry(100.00f, "Float");
        addCoreEntry(100, "Integer");
        addCoreEntry(100L, "Long");
        addCoreEntry(new java.sql.Timestamp(1481750076295L), "Timestamp", GryoCompatibility.V1D0_3_2_3, GryoCompatibility.V1D0_3_3_0);
        addCoreEntry(UUID.fromString("41d2e28a-20a4-4ab0-b379-d810dede3786"), "UUID");

        addGraphStructureEntry(graph.edges().next(), "Edge");
        addGraphStructureEntry(g.V().out().out().path().next(), "Path");
        addGraphStructureEntry(graph.edges().next().properties().next(), "Property");
        addEntry("Graph Structure", StarGraph.of(graph.vertices().next()), "StarGraph", "", GRYO_ONLY);
        addEntry("Graph Structure", graph, "TinkerGraph", "`TinkerGraph` has a custom serializer that is registered as part of the `TinkerIoRegistry`.", Collections.emptyList());
        addEntry("Graph Structure", g.V().out().out().tree().next(), "Tree", "", GRYO_ONLY);
        addGraphStructureEntry(graph.vertices().next(), "Vertex");
        addGraphStructureEntry(graph.vertices().next().properties().next(), "VertexProperty");

        addGraphProcessEntry(SackFunctions.Barrier.normSack, "Barrier", "", GRYO_ONLY);
        addGraphProcessEntry(new Bytecode.Binding("x", 1), "Binding", "A \"Binding\" refers to a `Bytecode.Binding`.");
        addGraphProcessEntry(g.V().hasLabel("person").out().in().tree().asAdmin().getBytecode(), "Bytecode", "The following `Bytecode` example represents the traversal of `g.V().hasLabel('person').out().in().tree()`. Obviously the serialized `Bytecode` woudl be quite different for the endless variations of commands that could be used together in the Gremlin language.");
        addGraphProcessEntry(VertexProperty.Cardinality.list, "Cardinality");
        addGraphProcessEntry(Column.keys, "Column", "", GRYO_ONLY);
        addGraphProcessEntry(Direction.OUT, "Direction");
        addGraphProcessEntry(Operator.sum, "Operator", "", GRYO_ONLY);
        addGraphProcessEntry(Order.incr, "Order", "", GRYO_ONLY);
        addGraphProcessEntry(TraversalOptionParent.Pick.any, "Pick");
        addGraphProcessEntry(Pop.all, "Pop");
        addGraphProcessEntry(org.apache.tinkerpop.gremlin.util.function.Lambda.function("{ it.get() }"), "Lambda");
        final TraversalMetrics tm = createStaticTraversalMetrics();
        final MutableMetrics metrics = new MutableMetrics(tm.getMetrics("7.0.0()"));
        metrics.addNested(new MutableMetrics(tm.getMetrics("3.0.0()")));
        addGraphProcessEntry(metrics, "Metrics");
        addGraphProcessEntry(P.gt(0), "P");
        addGraphProcessEntry(P.gt(0).and(P.lt(10)), "P and", "", GRAPHSON_ONLY);
        addGraphProcessEntry(P.gt(0).or(P.within(-1, -10, -100)), "P or", "", GRAPHSON_ONLY);
        addGraphProcessEntry(Scope.local, "Scope");
        addGraphProcessEntry(T.label, "T", "", GRYO_ONLY);
        addGraphProcessEntry(createStaticTraversalMetrics(), "TraversalMetrics");
        addGraphProcessEntry(g.V().hasLabel("person").asAdmin().nextTraverser(), "Traverser");

        final Map<String,Object> requestBindings = new HashMap<>();
        requestBindings.put("x", 1);

        final Map<String,Object> requestAliases = new HashMap<>();<commit_msg>TINKERPOP-1130 Enabled GraphSON serialization tests for enums<commit_after>/*
 * 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.structure.io;

import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage;
import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
import org.apache.tinkerpop.gremlin.process.traversal.Operator;
import org.apache.tinkerpop.gremlin.process.traversal.Order;
import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.Pop;
import org.apache.tinkerpop.gremlin.process.traversal.SackFunctions;
import org.apache.tinkerpop.gremlin.process.traversal.Scope;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalOptionParent;
import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalMetrics;
import org.apache.tinkerpop.gremlin.process.traversal.util.MutableMetrics;
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics;
import org.apache.tinkerpop.gremlin.structure.Column;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONCompatibility;
import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoCompatibility;
import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;

import java.io.File;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.InetAddress;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.MonthDay;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.Period;
import java.time.Year;
import java.time.YearMonth;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Defines the supported types for IO and the versions (and configurations) to which they apply and are tested.
 *
 * @author <NAME> (http://stephen.genoprime.com)
 */
public class Model {

    private static final List<Compatibility> ALL = Collections.unmodifiableList(new ArrayList<Compatibility>() {{
        addAll(Arrays.asList(GraphSONCompatibility.values()));
        addAll(Arrays.asList(GryoCompatibility.values()));
    }});

    private static final List<Compatibility> GRAPHSON_ONLY = Collections.unmodifiableList(new ArrayList<Compatibility>() {{
        addAll(Arrays.asList(GraphSONCompatibility.values()));
    }});

    private static final List<Compatibility> UNTYPED_GRAPHSON_ONLY = Collections.unmodifiableList(new ArrayList<Compatibility>() {{
        add(GraphSONCompatibility.V1D0_3_2_3);
        add(GraphSONCompatibility.V1D0_3_3_0);
        add(GraphSONCompatibility.V2D0_NO_TYPE_3_2_3);
        add(GraphSONCompatibility.V2D0_NO_TYPE_3_3_0);
    }});

    private static final List<Compatibility> GRYO_ONLY = Collections.unmodifiableList(new ArrayList<Compatibility>() {{
        addAll(Arrays.asList(GryoCompatibility.values()));
    }});

    private static final Model model = new Model();

    private final Map<String, List<Entry>> entries = new HashMap<>();
    
    private Model() {
        final Graph graph = TinkerFactory.createTheCrew();
        final GraphTraversalSource g = graph.traversal();

        // IMPORTANT - the "title" or name of the Entry needs to be unique
        addCoreEntry(File.class, "Class", GryoCompatibility.V1D0_3_2_3, GryoCompatibility.V1D0_3_3_0);
        addCoreEntry(new Date(1481750076295L), "Date");
        addCoreEntry(100.00d, "Double");
        addCoreEntry(100.00f, "Float");
        addCoreEntry(100, "Integer");
        addCoreEntry(100L, "Long");
        addCoreEntry(new java.sql.Timestamp(1481750076295L), "Timestamp", GryoCompatibility.V1D0_3_2_3, GryoCompatibility.V1D0_3_3_0);
        addCoreEntry(UUID.fromString("41d2e28a-20a4-4ab0-b379-d810dede3786"), "UUID");

        addGraphStructureEntry(graph.edges().next(), "Edge");
        addGraphStructureEntry(g.V().out().out().path().next(), "Path");
        addGraphStructureEntry(graph.edges().next().properties().next(), "Property");
        addEntry("Graph Structure", StarGraph.of(graph.vertices().next()), "StarGraph", "", GRYO_ONLY);
        addEntry("Graph Structure", graph, "TinkerGraph", "`TinkerGraph` has a custom serializer that is registered as part of the `TinkerIoRegistry`.", Collections.emptyList());
        addEntry("Graph Structure", g.V().out().out().tree().next(), "Tree", "", GRYO_ONLY);
        addGraphStructureEntry(graph.vertices().next(), "Vertex");
        addGraphStructureEntry(graph.vertices().next().properties().next(), "VertexProperty");

        addGraphProcessEntry(SackFunctions.Barrier.normSack, "Barrier", "");
        addGraphProcessEntry(new Bytecode.Binding("x", 1), "Binding", "A \"Binding\" refers to a `Bytecode.Binding`.");
        addGraphProcessEntry(g.V().hasLabel("person").out().in().tree().asAdmin().getBytecode(), "Bytecode", "The following `Bytecode` example represents the traversal of `g.V().hasLabel('person').out().in().tree()`. Obviously the serialized `Bytecode` woudl be quite different for the endless variations of commands that could be used together in the Gremlin language.");
        addGraphProcessEntry(VertexProperty.Cardinality.list, "Cardinality");
        addGraphProcessEntry(Column.keys, "Column", "");
        addGraphProcessEntry(Direction.OUT, "Direction");
        addGraphProcessEntry(Operator.sum, "Operator", "");
        addGraphProcessEntry(Order.incr, "Order", "");
        addGraphProcessEntry(TraversalOptionParent.Pick.any, "Pick");
        addGraphProcessEntry(Pop.all, "Pop");
        addGraphProcessEntry(org.apache.tinkerpop.gremlin.util.function.Lambda.function("{ it.get() }"), "Lambda");
        final TraversalMetrics tm = createStaticTraversalMetrics();
        final MutableMetrics metrics = new MutableMetrics(tm.getMetrics("7.0.0()"));
        metrics.addNested(new MutableMetrics(tm.getMetrics("3.0.0()")));
        addGraphProcessEntry(metrics, "Metrics");
        addGraphProcessEntry(P.gt(0), "P");
        addGraphProcessEntry(P.gt(0).and(P.lt(10)), "P and", "", GRAPHSON_ONLY);
        addGraphProcessEntry(P.gt(0).or(P.within(-1, -10, -100)), "P or", "", GRAPHSON_ONLY);
        addGraphProcessEntry(Scope.local, "Scope");
        addGraphProcessEntry(T.label, "T", "");
        addGraphProcessEntry(createStaticTraversalMetrics(), "TraversalMetrics");
        addGraphProcessEntry(g.V().hasLabel("person").asAdmin().nextTraverser(), "Traverser");

        final Map<String,Object> requestBindings = new HashMap<>();
        requestBindings.put("x", 1);

        final Map<String,Object> requestAliases = new HashMap<>();
{'fraction_non_alphanumeric': 0.1274741238423824, 'fraction_numerical': 0.015374372011379457, 'mean_word_length': 4.819654808030997, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1896211', 'n_tokens_mistral': 5190, 'n_tokens_neox': 4936, 'n_words': 992}