Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1592 [created] 65a51d3d8


Added DeflatedXXX classes for the new withDetachment() model for TinkerPop 
3.3.0.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/65a51d3d
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/65a51d3d
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/65a51d3d

Branch: refs/heads/TINKERPOP-1592
Commit: 65a51d3d86d3d0d18e85dacd409f7f0efb0c771a
Parents: 7d2b46b
Author: Marko A. Rodriguez <okramma...@gmail.com>
Authored: Mon Jun 26 10:50:51 2017 -0600
Committer: Marko A. Rodriguez <okramma...@gmail.com>
Committed: Mon Jun 26 10:50:51 2017 -0600

----------------------------------------------------------------------
 .../process/traversal/TraversalSource.java      |   8 ++
 .../decoration/HaltedTraverserStrategy.java     |  14 +++
 .../structure/util/deflated/DeflatedEdge.java   | 101 ++++++++++++++++
 .../util/deflated/DeflatedElement.java          | 104 +++++++++++++++++
 .../util/deflated/DeflatedFactory.java          |  82 +++++++++++++
 .../structure/util/deflated/DeflatedPath.java   |  65 +++++++++++
 .../util/deflated/DeflatedProperty.java         |  91 +++++++++++++++
 .../structure/util/deflated/DeflatedVertex.java | 116 +++++++++++++++++++
 .../util/deflated/DeflatedVertexProperty.java   | 103 ++++++++++++++++
 9 files changed, 684 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/65a51d3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java
index d20ce10..ab37cfd 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java
@@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.process.computer.Computer;
 import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
 import 
org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy;
 import org.apache.tinkerpop.gremlin.process.remote.RemoteConnection;
+import 
org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.HaltedTraverserStrategy;
 import 
org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SackStrategy;
 import 
org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SideEffectStrategy;
 import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -31,7 +32,9 @@ import 
org.apache.tinkerpop.gremlin.util.function.ConstantSupplier;
 
 import java.io.Serializable;
 import java.lang.reflect.Constructor;
+import java.util.Map;
 import java.util.Optional;
+import java.util.Set;
 import java.util.function.BinaryOperator;
 import java.util.function.Supplier;
 import java.util.function.UnaryOperator;
@@ -92,6 +95,7 @@ public interface TraversalSource extends Cloneable, 
AutoCloseable {
         public static final String withComputer = "withComputer";
         public static final String withSideEffect = "withSideEffect";
         public static final String withRemote = "withRemote";
+        public static final String withDetachment = "withDetachment";
     }
 
     /////////////////////////////
@@ -173,6 +177,10 @@ public interface TraversalSource extends Cloneable, 
AutoCloseable {
         return this.withStrategies(new 
VertexProgramStrategy(Computer.compute()));
     }
 
