You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by co...@apache.org on 2023/12/05 22:08:24 UTC
(tinkerpop) 13/13: lots of cleanup and reorg. Path now implements TSequence (smart, duplicate keys allowed). Thought through and tweaked all the methods of the core structure API/. TTuple and TSequence are making lots of sense -- basically, map and list respectively.
This is an automated email from the ASF dual-hosted git repository.
colegreer pushed a commit to branch old-4.0-dev
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit bd79bcc4c1d5db3f1bcf3e40e7f1d27892c928e4
Author: Marko A. Rodriguez <ok...@gmail.com>
AuthorDate: Tue Apr 30 04:05:56 2019 -0600
lots of cleanup and reorg. Path now implements TSequence (smart, duplicate keys allowed). Thought through and tweaked all the methods of the core structure API/. TTuple and TSequence are making lots of sense -- basically, map and list respectively.
---
.../language/gremlin/AbstractTraversal.java | 2 +-
.../tinkerpop/language/gremlin/Traversal.java | 4 +-
.../language/gremlin/TraversalSource.java | 6 +--
.../language/gremlin/core/CoreTraversal.java | 4 +-
.../tinkerpop/machine/bytecode/Bytecode.java | 11 +++--
.../tinkerpop/machine/bytecode/Instruction.java | 6 +--
.../machine/function/filter/HasKeyFilter.java | 8 +---
.../machine/function/flatmap/DbFlatMap.java | 17 ++++---
.../machine/function/flatmap/EntriesFlatMap.java | 19 ++++----
.../machine/function/reduce/GroupCountReduce.java | 4 +-
.../strategy/decoration/ExplainStrategy.java | 1 +
.../structure/{util/J2Tuple.java => TPair.java} | 52 ++++++----------------
.../apache/tinkerpop/machine/structure/TTuple.java | 13 +++---
.../tinkerpop/machine/structure/graph/TEdge.java | 6 ++-
.../tinkerpop/machine/structure/graph/TVertex.java | 16 +++----
.../{JSequence.java => CompositeSequence.java} | 22 +++++----
.../structure/util/{T2Tuple.java => JPair.java} | 27 +++++++++--
.../machine/structure/util/JSequence.java | 5 +++
.../tinkerpop/machine/structure/util/JTuple.java | 21 ++-------
.../machine/traverser/path/BasicPath.java | 28 +++++++-----
.../machine/traverser/path/EmptyPath.java | 10 ++---
.../tinkerpop/machine/traverser/path/Path.java | 21 ++++++---
.../tinkerpop/machine/bytecode/BytecodeTest.java | 4 +-
.../machine/bytecode/InstructionTest.java | 10 ++---
.../machine/bytecode/compiler/CompilationTest.java | 6 +--
.../blueprints/data/BlueprintsVertex.java | 18 +++-----
.../provider/BlueprintsVerticesStrategy.java | 2 +-
.../machine/structure/jdbc/JDBCDatabase.java | 17 +++----
.../tinkerpop/machine/structure/jdbc/JDBCRow.java | 27 +++--------
.../jdbc/bytecode/compiler/JDBCCompiler.java | 15 +++----
.../jdbc/function/flatmap/SqlFlatMap.java | 5 +++
.../structure/jdbc/strategy/JDBCQueryStrategy.java | 2 +-
.../structure/jdbc/strategy/JDBCStrategy.java | 2 +-
33 files changed, 191 insertions(+), 220 deletions(-)
diff --git a/java/language/gremlin/src/main/java/org/apache/tinkerpop/language/gremlin/AbstractTraversal.java b/java/language/gremlin/src/main/java/org/apache/tinkerpop/language/gremlin/AbstractTraversal.java
index 51f7e080d9..793a469315 100644
--- a/java/language/gremlin/src/main/java/org/apache/tinkerpop/language/gremlin/AbstractTraversal.java
+++ b/java/language/gremlin/src/main/java/org/apache/tinkerpop/language/gremlin/AbstractTraversal.java
@@ -54,7 +54,7 @@ public abstract class AbstractTraversal<C, S, E> implements Traversal<C, S, E> {
protected final <A, B> Traversal<C, A, B> addInstruction(final String op, final Object... args) {
if (this.executed)
throw new IllegalStateException("The traversal has already been submitted and can no longer be mutated");
- this.bytecode.addInstruction(this.currentCoefficient, op, args);
+ this.bytecode.addInstruction(this.currentCoefficient, null, op, args);
this.currentCoefficient.unity();
return (Traversal<C, A, B>) this;
}
diff --git a/java/language/gremlin/src/main/java/org/apache/tinkerpop/language/gremlin/Traversal.java b/java/language/gremlin/src/main/java/org/apache/tinkerpop/language/gremlin/Traversal.java
index 5015a9e15d..b9745027ea 100644
--- a/java/language/gremlin/src/main/java/org/apache/tinkerpop/language/gremlin/Traversal.java
+++ b/java/language/gremlin/src/main/java/org/apache/tinkerpop/language/gremlin/Traversal.java
@@ -21,7 +21,7 @@ package org.apache.tinkerpop.language.gremlin;
import org.apache.tinkerpop.machine.bytecode.compiler.Order;
import org.apache.tinkerpop.machine.structure.TTuple;
import org.apache.tinkerpop.machine.structure.rdbms.TDatabase;
-import org.apache.tinkerpop.machine.structure.util.T2Tuple;
+import org.apache.tinkerpop.machine.structure.TPair;
import org.apache.tinkerpop.machine.traverser.Traverser;
import org.apache.tinkerpop.machine.traverser.path.Path;
@@ -61,7 +61,7 @@ public interface Traversal<C, S, E> extends Iterator<E> {
public Traversal<C, S, E> emit(final Traversal<C, ?, ?> emitTraversal); // TODO: why not <C,E,?>
- public <K, V> Traversal<C, S, T2Tuple<K, V>> entries();
+ public <K, V> Traversal<C, S, TPair<K, V>> entries();
public Traversal<C, S, String> explain();
diff --git a/java/language/gremlin/src/main/java/org/apache/tinkerpop/language/gremlin/TraversalSource.java b/java/language/gremlin/src/main/java/org/apache/tinkerpop/language/gremlin/TraversalSource.java
index 1b91203b5d..6fa1d4c76d 100644
--- a/java/language/gremlin/src/main/java/org/apache/tinkerpop/language/gremlin/TraversalSource.java
+++ b/java/language/gremlin/src/main/java/org/apache/tinkerpop/language/gremlin/TraversalSource.java
@@ -97,7 +97,7 @@ public class TraversalSource<C> implements Cloneable {
this.prepareSourceCode();
final Bytecode<C> bytecode = this.bytecode.clone();
final Coefficient<C> coefficient = this.coefficient.clone();
- bytecode.addInstruction(coefficient, Symbols.INJECT, objects);
+ bytecode.addInstruction(coefficient, null, Symbols.INJECT, objects);
return new CoreTraversal<>(this.machine, bytecode, coefficient); // TODO
}
@@ -105,7 +105,7 @@ public class TraversalSource<C> implements Cloneable {
this.prepareSourceCode();
final Bytecode<C> bytecode = this.bytecode.clone();
final Coefficient<C> coefficient = this.coefficient.clone();
- bytecode.addInstruction(coefficient, Symbols.V);
+ bytecode.addInstruction(coefficient, null, Symbols.V);
return new CoreTraversal<>(this.machine, bytecode, coefficient); // TODO
}
@@ -113,7 +113,7 @@ public class TraversalSource<C> implements Cloneable {
this.prepareSourceCode();
final Bytecode<C> bytecode = this.bytecode.clone();
final Coefficient<C> coefficient = this.coefficient.clone();
- bytecode.addInstruction(coefficient, Symbols.DB);
+ bytecode.addInstruction(coefficient, null, Symbols.DB);
return new CoreTraversal<>(this.machine, bytecode, coefficient); // TODO
}
diff --git a/java/language/gremlin/src/main/java/org/apache/tinkerpop/language/gremlin/core/CoreTraversal.java b/java/language/gremlin/src/main/java/org/apache/tinkerpop/language/gremlin/core/CoreTraversal.java
index 35c01edeca..085a542270 100644
--- a/java/language/gremlin/src/main/java/org/apache/tinkerpop/language/gremlin/core/CoreTraversal.java
+++ b/java/language/gremlin/src/main/java/org/apache/tinkerpop/language/gremlin/core/CoreTraversal.java
@@ -31,7 +31,7 @@ import org.apache.tinkerpop.machine.coefficient.Coefficient;
import org.apache.tinkerpop.machine.coefficient.LongCoefficient;
import org.apache.tinkerpop.machine.structure.TTuple;
import org.apache.tinkerpop.machine.structure.rdbms.TDatabase;
-import org.apache.tinkerpop.machine.structure.util.T2Tuple;
+import org.apache.tinkerpop.machine.structure.TPair;
import org.apache.tinkerpop.machine.traverser.path.Path;
/**
@@ -125,7 +125,7 @@ public class CoreTraversal<C, S, E> extends AbstractTraversal<C, S, E> {
}
@Override
- public <K, V> Traversal<C, S, T2Tuple<K, V>> entries() {
+ public <K, V> Traversal<C, S, TPair<K, V>> entries() {
return this.addInstruction(Symbols.ENTRIES);
}
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/Bytecode.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/Bytecode.java
index 75196521a9..038a781d8a 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/Bytecode.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/Bytecode.java
@@ -59,14 +59,14 @@ public final class Bytecode<C> implements Cloneable, Serializable {
///
- public void addInstruction(final Coefficient<C> coefficient, final String op, final Object... args) {
+ public void addInstruction(final Coefficient<C> coefficient, final String label, final String op, final Object... args) {
BytecodeUtil.linkBytecodeChildren(this, args);
- this.instructions.add(new Instruction<>(coefficient, op, args));
+ this.instructions.add(new Instruction<>(coefficient, label, op, args));
}
- public void addInstruction(final int index, final Coefficient<C> coefficient, final String op, final Object... args) {
+ public void addInstruction(final int index, final Coefficient<C> coefficient, final String label, final String op, final Object... args) {
BytecodeUtil.linkBytecodeChildren(this, args);
- this.instructions.add(index, new Instruction<>(coefficient, op, args));
+ this.instructions.add(index, new Instruction<>(coefficient, label, op, args));
}
public List<Instruction<C>> getInstructions() {
@@ -114,8 +114,7 @@ public final class Bytecode<C> implements Cloneable, Serializable {
clone.addSourceInstruction(sourceInstruction.op(), sourceInstruction.args());
}
for (final Instruction<C> instruction : this.instructions) {
- clone.addInstruction(instruction.coefficient(), instruction.op(), instruction.args());
- clone.lastInstruction().setLabel(instruction.label());
+ clone.addInstruction(instruction.coefficient(), instruction.label(), instruction.op(), instruction.args());
}
return clone;
} catch (final CloneNotSupportedException e) {
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/Instruction.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/Instruction.java
index 430479ddac..184dacfeca 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/Instruction.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/Instruction.java
@@ -29,12 +29,13 @@ import java.util.Arrays;
*/
public final class Instruction<C> implements Serializable {
+ private String label;
private final Coefficient<C> coefficient;
private final String op;
Object[] args;
- private String label = null;
- public Instruction(final Coefficient<C> coefficient, final String op, final Object... args) {
+ public Instruction(final Coefficient<C> coefficient, final String label, final String op, final Object... args) {
+ this.label = label;
this.coefficient = coefficient.clone();
this.op = op;
this.args = args;
@@ -60,7 +61,6 @@ public final class Instruction<C> implements Serializable {
this.label = label;
}
-
@Override
public int hashCode() {
return this.coefficient.hashCode() ^ this.op.hashCode() ^ Arrays.hashCode(this.args) ^ (null == this.label ? 1 : this.label.hashCode());
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/filter/HasKeyFilter.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/filter/HasKeyFilter.java
index d6ef5db1a1..541bb7f48d 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/filter/HasKeyFilter.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/filter/HasKeyFilter.java
@@ -25,12 +25,10 @@ import org.apache.tinkerpop.machine.coefficient.Coefficient;
import org.apache.tinkerpop.machine.function.AbstractFunction;
import org.apache.tinkerpop.machine.function.FilterFunction;
import org.apache.tinkerpop.machine.structure.TTuple;
-import org.apache.tinkerpop.machine.structure.util.T2Tuple;
+import org.apache.tinkerpop.machine.structure.TPair;
import org.apache.tinkerpop.machine.traverser.Traverser;
import org.apache.tinkerpop.machine.util.StringFactory;
-import java.util.Iterator;
-
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
@@ -52,9 +50,7 @@ public final class HasKeyFilter<C, K, V> extends AbstractFunction<C> implements
return object.has(this.key.mapArg(traverser));
else {
final K testKey = this.key.mapArg(traverser);
- final Iterator<T2Tuple<K, V>> iterator = traverser.object().entries();
- while (iterator.hasNext()) {
- final T2Tuple<K, V> entry = iterator.next();
+ for (final TPair<K, V> entry : traverser.object()) {
if (this.predicate.test(entry.key(), testKey))
return true;
}
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/flatmap/DbFlatMap.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/flatmap/DbFlatMap.java
index a071ec7e5d..7218e9fdcb 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/flatmap/DbFlatMap.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/flatmap/DbFlatMap.java
@@ -41,6 +41,10 @@ public final class DbFlatMap<C, S> extends AbstractFunction<C> implements Initia
this.database = database;
}
+ @Override
+ public Iterator<TDatabase> apply(final Traverser<C, S> traverser) {
+ return IteratorUtils.of(this.database);
+ }
@Override
public int hashCode() {
@@ -52,17 +56,12 @@ public final class DbFlatMap<C, S> extends AbstractFunction<C> implements Initia
return StringFactory.makeFunctionString(this, this.database);
}
- public static <C, S> DbFlatMap<C, S> compile(final Instruction<C> instruction) {
- return new DbFlatMap<>(instruction.coefficient(), instruction.label(), (TDatabase) instruction.args()[0]);
- }
-
@Override
- public Iterator<TDatabase> apply(final Traverser<C, S> traverser) {
- return IteratorUtils.of(this.database);
+ public DbFlatMap<C, S> clone() {
+ return (DbFlatMap<C, S>) super.clone();
}
- @Override
- public DbFlatMap<C, S> clone() { // TODO
- return this;
+ public static <C, S> DbFlatMap<C, S> compile(final Instruction<C> instruction) {
+ return new DbFlatMap<>(instruction.coefficient(), instruction.label(), (TDatabase) instruction.args()[0]); // TODO: db() should be a custom instruction, no complex objects in bytecode
}
}
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/flatmap/EntriesFlatMap.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/flatmap/EntriesFlatMap.java
index 4143cc55b7..e7affead9c 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/flatmap/EntriesFlatMap.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/flatmap/EntriesFlatMap.java
@@ -22,8 +22,8 @@ import org.apache.tinkerpop.machine.bytecode.Instruction;
import org.apache.tinkerpop.machine.coefficient.Coefficient;
import org.apache.tinkerpop.machine.function.AbstractFunction;
import org.apache.tinkerpop.machine.function.FlatMapFunction;
+import org.apache.tinkerpop.machine.structure.TPair;
import org.apache.tinkerpop.machine.structure.TTuple;
-import org.apache.tinkerpop.machine.structure.util.T2Tuple;
import org.apache.tinkerpop.machine.traverser.Traverser;
import org.apache.tinkerpop.machine.util.StringFactory;
@@ -32,21 +32,15 @@ import java.util.Iterator;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public final class EntriesFlatMap<C, K, V> extends AbstractFunction<C> implements FlatMapFunction<C, TTuple<K, V>, T2Tuple<K, V>> {
-
+public final class EntriesFlatMap<C, K, V> extends AbstractFunction<C> implements FlatMapFunction<C, TTuple<K, V>, TPair<K, V>> {
private EntriesFlatMap(final Coefficient<C> coefficient, final String label) {
super(coefficient, label);
}
@Override
- public Iterator<T2Tuple<K, V>> apply(final Traverser<C, TTuple<K, V>> traverser) {
- return traverser.object().entries();
- }
-
- @Override
- public EntriesFlatMap<C, K, V> clone() {
- return (EntriesFlatMap<C, K, V>) super.clone();
+ public Iterator<TPair<K, V>> apply(final Traverser<C, TTuple<K, V>> traverser) {
+ return traverser.object().iterator();
}
@Override
@@ -59,6 +53,11 @@ public final class EntriesFlatMap<C, K, V> extends AbstractFunction<C> implement
return StringFactory.makeFunctionString(this);
}
+ @Override
+ public EntriesFlatMap<C, K, V> clone() {
+ return (EntriesFlatMap<C, K, V>) super.clone();
+ }
+
public static <C, K, V> EntriesFlatMap<C, K, V> compile(final Instruction<C> instruction) {
return new EntriesFlatMap<>(instruction.coefficient(), instruction.label());
}
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/reduce/GroupCountReduce.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/reduce/GroupCountReduce.java
index 6549ad2d8b..e39b2179e4 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/reduce/GroupCountReduce.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/function/reduce/GroupCountReduce.java
@@ -50,8 +50,8 @@ public final class GroupCountReduce<C, S, E> extends AbstractFunction<C> impleme
@Override
public TTuple<E, Long> merge(final TTuple<E, Long> valueA, final TTuple<E, Long> valueB) {
final JTuple<E, Long> tuple = new JTuple<>();
- valueA.entries().forEachRemaining(entry -> tuple.set(entry.key(), entry.value()));
- valueB.entries().forEachRemaining(entry -> tuple.set(entry.key(), entry.value()));
+ valueA.forEach(entry -> tuple.set(entry.key(), entry.value()));
+ valueB.forEach(entry -> tuple.set(entry.key(), entry.value()));
return new JTuple<>();
}
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/strategy/decoration/ExplainStrategy.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/strategy/decoration/ExplainStrategy.java
index 65e02cb5fe..ec2958c8cf 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/strategy/decoration/ExplainStrategy.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/strategy/decoration/ExplainStrategy.java
@@ -50,6 +50,7 @@ public final class ExplainStrategy extends AbstractStrategy<Strategy.DecorationS
bytecode.getInstructions().clear();
bytecode.addInstruction(
(Coefficient<C>) LongCoefficient.create(),
+ null,
Symbols.INJECT,
ExplainStrategy.explainBytecode(clone));
}
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/J2Tuple.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/TPair.java
similarity index 50%
rename from java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/J2Tuple.java
rename to java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/TPair.java
index aeffd07074..394ed10922 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/J2Tuple.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/TPair.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tinkerpop.machine.structure.util;
+package org.apache.tinkerpop.machine.structure;
import org.apache.tinkerpop.machine.util.IteratorUtils;
@@ -25,63 +25,39 @@ import java.util.Iterator;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public final class J2Tuple<K, V> implements T2Tuple<K, V> {
+public interface TPair<K, V> extends TTuple<K, V> {
- private K key;
- private V value;
+ public K key();
- public J2Tuple(final K key, final V value) {
- this.key = key;
- this.value = value;
- }
-
- @Override
- public K key() {
- return this.key;
- }
-
- @Override
- public V value() {
- return this.value;
- }
+ public V value();
@Override
- public V value(final K key) {
- return this.key.equals(key) ? this.value : null;
+ public default boolean has(final K key) {
+ return key.equals(this.key());
}
@Override
- public void set(final K key, final V value) {
- throw new IllegalStateException("Can't set key/value for a 2-tuple");
+ public default V value(final K key) {
+ return key.equals(this.key()) ? this.value() : null; // TODO: Exception or Optional?
}
@Override
- public void add(final K key, final V value) {
- throw new IllegalStateException("Can't add key/value for a 2-tuple");
+ public default void set(final K key, final V value) {
+ throw new IllegalStateException("TPairs are immutable: " + this);
}
@Override
- public void remove(final K key) {
- throw new IllegalStateException("Can't remove key/value for a 2-tuple");
+ public default void remove(final K key) {
+ throw new IllegalStateException("TPairs are immutable: " + this);
}
@Override
- public int size() {
+ public default int size() {
return 1;
}
@Override
- public Iterator<T2Tuple<K, V>> entries() {
+ public default Iterator<TPair<K, V>> iterator() {
return IteratorUtils.of(this);
}
-
- @Override
- public boolean has(final K key) {
- return this.key.equals(key);
- }
-
- @Override
- public String toString() {
- return this.key + ":" + this.value;
- }
}
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/TTuple.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/TTuple.java
index cc4763df55..1f40518c2e 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/TTuple.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/TTuple.java
@@ -18,14 +18,14 @@
*/
package org.apache.tinkerpop.machine.structure;
-import org.apache.tinkerpop.machine.structure.util.T2Tuple;
+import org.apache.tinkerpop.machine.util.IteratorUtils;
import java.util.Iterator;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public interface TTuple<K, V> {
+public interface TTuple<K, V> extends Iterable<TPair<K, V>> {
public boolean has(final K key);
@@ -35,14 +35,15 @@ public interface TTuple<K, V> {
return this.has(key) ? this.value(key) : defaultValue;
}
- public void set(final K key, final V value);
+ public default <U> Iterator<U> values(final K key) {
+ final Object object = this.value(key);
+ return object instanceof TSequence ? ((TSequence<U>) object).iterator() : IteratorUtils.of((U) object);
+ }
- public void add(final K key, final V value);
+ public void set(final K key, final V value);
public void remove(final K key);
public int size();
- public Iterator<T2Tuple<K, V>> entries();
-
}
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/graph/TEdge.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/graph/TEdge.java
index c5695e4ea6..b75a462516 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/graph/TEdge.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/graph/TEdge.java
@@ -18,6 +18,8 @@
*/
package org.apache.tinkerpop.machine.structure.graph;
+import org.apache.tinkerpop.machine.structure.TSequence;
+import org.apache.tinkerpop.machine.structure.util.JSequence;
import org.apache.tinkerpop.machine.util.IteratorUtils;
import java.util.Iterator;
@@ -31,7 +33,7 @@ public interface TEdge<V> extends TElement<V> {
public TVertex<V> outV();
- public default Iterator<TVertex<V>> bothV() {
- return IteratorUtils.of(this.inV(), this.outV());
+ public default TSequence<TVertex<V>> bothV() {
+ return new JSequence<>(this.outV(),this.inV());
}
}
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/graph/TVertex.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/graph/TVertex.java
index 360c25df01..9f3197bfae 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/graph/TVertex.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/graph/TVertex.java
@@ -18,24 +18,20 @@
*/
package org.apache.tinkerpop.machine.structure.graph;
-import org.apache.tinkerpop.machine.util.MultiIterator;
-
-import java.util.Iterator;
+import org.apache.tinkerpop.machine.structure.TSequence;
+import org.apache.tinkerpop.machine.structure.util.CompositeSequence;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public interface TVertex<V> extends TElement<V> {
- public Iterator<TEdge<V>> inE();
+ public TSequence<TEdge<V>> inE();
- public Iterator<TEdge<V>> outE();
+ public TSequence<TEdge<V>> outE();
- public default Iterator<TEdge<V>> bothE() {
- final MultiIterator<TEdge<V>> iterator = new MultiIterator<>();
- iterator.addIterator(this.inE());
- iterator.addIterator(this.outE());
- return iterator;
+ public default TSequence<TEdge<V>> bothE() {
+ return new CompositeSequence<>(this.inE(), this.outE());
}
}
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/JSequence.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/CompositeSequence.java
similarity index 71%
copy from java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/JSequence.java
copy to java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/CompositeSequence.java
index 6b54a54526..c50d4ad896 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/JSequence.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/CompositeSequence.java
@@ -19,30 +19,36 @@
package org.apache.tinkerpop.machine.structure.util;
import org.apache.tinkerpop.machine.structure.TSequence;
+import org.apache.tinkerpop.machine.util.IteratorUtils;
-import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public final class JSequence<V> implements TSequence<V> {
+public class CompositeSequence<V> implements TSequence<V> {
+
+ private final List<TSequence<V>> list;
+
+ public CompositeSequence(final TSequence... sequences) {
+ this.list = Arrays.asList(sequences);
+ }
- private final List<V> list = new ArrayList<>();
@Override
- public void add(final V value) {
- this.list.add(value);
+ public void add(V value) {
+
}
@Override
- public void remove(final V value) {
- this.list.remove(value);
+ public void remove(V value) {
+
}
@Override
public Iterator<V> iterator() {
- return this.list.iterator();
+ return list.stream().flatMap(s -> IteratorUtils.stream(s.iterator())).iterator();
}
}
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/T2Tuple.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/JPair.java
similarity index 65%
rename from java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/T2Tuple.java
rename to java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/JPair.java
index f10b8ffc3d..fd07f98572 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/T2Tuple.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/JPair.java
@@ -18,14 +18,33 @@
*/
package org.apache.tinkerpop.machine.structure.util;
-import org.apache.tinkerpop.machine.structure.TTuple;
+import org.apache.tinkerpop.machine.structure.TPair;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public interface T2Tuple<K, V> extends TTuple<K, V> {
+public final class JPair<K, V> implements TPair<K, V> {
- public K key();
+ private K key;
+ private V value;
- public V value();
+ public JPair(final K key, final V value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ @Override
+ public K key() {
+ return this.key;
+ }
+
+ @Override
+ public V value() {
+ return this.value;
+ }
+
+ @Override
+ public String toString() {
+ return this.key + ":" + this.value;
+ }
}
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/JSequence.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/JSequence.java
index 6b54a54526..6b509d498e 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/JSequence.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/JSequence.java
@@ -21,6 +21,7 @@ package org.apache.tinkerpop.machine.structure.util;
import org.apache.tinkerpop.machine.structure.TSequence;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -31,6 +32,10 @@ public final class JSequence<V> implements TSequence<V> {
private final List<V> list = new ArrayList<>();
+ public JSequence(final V... values) {
+ Collections.addAll(this.list, values);
+ }
+
@Override
public void add(final V value) {
this.list.add(value);
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/JTuple.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/JTuple.java
index 46f5cf95b5..59046f02fa 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/JTuple.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/structure/util/JTuple.java
@@ -18,6 +18,7 @@
*/
package org.apache.tinkerpop.machine.structure.util;
+import org.apache.tinkerpop.machine.structure.TPair;
import org.apache.tinkerpop.machine.structure.TSequence;
import org.apache.tinkerpop.machine.structure.TTuple;
import org.apache.tinkerpop.machine.util.IteratorUtils;
@@ -48,22 +49,6 @@ public class JTuple<K, V> implements TTuple<K, V> {
this.map.put(key, value);
}
- @Override
- public void add(final K key, final V value) {
- if (this.map.containsKey(key)) {
- final Object v = this.map.get(key);
- if (v instanceof TSequence) {
- ((TSequence) v).add(v);
- } else {
- final JSequence sequence = new JSequence();
- sequence.add(v);
- this.map.put(key, (V) sequence);
- }
- } else {
- this.map.put(key, value);
- }
- }
-
@Override
public void remove(final K key) {
this.map.remove(key);
@@ -75,8 +60,8 @@ public class JTuple<K, V> implements TTuple<K, V> {
}
@Override
- public Iterator<T2Tuple<K, V>> entries() {
- return IteratorUtils.map(this.map.entrySet().iterator(), e -> new J2Tuple<>(e.getKey(), e.getValue()));
+ public Iterator<TPair<K, V>> iterator() {
+ return IteratorUtils.map(this.map.entrySet().iterator(), e -> new JPair<>(e.getKey(), e.getValue()));
}
@Override
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/traverser/path/BasicPath.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/traverser/path/BasicPath.java
index 5b7f0781a1..3ef84c95fb 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/traverser/path/BasicPath.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/traverser/path/BasicPath.java
@@ -18,7 +18,7 @@
*/
package org.apache.tinkerpop.machine.traverser.path;
-import org.apache.tinkerpop.machine.structure.util.T2Tuple;
+import org.apache.tinkerpop.machine.structure.TPair;
import java.util.ArrayList;
import java.util.Iterator;
@@ -40,13 +40,6 @@ public final class BasicPath implements Path {
return this.labels.contains(key);
}
- @Override
- public void set(final String key, final Object value) {
- final int index = this.labels.indexOf(key);
- if (-1 != index)
- this.objects.set(index, value);
- }
-
@Override
public void add(final String label, final Object object) {
this.labels.add(label);
@@ -55,16 +48,27 @@ public final class BasicPath implements Path {
@Override
public void remove(final String key) {
- final int index = this.labels.indexOf(key);
- if (-1 != index) {
+ int index;
+ while (-1 != (index = this.labels.indexOf(key))) {
this.labels.remove(index);
this.objects.remove(index);
}
}
@Override
- public Iterator<T2Tuple<String, Object>> entries() {
- return null;
+ public void remove(final TPair<String, Object> pair) {
+ int index;
+ while (-1 != (index = this.labels.indexOf(pair.key()))) {
+ if (pair.value().equals(this.objects.get(index))) {
+ this.labels.remove(index);
+ this.objects.remove(index);
+ }
+ }
+ }
+
+ @Override
+ public Iterator<TPair<String, Object>> iterator() {
+ return null; // TODO
}
@Override
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/traverser/path/EmptyPath.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/traverser/path/EmptyPath.java
index e3039f1177..847eebebf6 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/traverser/path/EmptyPath.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/traverser/path/EmptyPath.java
@@ -18,7 +18,7 @@
*/
package org.apache.tinkerpop.machine.traverser.path;
-import org.apache.tinkerpop.machine.structure.util.T2Tuple;
+import org.apache.tinkerpop.machine.structure.TPair;
import java.util.Collections;
import java.util.Iterator;
@@ -40,22 +40,22 @@ public final class EmptyPath implements Path {
}
@Override
- public void set(final String key, final Object value) {
+ public void add(final String label, final Object object) {
}
@Override
- public void add(final String label, final Object object) {
+ public void remove(final String key) {
}
@Override
- public void remove(final String key) {
+ public void remove(final TPair<String, Object> pair) {
}
@Override
- public Iterator<T2Tuple<String, Object>> entries() {
+ public Iterator<TPair<String, Object>> iterator() {
return Collections.emptyIterator();
}
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/traverser/path/Path.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/traverser/path/Path.java
index 0d06f73a0d..7d07c50c21 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/traverser/path/Path.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/traverser/path/Path.java
@@ -18,32 +18,41 @@
*/
package org.apache.tinkerpop.machine.traverser.path;
-import org.apache.tinkerpop.machine.structure.TTuple;
+import org.apache.tinkerpop.machine.structure.TSequence;
+import org.apache.tinkerpop.machine.structure.TPair;
import java.io.Serializable;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public interface Path extends Serializable, Cloneable, TTuple<String, Object> {
+public interface Path extends Serializable, Cloneable, TSequence<TPair<String, Object>> {
public enum Pop {
first, last, all;
}
- public void add(final String label, final Object object);
-
public Object object(final int index);
public String label(final int index);
public Object get(final Pop pop, final String label);
+ public default Object get(final String label) {
+ return this.get(Pop.last, label);
+ }
+
+ public boolean has(final String key);
+
+ public void add(final String label, final Object object);
+
@Override
- public default Object value(final String key) {
- return this.get(Pop.last, key);
+ public default void add(final TPair<String, Object> pair) {
+ this.add(pair.key(), pair.value());
}
+ public void remove(final String key);
+
public int size();
public Path clone();
diff --git a/java/machine/machine-core/src/test/java/org/apache/tinkerpop/machine/bytecode/BytecodeTest.java b/java/machine/machine-core/src/test/java/org/apache/tinkerpop/machine/bytecode/BytecodeTest.java
index 9653d522da..69df8d9970 100644
--- a/java/machine/machine-core/src/test/java/org/apache/tinkerpop/machine/bytecode/BytecodeTest.java
+++ b/java/machine/machine-core/src/test/java/org/apache/tinkerpop/machine/bytecode/BytecodeTest.java
@@ -36,7 +36,7 @@ class BytecodeTest {
Bytecode<Long> parent = new Bytecode<>();
assertFalse(parent.getParent().isPresent());
Bytecode<Long> child = new Bytecode<>();
- parent.addInstruction(LongCoefficient.create(), "test", child);
+ parent.addInstruction(LongCoefficient.create(), null, "test", child);
assertTrue(child.getParent().isPresent());
assertEquals(parent, child.getParent().get());
assertFalse(child.getParent().get().getParent().isPresent());
@@ -47,7 +47,7 @@ class BytecodeTest {
Bytecode<Long> parent = new Bytecode<>();
assertFalse(parent.getParent().isPresent());
Bytecode<Long> child = new Bytecode<>();
- parent.addInstruction(LongCoefficient.create(), "test", child);
+ parent.addInstruction(LongCoefficient.create(), null, "test", child);
Bytecode<Long> cloneParent = parent.clone();
Bytecode<Long> cloneChild = (Bytecode<Long>) cloneParent.lastInstruction().args()[0];
diff --git a/java/machine/machine-core/src/test/java/org/apache/tinkerpop/machine/bytecode/InstructionTest.java b/java/machine/machine-core/src/test/java/org/apache/tinkerpop/machine/bytecode/InstructionTest.java
index ed2b723bde..0a184a3266 100644
--- a/java/machine/machine-core/src/test/java/org/apache/tinkerpop/machine/bytecode/InstructionTest.java
+++ b/java/machine/machine-core/src/test/java/org/apache/tinkerpop/machine/bytecode/InstructionTest.java
@@ -29,11 +29,11 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;
*/
class InstructionTest {
- private final Instruction<Long> a = new Instruction<>(LongCoefficient.create(10L), "atest", 1, 2, 3);
- private final Instruction<Long> b = new Instruction<>(LongCoefficient.create(10L), "atest", 1, 2, 3);
- private final Instruction<Long> c = new Instruction<>(LongCoefficient.create(10L), "atest", 1, 2);
- private final Instruction<Long> d = new Instruction<>(LongCoefficient.create(10L), "btest", 1, 2, 3);
- private final Instruction<Long> e = new Instruction<>(LongCoefficient.create(1L), "btest", 1, 2, 3);
+ private final Instruction<Long> a = new Instruction<>(LongCoefficient.create(10L), null, "atest", 1, 2, 3);
+ private final Instruction<Long> b = new Instruction<>(LongCoefficient.create(10L), null, "atest", 1, 2, 3);
+ private final Instruction<Long> c = new Instruction<>(LongCoefficient.create(10L), null, "atest", 1, 2);
+ private final Instruction<Long> d = new Instruction<>(LongCoefficient.create(10L), null, "btest", 1, 2, 3);
+ private final Instruction<Long> e = new Instruction<>(LongCoefficient.create(1L), null, "btest", 1, 2, 3);
@Test
void testMethods() {
diff --git a/java/machine/machine-core/src/test/java/org/apache/tinkerpop/machine/bytecode/compiler/CompilationTest.java b/java/machine/machine-core/src/test/java/org/apache/tinkerpop/machine/bytecode/compiler/CompilationTest.java
index 1970f60d6f..f59e509bc4 100644
--- a/java/machine/machine-core/src/test/java/org/apache/tinkerpop/machine/bytecode/compiler/CompilationTest.java
+++ b/java/machine/machine-core/src/test/java/org/apache/tinkerpop/machine/bytecode/compiler/CompilationTest.java
@@ -38,9 +38,9 @@ class CompilationTest {
void shouldCloneCorrectly() {
final Bytecode<Long> bytecode = new Bytecode<>();
final Bytecode<Long> inner = new Bytecode<>();
- inner.addInstruction(LongCoefficient.create(), CoreCompiler.Symbols.VALUE, "name");
- bytecode.addInstruction(LongCoefficient.create(), CoreCompiler.Symbols.HAS_KEY, "eq", inner);
- bytecode.addInstruction(LongCoefficient.create(), CoreCompiler.Symbols.COUNT);
+ inner.addInstruction(LongCoefficient.create(), null, CoreCompiler.Symbols.VALUE, "name");
+ bytecode.addInstruction(LongCoefficient.create(), null, CoreCompiler.Symbols.HAS_KEY, "eq", inner);
+ bytecode.addInstruction(LongCoefficient.create(), null, CoreCompiler.Symbols.COUNT);
final Compilation<Long, TTuple, Long> compilationA = Compilation.compile(bytecode);
final Compilation<Long, TTuple, Long> compilationB = compilationA.clone();
diff --git a/java/machine/structure/blueprints/src/main/java/org/apache/tinkerpop/machine/structure/blueprints/data/BlueprintsVertex.java b/java/machine/structure/blueprints/src/main/java/org/apache/tinkerpop/machine/structure/blueprints/data/BlueprintsVertex.java
index 120533e00c..911ab108cd 100644
--- a/java/machine/structure/blueprints/src/main/java/org/apache/tinkerpop/machine/structure/blueprints/data/BlueprintsVertex.java
+++ b/java/machine/structure/blueprints/src/main/java/org/apache/tinkerpop/machine/structure/blueprints/data/BlueprintsVertex.java
@@ -18,10 +18,11 @@
*/
package org.apache.tinkerpop.machine.structure.blueprints.data;
-import org.apache.tinkerpop.machine.structure.util.T2Tuple;
import org.apache.tinkerpop.machine.structure.TSequence;
import org.apache.tinkerpop.machine.structure.graph.TEdge;
import org.apache.tinkerpop.machine.structure.graph.TVertex;
+import org.apache.tinkerpop.machine.structure.util.JSequence;
+import org.apache.tinkerpop.machine.structure.TPair;
import java.io.Serializable;
import java.util.Collections;
@@ -34,13 +35,13 @@ import java.util.UUID;
public class BlueprintsVertex<V> implements TVertex<V>, Serializable {
@Override
- public Iterator<TEdge<V>> inE() {
- return Collections.emptyIterator();
+ public TSequence<TEdge<V>> inE() {
+ return new JSequence<>();
}
@Override
- public Iterator<TEdge<V>> outE() {
- return Collections.emptyIterator();
+ public TSequence<TEdge<V>> outE() {
+ return new JSequence<>();
}
@Override
@@ -58,11 +59,6 @@ public class BlueprintsVertex<V> implements TVertex<V>, Serializable {
}
- @Override
- public void add(String key, V value) {
-
- }
-
@Override
public void remove(String key) {
@@ -89,7 +85,7 @@ public class BlueprintsVertex<V> implements TVertex<V>, Serializable {
}
@Override
- public Iterator<T2Tuple<String, V>> entries() {
+ public Iterator<TPair<String, V>> iterator() {
return Collections.emptyIterator();
}
diff --git a/java/machine/structure/blueprints/src/main/java/org/apache/tinkerpop/machine/structure/blueprints/strategy/provider/BlueprintsVerticesStrategy.java b/java/machine/structure/blueprints/src/main/java/org/apache/tinkerpop/machine/structure/blueprints/strategy/provider/BlueprintsVerticesStrategy.java
index 6b18d77d66..65980d2856 100644
--- a/java/machine/structure/blueprints/src/main/java/org/apache/tinkerpop/machine/structure/blueprints/strategy/provider/BlueprintsVerticesStrategy.java
+++ b/java/machine/structure/blueprints/src/main/java/org/apache/tinkerpop/machine/structure/blueprints/strategy/provider/BlueprintsVerticesStrategy.java
@@ -38,6 +38,6 @@ public class BlueprintsVerticesStrategy extends AbstractStrategy<Strategy.Provid
temp = instruction;
}
if (null != temp)
- BytecodeUtil.replaceInstruction(bytecode, temp, new Instruction<>(temp.coefficient(), BlueprintsCompiler.Symbols.BP_V)); // TODO: as(label)
+ BytecodeUtil.replaceInstruction(bytecode, temp, new Instruction<>(temp.coefficient(), temp.label(), BlueprintsCompiler.Symbols.BP_V));
}
}
diff --git a/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/JDBCDatabase.java b/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/JDBCDatabase.java
index 3e4e93faf5..03f4c45ed9 100644
--- a/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/JDBCDatabase.java
+++ b/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/JDBCDatabase.java
@@ -20,8 +20,8 @@ package org.apache.tinkerpop.machine.structure.jdbc;
import org.apache.tinkerpop.machine.structure.rdbms.TDatabase;
import org.apache.tinkerpop.machine.structure.rdbms.TTable;
-import org.apache.tinkerpop.machine.structure.util.J2Tuple;
-import org.apache.tinkerpop.machine.structure.util.T2Tuple;
+import org.apache.tinkerpop.machine.structure.util.JPair;
+import org.apache.tinkerpop.machine.structure.TPair;
import org.apache.tinkerpop.machine.util.IteratorUtils;
import java.sql.Connection;
@@ -73,11 +73,6 @@ public final class JDBCDatabase implements TDatabase {
}
- @Override
- public void add(final String key, final TTable value) {
- // TODO
- }
-
@Override
public void remove(final String key) {
try {
@@ -89,11 +84,11 @@ public final class JDBCDatabase implements TDatabase {
@Override
public int size() {
- return (int) IteratorUtils.count(this.entries());
+ return (int) IteratorUtils.count(this);
}
@Override
- public Iterator<T2Tuple<String, TTable>> entries() {
+ public Iterator<TPair<String, TTable>> iterator() {
try {
final ResultSet result = this.connection.createStatement().executeQuery("SHOW TABLES");
return new Iterator<>() {
@@ -105,11 +100,11 @@ public final class JDBCDatabase implements TDatabase {
}
@Override
- public T2Tuple<String, TTable> next() {
+ public TPair<String, TTable> next() {
try {
result.next();
final String tableName = result.getString(1);
- final T2Tuple<String, TTable> tuple = new J2Tuple<>(tableName, new JDBCTable(connection, tableName));
+ final TPair<String, TTable> tuple = new JPair<>(tableName, new JDBCTable(connection, tableName));
this.done = result.isLast();
return tuple;
} catch (final SQLException e) {
diff --git a/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/JDBCRow.java b/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/JDBCRow.java
index 36d2c9607c..1b841b8cdc 100644
--- a/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/JDBCRow.java
+++ b/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/JDBCRow.java
@@ -19,8 +19,8 @@
package org.apache.tinkerpop.machine.structure.jdbc;
import org.apache.tinkerpop.machine.structure.rdbms.TRow;
-import org.apache.tinkerpop.machine.structure.util.J2Tuple;
-import org.apache.tinkerpop.machine.structure.util.T2Tuple;
+import org.apache.tinkerpop.machine.structure.util.JPair;
+import org.apache.tinkerpop.machine.structure.TPair;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -73,23 +73,6 @@ final class JDBCRow<V> implements TRow<V> {
}
}
- @Override
- public void add(final String key, final V value) {
- try {
- this.rows.absolute(this.rowId);
- Object v = this.rows.getObject(key);
- if (v instanceof List)
- ((List) v).add(value);
- else {
- v = new ArrayList<>();
- ((ArrayList) v).add(value);
- }
- this.rows.updateObject(key, v);
- } catch (final SQLException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- }
-
@Override
public void remove(final String key) {
try {
@@ -111,7 +94,7 @@ final class JDBCRow<V> implements TRow<V> {
}
@Override
- public Iterator<T2Tuple<String, V>> entries() {
+ public Iterator<TPair<String, V>> iterator() {
try {
this.rows.absolute(this.rowId);
return new Iterator<>() {
@@ -128,9 +111,9 @@ final class JDBCRow<V> implements TRow<V> {
}
@Override
- public T2Tuple<String, V> next() {
+ public TPair<String, V> next() {
try {
- final J2Tuple<String, V> temp = new J2Tuple<>(rows.getMetaData().getColumnName(column), (V) rows.getObject(column));
+ final JPair<String, V> temp = new JPair<>(rows.getMetaData().getColumnName(column), (V) rows.getObject(column));
column++;
return temp;
} catch (final SQLException e) {
diff --git a/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/bytecode/compiler/JDBCCompiler.java b/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/bytecode/compiler/JDBCCompiler.java
index eb75b44851..52506eaf46 100644
--- a/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/bytecode/compiler/JDBCCompiler.java
+++ b/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/bytecode/compiler/JDBCCompiler.java
@@ -21,12 +21,9 @@ package org.apache.tinkerpop.machine.structure.jdbc.bytecode.compiler;
import org.apache.tinkerpop.machine.bytecode.Instruction;
import org.apache.tinkerpop.machine.bytecode.compiler.BytecodeCompiler;
import org.apache.tinkerpop.machine.bytecode.compiler.FunctionType;
-import org.apache.tinkerpop.machine.coefficient.Coefficient;
import org.apache.tinkerpop.machine.function.CFunction;
import org.apache.tinkerpop.machine.structure.jdbc.function.flatmap.SqlFlatMap;
-import java.sql.Connection;
-
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
@@ -38,17 +35,11 @@ public final class JDBCCompiler implements BytecodeCompiler {
// static instance
}
- public static JDBCCompiler instance() {
- return INSTANCE;
- }
-
@Override
public <C> CFunction<C> compile(final Instruction<C> instruction) {
final String op = instruction.op();
- final Coefficient<C> coefficient = instruction.coefficient();
- final String label = instruction.label();
if (op.equals(Symbols.JDBC_SQL))
- return new SqlFlatMap<>(coefficient, label, (Connection) instruction.args()[0], (String) instruction.args()[1], (String) instruction.args()[2], (String) instruction.args()[3]);
+ return SqlFlatMap.compile(instruction);
else
return null;
}
@@ -58,6 +49,10 @@ public final class JDBCCompiler implements BytecodeCompiler {
return op.equals(Symbols.JDBC_SQL) ? FunctionType.FLATMAP : null;
}
+ public static JDBCCompiler instance() {
+ return INSTANCE;
+ }
+
public static class Symbols {
private Symbols() {
diff --git a/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/function/flatmap/SqlFlatMap.java b/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/function/flatmap/SqlFlatMap.java
index af5f2b0777..4863568dd8 100644
--- a/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/function/flatmap/SqlFlatMap.java
+++ b/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/function/flatmap/SqlFlatMap.java
@@ -18,6 +18,7 @@
*/
package org.apache.tinkerpop.machine.structure.jdbc.function.flatmap;
+import org.apache.tinkerpop.machine.bytecode.Instruction;
import org.apache.tinkerpop.machine.coefficient.Coefficient;
import org.apache.tinkerpop.machine.function.AbstractFunction;
import org.apache.tinkerpop.machine.function.initial.Initializing;
@@ -102,4 +103,8 @@ public final class SqlFlatMap<C, S> extends AbstractFunction<C> implements Initi
public SqlFlatMap<C, S> clone() {
return this; // TODO;
}
+
+ public static <C, S> SqlFlatMap<C, S> compile(final Instruction<C> instruction) {
+ return new SqlFlatMap<>(instruction.coefficient(), instruction.label(), (Connection) instruction.args()[0], (String) instruction.args()[1], (String) instruction.args()[2], (String) instruction.args()[3]);
+ }
}
diff --git a/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/strategy/JDBCQueryStrategy.java b/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/strategy/JDBCQueryStrategy.java
index 203bcdb8dc..9ad05c81bd 100644
--- a/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/strategy/JDBCQueryStrategy.java
+++ b/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/strategy/JDBCQueryStrategy.java
@@ -47,7 +47,7 @@ public final class JDBCQueryStrategy extends AbstractStrategy<Strategy.ProviderS
final String query = "SELECT " + as1 + ".*, " + as2 + ".* FROM " + table1 + " AS " + as1 + ", " + table2 + " AS " + as2 + " WHERE " + join;
final Instruction<C> inst = bytecode.getInstructions().remove(0); // HAS_KEY_VALUE
bytecode.getInstructions().remove(0); // PATH
- bytecode.addInstruction(0, inst.coefficient(), "jdbc:sql", db.getConnection(), as1, as2, query);
+ bytecode.addInstruction(0, inst.coefficient(), inst.label(), "jdbc:sql", db.getConnection(), as1, as2, query);
}
}
}
diff --git a/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/strategy/JDBCStrategy.java b/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/strategy/JDBCStrategy.java
index 60a3c285c6..8415412ec0 100644
--- a/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/strategy/JDBCStrategy.java
+++ b/java/machine/structure/jdbc/src/main/java/org/apache/tinkerpop/machine/structure/jdbc/strategy/JDBCStrategy.java
@@ -26,7 +26,6 @@ import org.apache.tinkerpop.machine.strategy.AbstractStrategy;
import org.apache.tinkerpop.machine.strategy.Strategy;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -47,6 +46,7 @@ public final class JDBCStrategy extends AbstractStrategy<Strategy.ProviderStrate
BytecodeUtil.replaceInstruction(bytecode, instruction,
new Instruction<>(
instruction.coefficient(),
+ instruction.label(),
Symbols.DB,
BytecodeUtil.getStructureFactory(BytecodeUtil.getRootBytecode(bytecode)).get().mint()));
}