Skip to content

Commit

Permalink
Updates from PR feedback and added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Cole-Greer committed Nov 28, 2024
1 parent d60eca3 commit b3535ce
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@

import org.apache.tinkerpop.gremlin.process.traversal.step.GType;
import org.apache.tinkerpop.gremlin.process.traversal.step.GValue;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;

import java.lang.reflect.Array;
import java.time.OffsetDateTime;
import java.util.Map;
import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,11 @@ public void setValue(final V value) {

@Override
public boolean test(final V testValue) {
if (this.value instanceof GValue) {
return this.biPredicate.test(testValue, ((GValue<V>) this.value).get());
// this might be a bunch of GValue that need to be resolved. zomg
if (this.value instanceof List) {
return this.biPredicate.test(testValue, (V) ((List) this.value).stream().map(GValue::valueOf).collect(Collectors.toList()));
} else {
// this might be a bunch of GValue that need to be resolved. zomg
if (this.value instanceof List) {
return this.biPredicate.test(testValue, (V) ((List) this.value).stream().map(GValue::valueOf).collect(Collectors.toList()));
} else {
return this.biPredicate.test(testValue, this.value);
}
return this.biPredicate.test(testValue, (V) GValue.valueOf(this.value));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ public int hashCode() {
return Objects.hash(name, type, value);
}

@Override
public GValue<V> clone() {
return new GValue<>(this.name, this.type, this.value);
}

/**
* Create a new {@code Var} from a particular value but without the specified name. If the argument provide is
* already a {@code GValue} then it is returned as-is.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,8 @@ public <S> Object[] getKeyValues(final Traverser.Admin<S> traverser, final Objec
private static <S> Object resolve(final Object object, final Traverser.Admin<S> traverser) {
if (object instanceof Traversal.Admin) {
return TraversalUtil.apply(traverser, (Traversal.Admin<S, ?>) object);
} else if (object instanceof GValue) {
return ((GValue) object).get();
} else {
return object;
return GValue.valueOf(object);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ public static <A> void addSideEffect(final TraversalStrategies traversalStrategi

// don't want the GValue to leak beyond strategy application or else the Supplier will start producing it
// during execution
final ConstantSupplier initialValue = value instanceof GValue ? new ConstantSupplier<>(((GValue) value).get()) : new ConstantSupplier<>(value);
strategy.sideEffects.add(new Triplet<>(key, value instanceof Supplier ? (Supplier) value : initialValue, reducer));
strategy.sideEffects.add(new Triplet<>(key, () -> {
Object initialValue = value instanceof Supplier ? ((Supplier) value).get() : value;
return GValue.valueOf(initialValue);
}, reducer));
}

public boolean contains(final String sideEffectKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,7 @@ public static <K,V> ConcurrentHashMap<K,V> clone(final ConcurrentHashMap<K,V> ma
* element as a new array with just that item in it.
*/
public static <T> T[] addFirst(final T[] array, final T element, final Class<T> clazz) {
if (null == array && null == element) {
final T[] singleElementArray = (T[]) Array.newInstance(clazz, 1);
singleElementArray[0] = null;
return singleElementArray;
} else if (null == array) {
if (null == array) {
final T[] singleElementArray = (T[]) Array.newInstance(clazz, 1);
singleElementArray[0] = element;
return singleElementArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,4 +638,28 @@ public void numberOfShouldThrowBecauseNullIntegerGType() {
public void numberOfShouldThrowBecauseNullObject() {
GValue.numberOf(null);
}

@Test
public void numberOfShouldAcceptAllNumericTypeLiterals() {
assertEquals((byte) 123, GValue.numberOf((byte) 123));
assertEquals((short) 123, GValue.numberOf((short) 123));
assertEquals(123, GValue.numberOf(123));
assertEquals(123l, GValue.numberOf(123l));
assertEquals(123.45f, GValue.numberOf(123.45f));
assertEquals(123.45, GValue.numberOf(123.45));
assertEquals(BigInteger.ONE, GValue.numberOf(BigInteger.ONE));
assertEquals(BigDecimal.ONE, GValue.numberOf(BigDecimal.ONE));
}

@Test
public void numberOfShouldAcceptAllNumericTypeGValues() {
assertEquals((byte) 123, GValue.numberOf(GValue.of((byte) 123)));
assertEquals((short) 123, GValue.numberOf((GValue.of((short) 123))));
assertEquals(123, GValue.numberOf((GValue.of(123))));
assertEquals(123l, GValue.numberOf((GValue.of(123l))));
assertEquals(123.45f, GValue.numberOf((GValue.of(123.45f))));
assertEquals(123.45, GValue.numberOf((GValue.of(123.45))));
assertEquals(BigInteger.ONE, GValue.numberOf((GValue.of(BigInteger.ONE))));
assertEquals(BigDecimal.ONE, GValue.numberOf((GValue.of(BigDecimal.ONE))));
}
}

0 comments on commit b3535ce

Please sign in to comment.