+    public default TraversalSource withDetachment(final Map<String, 
Set<String>> detachment) {
+        return this.withStrategies(HaltedTraverserStrategy.detached());
+    }
+
     /**
      * Add a sideEffect to be used throughout the life of a spawned {@link 
Traversal}.
      * This adds a {@link 
org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SideEffectStrategy}
 to the strategies.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/65a51d3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/HaltedTraverserStrategy.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/HaltedTraverserStrategy.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/HaltedTraverserStrategy.java
index 3f02c40..11d9929 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/HaltedTraverserStrategy.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/HaltedTraverserStrategy.java
@@ -30,6 +30,7 @@ import 
org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceFactory;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -38,8 +39,17 @@ public final class HaltedTraverserStrategy extends 
AbstractTraversalStrategy<Tra
 
     private final Class haltedTraverserFactory;
     private final boolean useReference;
+    private final Map<String, Set<String>> deflate;
+
+    private HaltedTraverserStrategy(final Map<String, Set<String>> deflate) {
+        this.haltedTraverserFactory = null;
+        this.useReference = false;
+        this.deflate = deflate;
+
+    }
 
     private HaltedTraverserStrategy(final Class haltedTraverserFactory) {
+        this.deflate = null;
         if (haltedTraverserFactory.equals(DetachedFactory.class) || 
haltedTraverserFactory.equals(ReferenceFactory.class)) {
             this.haltedTraverserFactory = haltedTraverserFactory;
             this.useReference = 
ReferenceFactory.class.equals(this.haltedTraverserFactory);
@@ -91,4 +101,8 @@ public final class HaltedTraverserStrategy extends 
AbstractTraversalStrategy<Tra
         return new HaltedTraverserStrategy(ReferenceFactory.class);
     }
 
+    public static HaltedTraverserStrategy deflated(final Map<String, 
Set<String>> deflate) {
+        return new HaltedTraverserStrategy(deflate);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/65a51d3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedEdge.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedEdge.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedEdge.java
new file mode 100644
index 0000000..976b167
--- /dev/null
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedEdge.java
@@ -0,0 +1,101 @@
+/*
+ *  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.util.deflated;
+
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceFactory;
+import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertex;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class DeflatedEdge extends DeflatedElement<Edge> implements Edge {
+
+    private ReferenceVertex outVertex;
+    private ReferenceVertex inVertex;
+
+
+    protected DeflatedEdge(final Edge edge, final Map<String, Set<String>> 
components) {
+        super(edge);
+        this.outVertex = ReferenceFactory.detach(edge.outVertex());
+        this.inVertex = ReferenceFactory.detach(edge.inVertex());
+        if (components.containsKey(PROPERTIES)) {
+            final Set<String> propertiesSet = components.get(PROPERTIES);
+            final Iterator<Property<Object>> itty = propertiesSet.isEmpty() ?
+                    edge.properties() :
+                    edge.properties(propertiesSet.toArray(new 
String[propertiesSet.size()]));
+            if (itty.hasNext() && null == this.properties) this.properties = 
new HashMap<>();
+            while (itty.hasNext()) {
+                final Property<Object> property = itty.next();
+                if (!this.properties.containsKey(property.key()))
+                    this.properties.put(property.key(), new ArrayList<>());
+                this.properties.get(property.key()).add(new 
DeflatedProperty<>(property));
+            }
+        }
+    }
+
+    @Override
+    public String toString() {
+        return StringFactory.edgeString(this);
+    }
+
+    @Override
+    public Vertex inVertex() {
+        return this.inVertex;
+    }
+
+    @Override
+    public Vertex outVertex() {
+        return this.outVertex;
+    }
+
+    @Override
+    public Iterator<Vertex> vertices(final Direction direction) {
+        switch (direction) {
+            case OUT:
+                return IteratorUtils.of(this.outVertex);
+            case IN:
+                return IteratorUtils.of(this.inVertex);
+            default:
+                return IteratorUtils.of(this.outVertex, this.inVertex);
+        }
+    }
+
+    @Override
+    public void remove() {
+        throw Edge.Exceptions.edgeRemovalNotSupported();
+    }
+
+    @Override
+    public <V> Iterator<Property<V>> properties(final String... propertyKeys) {
+        return (Iterator) super.properties(propertyKeys);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/65a51d3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedElement.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedElement.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedElement.java
new file mode 100644
index 0000000..26e2164
--- /dev/null
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedElement.java
@@ -0,0 +1,104 @@
+/*
+ *  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.util.deflated;
+
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
+import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public abstract class DeflatedElement<E> implements Element, Serializable, 
Attachable<E> {
+
+    public static final String PROPERTIES = "properties";
+    public static final String OUT_E = "outE";
+    public static final String IN_E = "bothE";
+    public static final String BOTH_E = "bothE";
+
+    protected Object id;
+    protected String label;
+    protected Map<String, List<Property>> properties = null;
+
+    public DeflatedElement(final Element element) {
+        this.id = element.id();
+        this.label = element.label();
+    }
+
+    @Override
+    public Object id() {
+        return this.id;
+    }
+
+    @Override
+    public String label() {
+        return this.label;
+    }
+
+    @Override
+    public Graph graph() {
+        return EmptyGraph.instance();
+    }
+
+    @Override
+    public <V> Property<V> property(final String key, final V value) {
+        throw Element.Exceptions.propertyAdditionNotSupported();
+    }
+
+    @Override
+    public abstract void remove();
+
+    @Override
+    public <V> Property<V> property(final String key) {
+        return null != this.properties && this.properties.containsKey(key) ? 
this.properties.get(key).get(0) : Property.empty();
+    }
+
+    @Override
+    public int hashCode() {
+        return ElementHelper.hashCode(this);
+    }
+
+    @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
+    @Override
+    public boolean equals(final Object object) {
+        return ElementHelper.areEqual(this, object);
+    }
+
+    @Override
+    public <V> Iterator<? extends Property<V>> properties(final String... 
propertyKeys) {
+        return null == this.properties ?
+                Collections.emptyIterator() :
+                (Iterator) this.properties.entrySet().stream().filter(entry -> 
ElementHelper.keyExists(entry.getKey(), propertyKeys)).flatMap(entry -> 
entry.getValue().stream()).iterator();
+    }
+
+    public E get() {
+        return (E) this;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/65a51d3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedFactory.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedFactory.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedFactory.java
new file mode 100644
index 0000000..4540695
--- /dev/null
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedFactory.java
@@ -0,0 +1,82 @@
+/*
+ *  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.util.deflated;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Path;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class DeflatedFactory {
+
+    private DeflatedFactory() {
+    }
+
+    public static DeflatedVertex detach(final Vertex vertex, final Map<String, 
Set<String>> components) {
+        return new DeflatedVertex(vertex, components);
+    }
+
+    public static DeflatedEdge detach(final Edge edge, final Map<String, 
Set<String>> components) {
+        return new DeflatedEdge(edge, components);
+    }
+
+    public static <V> DeflatedVertexProperty detach(final VertexProperty<V> 
vertexProperty, final Map<String, Set<String>> components) {
+        return new DeflatedVertexProperty<>(vertexProperty, components);
+    }
+
+    public static <V> DeflatedProperty<V> detach(final Property<V> property) {
+        return new DeflatedProperty<V>(property);
+    }
+
+    public static DeflatedPath detach(final Path path, final Map<String, 
Set<String>> components) {
+        return new DeflatedPath(path, components);
+    }
+
+    public static DeflatedElement detach(final Element element, final 
Map<String, Set<String>> components) {
+        if (element instanceof Vertex)
+            return detach((Vertex) element, components);
+        else if (element instanceof Edge)
+            return detach((Edge) element, components);
+        else if (element instanceof VertexProperty)
+            return detach((VertexProperty) element, components);
+        else
+            throw new IllegalArgumentException("The provided argument is an 
unknown element: " + element + ':' + element.getClass());
+    }
+
+    public static <D> D detach(final Object object, final Map<String, 
Set<String>> components) {
+        if (object instanceof Element) {
+            return (D) DeflatedFactory.detach((Element) object, components);
+        } else if (object instanceof Property) {
+            return (D) DeflatedFactory.detach((Property) object);
+        } else if (object instanceof Path) {
+            return (D) DeflatedFactory.detach((Path) object, components);
+        } else {
+            return (D) object;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/65a51d3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedPath.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedPath.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedPath.java
new file mode 100644
index 0000000..7f8a5f7
--- /dev/null
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedPath.java
@@ -0,0 +1,65 @@
+/*
+ *  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.util.deflated;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Path;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.MutablePath;
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
+
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class DeflatedPath extends MutablePath implements Attachable<Path> {
+
+
+    public Path get() {
+        return this;
+    }
+
+    public DeflatedPath(final Path path, final Map<String, Set<String>> 
components) {
+        path.forEach((object, labels) -> {
+            if (object instanceof Element) {
+                this.objects.add(DeflatedFactory.detach((Element) object, 
components));
+            } else if (object instanceof Property) {
+                this.objects.add(DeflatedFactory.detach((Property) object));
+            } else if (object instanceof Path) {
+                this.objects.add(DeflatedFactory.detach((Path) object, 
components));
+            } else {
+                this.objects.add(object);
+            }
+            //Make a copy of the labels as its an UnmodifiableSet which can 
not be serialized.
+            this.labels.add(new LinkedHashSet<>(labels));
+        });
+    }
+
+    @Override
+    public Path attach(final Function<Attachable<Path>, Path> method) {
+        final Path path = MutablePath.make();
+        this.forEach((object, labels) -> path.extend(object instanceof 
Attachable ? ((Attachable) object).attach(method) : object, labels));
+        return path;
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/65a51d3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedProperty.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedProperty.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedProperty.java
new file mode 100644
index 0000000..ced2123
--- /dev/null
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedProperty.java
@@ -0,0 +1,91 @@
+/*
+ *  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.util.deflated;
+
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
+import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceElement;
+import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceFactory;
+
+import java.io.Serializable;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class DeflatedProperty<V> implements Property<V>, Serializable, 
Attachable<Property<V>> {
+
+    private String key;
+    private V value;
+    private transient ReferenceElement element;
+
+    public DeflatedProperty(final Property<V> property) {
+        this.key = property.key();
+        this.value = property.value();
+        this.element = ReferenceFactory.detach(property.element());
+    }
+
+    public Property<V> get() {
+        return this;
+    }
+
+    @Override
+    public boolean isPresent() {
+        return true;
+    }
+
+    @Override
+    public String key() {
+        return this.key;
+    }
+
+    @Override
+    public V value() {
+        return this.value;
+    }
+
+    @Override
+    public Element element() {
+        return this.element;
+    }
+
+    @Override
+    public void remove() {
+        throw Property.Exceptions.propertyRemovalNotSupported();
+    }
+
+    @Override
+    public String toString() {
+        return StringFactory.propertyString(this);
+    }
+
+    @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
+    @Override
+    public boolean equals(final Object object) {
+        return ElementHelper.areEqual(this, object);
+    }
+
+    @Override
+    public int hashCode() {
+        return ElementHelper.hashCode(this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/65a51d3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedVertex.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedVertex.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedVertex.java
new file mode 100644
index 0000000..ab990da
--- /dev/null
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedVertex.java
@@ -0,0 +1,116 @@
+/*
+ *  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.util.deflated;
+
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class DeflatedVertex extends DeflatedElement<Vertex> implements Vertex {
+
+    public DeflatedVertex(final Vertex vertex, final Map<String, Set<String>> 
components) {
+        super(vertex);
+        if (components.containsKey(PROPERTIES)) {
+            final Set<String> propertiesSet = components.get(PROPERTIES);
+            final Iterator<VertexProperty<Object>> itty = 
propertiesSet.isEmpty() ?
+                    vertex.properties() :
+                    vertex.properties(propertiesSet.toArray(new 
String[propertiesSet.size()]));
+            if(itty.hasNext() && null == this.properties) this.properties = 
new HashMap<>();
+            while (itty.hasNext()) {
+                final VertexProperty<Object> vertexProperty = itty.next();
+                if (!this.properties.containsKey(vertexProperty.key()))
+                    this.properties.put(vertexProperty.key(), new 
ArrayList<>());
+                this.properties.get(vertexProperty.key()).add(new 
DeflatedVertexProperty<>(vertexProperty, components));
+            }
+        }
+    }
+
+    @Override
+    public <V> VertexProperty<V> property(final String key, final V value) {
+        throw Element.Exceptions.propertyAdditionNotSupported();
+    }
+
+    @Override
+    public <V> VertexProperty<V> property(final String key, final V value, 
final Object... keyValues) {
+        throw Element.Exceptions.propertyAdditionNotSupported();
+    }
+
+    @Override
+    public <V> VertexProperty<V> property(final VertexProperty.Cardinality 
cardinality, final String key, final V value, final Object... keyValues) {
+        throw Element.Exceptions.propertyAdditionNotSupported();
+    }
+
+    @Override
+    public <V> VertexProperty<V> property(final String key) {
+        if (null != this.properties && this.properties.containsKey(key)) {
+            final List<VertexProperty> list = (List) this.properties.get(key);
+            if (list.size() > 1)
+                throw 
Vertex.Exceptions.multiplePropertiesExistForProvidedKey(key);
+            else
+                return list.get(0);
+        } else
+            return VertexProperty.<V>empty();
+    }
+
+    @Override
+    public Edge addEdge(final String label, final Vertex inVertex, final 
Object... keyValues) {
+        throw Vertex.Exceptions.edgeAdditionsNotSupported();
+    }
+
+    @Override
+    public String toString() {
+        return StringFactory.vertexString(this);
+    }
+
+    @Override
+    public <V> Iterator<VertexProperty<V>> properties(final String... 
propertyKeys) {
+        return (Iterator) super.properties(propertyKeys);
+    }
+
+    @Override
+    public Iterator<Edge> edges(final Direction direction, final String... 
edgeLabels) {
+        return Collections.emptyIterator();
+    }
+
+    @Override
+    public Iterator<Vertex> vertices(final Direction direction, final 
String... labels) {
+        return Collections.emptyIterator();
+    }
+
+    @Override
+    public void remove() {
+        throw Vertex.Exceptions.vertexRemovalNotSupported();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/65a51d3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedVertexProperty.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedVertexProperty.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedVertexProperty.java
new file mode 100644
index 0000000..6e349fd
--- /dev/null
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/deflated/DeflatedVertexProperty.java
@@ -0,0 +1,103 @@
+/*
+ *  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.util.deflated;
+
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceFactory;
+import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertex;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class DeflatedVertexProperty<V> extends 
DeflatedElement<VertexProperty<V>> implements VertexProperty<V> {
+
+    protected V value;
+    protected transient ReferenceVertex vertex;
+
+    public DeflatedVertexProperty(final VertexProperty<V> vertexProperty, 
final Map<String, Set<String>> components) {
+        super(vertexProperty);
+        this.value = vertexProperty.value();
+        this.vertex = ReferenceFactory.detach(vertexProperty.element());
+        if (components.containsKey(PROPERTIES)) {
+            final Set<String> propertiesSet = components.get(PROPERTIES);
+            final Iterator<Property<Object>> itty = propertiesSet.isEmpty() ?
+                    vertexProperty.properties() :
+                    vertexProperty.properties(propertiesSet.toArray(new 
String[propertiesSet.size()]));
+            if (itty.hasNext() && null == this.properties) this.properties = 
new HashMap<>();
+            while (itty.hasNext()) {
+                final Property<Object> property = itty.next();
+                if (!this.properties.containsKey(property.key()))
+                    this.properties.put(property.key(), new ArrayList<>());
+                this.properties.get(property.key()).add(new 
DeflatedProperty<>(property));
+            }
+        }
+    }
+
+    @Override
+    public boolean isPresent() {
+        return true;
+    }
+
+    @Override
+    public String key() {
+        return this.label;
+    }
+
+    @Override
+    public V value() {
+        return this.value;
+    }
+
+    @Override
+    public Vertex element() {
+        return this.vertex;
+    }
+
+    @Override
+    public void remove() {
+        throw Property.Exceptions.propertyRemovalNotSupported();
+    }
+
+    @Override
+    public String toString() {
+        return StringFactory.propertyString(this);
+    }
+
+    @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
+    @Override
+    public boolean equals(final Object object) {
+        return ElementHelper.areEqual(this, object);
+    }
+
+    @Override
+    public <U> Iterator<Property<U>> properties(final String... propertyKeys) {
+        return (Iterator) super.properties(propertyKeys);
+    }
+}

Reply via email to