// Path: titan-core/src/main/java/com/thinkaurelius/titan/graphdb/relations/RelationCache.java
// public class RelationCache implements Iterable<LongObjectCursor<Object>> {
// 
//     private static final LongObjectHashMap<Object> EMPTY = new LongObjectHashMap<>(0);
// 
//     public final Direction direction;
//     public final long typeId;
//     public final long relationId;
//     private final Object other;
//     private final LongObjectHashMap<Object> properties;
// 
//     public RelationCache(final Direction direction, final long typeId, final long relationId,
//                          final Object other, final LongObjectHashMap<Object> properties) {
//         this.direction = direction;
//         this.typeId = typeId;
//         this.relationId = relationId;
//         this.other = other;
//         this.properties = (properties == null || properties.size() > 0) ? properties : EMPTY;
//     }
// 
//     public RelationCache(final Direction direction, final long typeId, final long relationId,
//                          final Object other) {
//         this(direction,typeId,relationId,other,null);
//     }
// 
//     @SuppressWarnings("unchecked")
//     public <O> O get(long key) {
//         return (O) properties.get(key);
//     }
// 
//     public boolean hasProperties() {
//         return properties != null && !properties.isEmpty();
//     }
// 
//     public int numProperties() {
//         return properties.size();
//     }
// 
//     public Object getValue() {
//         return other;
//     }
// 
//     public Long getOtherVertexId() {
//         return (Long) other;
//     }
// 
//     public Iterator<LongObjectCursor<Object>> propertyIterator() {
//         return properties.iterator();
//     }
// 
//     @Override
//     public Iterator<LongObjectCursor<Object>> iterator() {
//         return propertyIterator();
//     }
// 
//     @Override
//     public String toString() {
//          return typeId + "-" + direction + "->" + other + ":" + relationId;
//     }
// 
// }


import com.carrotsearch.hppc.cursors.LongObjectCursor;
import com.google.common.base.Preconditions;
import com.thinkaurelius.titan.core.*;
import com.thinkaurelius.titan.diskstorage.Entry;
import com.thinkaurelius.titan.diskstorage.StaticBuffer;
import com.thinkaurelius.titan.graphdb.database.RelationReader;
import com.thinkaurelius.titan.graphdb.idmanagement.IDManager;
import com.thinkaurelius.titan.graphdb.internal.InternalRelationType;
import com.thinkaurelius.titan.graphdb.relations.RelationCache;
import com.thinkaurelius.titan.graphdb.types.TypeInspector;
import com.thinkaurelius.titan.hadoop.formats.util.input.SystemTypeInspector;
import com.thinkaurelius.titan.hadoop.formats.util.input.TitanHadoopSetup;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerEdge;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.NoSuchElementException;
package com.thinkaurelius.titan.hadoop.formats.util;



public class TitanVertexDeserializer implements AutoCloseable {

    private final TitanHadoopSetup setup;
    private final TypeInspector typeManager;
    private final SystemTypeInspector systemTypes;
    private final IDManager idManager;
    private final boolean verifyVertexExistence = false;

    private static final Logger log =
            LoggerFactory.getLogger(TitanVertexDeserializer.class);

    public TitanVertexDeserializer(final TitanHadoopSetup setup) {
        this.setup = setup;
        this.typeManager = setup.getTypeInspector();
        this.systemTypes = setup.getSystemTypeInspector();
        this.idManager = setup.getIDManager();
    }

    // Read a single row from the edgestore and create a TinkerVertex corresponding to the row
    // The neighboring vertices are represented by DetachedVertex instances
    public TinkerVertex readHadoopVertex(final StaticBuffer key, Iterable<Entry> entries) {

        // Convert key to a vertex ID
        final long vertexId = idManager.getKeyID(key);
        Preconditions.checkArgument(vertexId > 0);

        // Partitioned vertex handling
        if (idManager.isPartitionedVertex(vertexId)) {
            Preconditions.checkState(setup.getFilterPartitionedVertices(),
                    "Read partitioned vertex (ID=%s), but partitioned vertex filtering is disabled.", vertexId);
            log.debug("Skipping partitioned vertex with ID {}", vertexId);
            return null;
        }

        // Create TinkerVertex
        TinkerGraph tg = TinkerGraph.open();

        boolean foundVertexState = !verifyVertexExistence;

        TinkerVertex tv = null;

        // Iterate over edgestore columns to find the vertex's label relation
        for (final Entry data : entries) {
            RelationReader relationReader = setup.getRelationReader(vertexId);
// Path: titan-core/src/main/java/com/thinkaurelius/titan/graphdb/relations/RelationCache.java
// public class RelationCache implements Iterable<LongObjectCursor<Object>> {
// 
//     private static final LongObjectHashMap<Object> EMPTY = new LongObjectHashMap<>(0);
// 
//     public final Direction direction;
//     public final long typeId;
//     public final long relationId;
//     private final Object other;
//     private final LongObjectHashMap<Object> properties;
// 
//     public RelationCache(final Direction direction, final long typeId, final long relationId,
//                          final Object other, final LongObjectHashMap<Object> properties) {
//         this.direction = direction;
//         this.typeId = typeId;
//         this.relationId = relationId;
//         this.other = other;
//         this.properties = (properties == null || properties.size() > 0) ? properties : EMPTY;
//     }
// 
//     public RelationCache(final Direction direction, final long typeId, final long relationId,
//                          final Object other) {
//         this(direction,typeId,relationId,other,null);
//     }
// 
//     @SuppressWarnings("unchecked")
//     public <O> O get(long key) {
//         return (O) properties.get(key);
//     }
// 
//     public boolean hasProperties() {
//         return properties != null && !properties.isEmpty();
//     }
// 
//     public int numProperties() {
//         return properties.size();
//     }
// 
//     public Object getValue() {
//         return other;
//     }
// 
//     public Long getOtherVertexId() {
//         return (Long) other;
//     }
// 
//     public Iterator<LongObjectCursor<Object>> propertyIterator() {
//         return properties.iterator();
//     }
// 
//     @Override
//     public Iterator<LongObjectCursor<Object>> iterator() {
//         return propertyIterator();
//     }
// 
//     @Override
//     public String toString() {
//          return typeId + "-" + direction + "->" + other + ":" + relationId;
//     }
// 
// }


// Path: titan-hadoop-parent/titan-hadoop-core/src/main/java/com/thinkaurelius/titan/hadoop/formats/util/TitanVertexDeserializer.java
import com.carrotsearch.hppc.cursors.LongObjectCursor;
import com.google.common.base.Preconditions;
import com.thinkaurelius.titan.core.*;
import com.thinkaurelius.titan.diskstorage.Entry;
import com.thinkaurelius.titan.diskstorage.StaticBuffer;
import com.thinkaurelius.titan.graphdb.database.RelationReader;
import com.thinkaurelius.titan.graphdb.idmanagement.IDManager;
import com.thinkaurelius.titan.graphdb.internal.InternalRelationType;
import com.thinkaurelius.titan.graphdb.relations.RelationCache;
import com.thinkaurelius.titan.graphdb.types.TypeInspector;
import com.thinkaurelius.titan.hadoop.formats.util.input.SystemTypeInspector;
import com.thinkaurelius.titan.hadoop.formats.util.input.TitanHadoopSetup;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerEdge;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.NoSuchElementException;

package com.thinkaurelius.titan.hadoop.formats.util;



public class TitanVertexDeserializer implements AutoCloseable {

    private final TitanHadoopSetup setup;
    private final TypeInspector typeManager;
    private final SystemTypeInspector systemTypes;
    private final IDManager idManager;
    private final boolean verifyVertexExistence = false;

    private static final Logger log =
            LoggerFactory.getLogger(TitanVertexDeserializer.class);

    public TitanVertexDeserializer(final TitanHadoopSetup setup) {
        this.setup = setup;
        this.typeManager = setup.getTypeInspector();
        this.systemTypes = setup.getSystemTypeInspector();
        this.idManager = setup.getIDManager();
    }

    // Read a single row from the edgestore and create a TinkerVertex corresponding to the row
    // The neighboring vertices are represented by DetachedVertex instances
    public TinkerVertex readHadoopVertex(final StaticBuffer key, Iterable<Entry> entries) {

        // Convert key to a vertex ID
        final long vertexId = idManager.getKeyID(key);
        Preconditions.checkArgument(vertexId > 0);

        // Partitioned vertex handling
        if (idManager.isPartitionedVertex(vertexId)) {
            Preconditions.checkState(setup.getFilterPartitionedVertices(),
                    "Read partitioned vertex (ID=%s), but partitioned vertex filtering is disabled.", vertexId);
            log.debug("Skipping partitioned vertex with ID {}", vertexId);
            return null;
        }

        // Create TinkerVertex
        TinkerGraph tg = TinkerGraph.open();

        boolean foundVertexState = !verifyVertexExistence;

        TinkerVertex tv = null;

        // Iterate over edgestore columns to find the vertex's label relation
        for (final Entry data : entries) {
            RelationReader relationReader = setup.getRelationReader(vertexId);
            final RelationCache relation = relationReader.parseRelation(data, false, typeManager);