Skip to content

Commit 3a6e5c4

Browse files
committed
Merge branch '3.8-dev'
2 parents 8bde216 + 54c4271 commit 3a6e5c4

File tree

11 files changed

+166
-71
lines changed

11 files changed

+166
-71
lines changed

gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/IsStepPlaceholder.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import java.util.Collection;
3030
import java.util.EnumSet;
31+
import java.util.Objects;
3132
import java.util.Set;
3233

3334
public final class IsStepPlaceholder<S> extends FilterStep<S> implements GValueHolder<S, S>, IsStepContract<S> {
@@ -65,9 +66,18 @@ public IsStepPlaceholder<S> clone() {
6566
return clone;
6667
}
6768

69+
@Override
70+
public boolean equals(Object o) {
71+
if (this == o) return true;
72+
if (o == null || getClass() != o.getClass()) return false;
73+
if (!super.equals(o)) return false;
74+
IsStepPlaceholder<?> that = (IsStepPlaceholder<?>) o;
75+
return Objects.equals(predicate, that.predicate);
76+
}
77+
6878
@Override
6979
public int hashCode() {
70-
return super.hashCode() ^ this.predicate.hashCode();
80+
return Objects.hash(super.hashCode(), predicate);
7181
}
7282

7383
@Override

gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/TailGlobalStepPlaceholder.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,18 @@ public TailGlobalStepPlaceholder<S> clone() {
7272
return clone;
7373
}
7474

75+
@Override
76+
public boolean equals(Object o) {
77+
if (this == o) return true;
78+
if (o == null || getClass() != o.getClass()) return false;
79+
if (!super.equals(o)) return false;
80+
TailGlobalStepPlaceholder<?> that = (TailGlobalStepPlaceholder<?>) o;
81+
return bypass == that.bypass && Objects.equals(limit, that.limit);
82+
}
83+
7584
@Override
7685
public int hashCode() {
77-
return super.hashCode() ^ Objects.hashCode(this.limit);
86+
return Objects.hash(super.hashCode(), limit, bypass);
7887
}
7988

8089
@Override

gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AbstractAddEdgeStepPlaceholder.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import java.util.Collection;
3030
import java.util.List;
31+
import java.util.Objects;
3132

3233
public abstract class AbstractAddEdgeStepPlaceholder<S> extends AbstractAddElementStepPlaceholder<S, Edge, Event.EdgeAddedEvent> implements AddEdgeStepContract<S> {
3334
protected Traversal.Admin<?, ?> from;
@@ -70,16 +71,18 @@ public void addFrom(final Traversal.Admin<?, ?> fromObject) {
7071
this.integrateChild(this.from);
7172
}
7273

74+
@Override
75+
public boolean equals(Object o) {
76+
if (this == o) return true;
77+
if (o == null || getClass() != o.getClass()) return false;
78+
if (!super.equals(o)) return false;
79+
AbstractAddEdgeStepPlaceholder<?> that = (AbstractAddEdgeStepPlaceholder<?>) o;
80+
return Objects.equals(from, that.from) && Objects.equals(to, that.to);
81+
}
82+
7383
@Override
7484
public int hashCode() {
75-
int hash = super.hashCode();
76-
if (from != null) {
77-
hash ^= from.hashCode();
78-
}
79-
if (to != null) {
80-
hash ^= to.hashCode();
81-
}
82-
return hash;
85+
return Objects.hash(super.hashCode(), from, to);
8386
}
8487

8588
@Override

gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AbstractAddElementStepPlaceholder.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,22 @@ protected E map(Traverser.Admin<S> traverser) {
126126
throw new IllegalStateException("GValuePlaceholder step is not executable");
127127
}
128128

129+
@Override
130+
public boolean equals(Object o) {
131+
if (this == o) return true;
132+
if (o == null || getClass() != o.getClass()) return false;
133+
if (!super.equals(o)) return false;
134+
AbstractAddElementStepPlaceholder<?, ?, ?> that = (AbstractAddElementStepPlaceholder<?, ?, ?>) o;
135+
return Objects.equals(label, that.label) &&
136+
Objects.equals(properties, that.properties) &&
137+
Objects.equals(elementId, that.elementId) &&
138+
Objects.equals(scopeKeys, that.scopeKeys) &&
139+
Objects.equals(withConfiguration, that.withConfiguration);
140+
}
141+
129142
@Override
130143
public int hashCode() {
131-
int hash = super.hashCode();
132-
if (label != null) {
133-
hash ^= label.hashCode();
134-
}
135-
if (elementId != null) {
136-
hash ^= elementId.hashCode();
137-
}
138-
if (properties != null) {
139-
for (Map.Entry<Object, List<Object>> entry : properties.entrySet()) {
140-
hash ^= Objects.hashCode(entry.getKey());
141-
hash ^= Objects.hashCode(entry.getValue());
142-
}
143-
}
144-
hash ^= withConfiguration.hashCode();
145-
return hash;
144+
return Objects.hash(super.hashCode(), label, properties, elementId, scopeKeys, withConfiguration);
146145
}
147146

148147
protected void configureConcreteStep(AddElementStepContract<S, E> step) {

gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AbstractAddVertexStepPlaceholder.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.apache.tinkerpop.gremlin.process.traversal.step.util.event.Event;
2525
import org.apache.tinkerpop.gremlin.structure.Vertex;
2626

27+
import java.util.Objects;
28+
2729
public abstract class AbstractAddVertexStepPlaceholder<S> extends AbstractAddElementStepPlaceholder<S, Vertex, Event.VertexAddedEvent>
2830
implements AddVertexStepContract<S>, GValueHolder<S, Vertex> {
2931

@@ -54,6 +56,20 @@ public boolean hasUserProvidedLabel() {
5456
return userProvidedLabel;
5557
}
5658

59+
@Override
60+
public boolean equals(Object o) {
61+
if (this == o) return true;
62+
if (o == null || getClass() != o.getClass()) return false;
63+
if (!super.equals(o)) return false;
64+
AbstractAddVertexStepPlaceholder<?> that = (AbstractAddVertexStepPlaceholder<?>) o;
65+
return userProvidedLabel == that.userProvidedLabel;
66+
}
67+
68+
@Override
69+
public int hashCode() {
70+
return Objects.hash(super.hashCode(), userProvidedLabel);
71+
}
72+
5773
@Override
5874
public AbstractAddVertexStepPlaceholder<S> clone() {
5975
final AbstractAddVertexStepPlaceholder<S> clone = (AbstractAddVertexStepPlaceholder<S>) super.clone();

gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/CallStepPlaceholder.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,22 @@ public String toString() {
202202
return StringFactory.stepString(this, args.toArray());
203203
}
204204

205+
@Override
206+
public boolean equals(Object o) {
207+
if (this == o) return true;
208+
if (o == null || getClass() != o.getClass()) return false;
209+
if (!super.equals(o)) return false;
210+
CallStepPlaceholder<?, ?> that = (CallStepPlaceholder<?, ?>) o;
211+
return isStart == that.isStart &&
212+
Objects.equals(serviceName, that.serviceName) &&
213+
Objects.equals(staticParams, that.staticParams) &&
214+
Objects.equals(mapTraversal, that.mapTraversal) &&
215+
Objects.equals(parameters, that.parameters);
216+
}
217+
205218
@Override
206219
public int hashCode() {
207-
int hashCode = super.hashCode() ^ Objects.hashCode(this.serviceName);
208-
if (!staticParams.get().isEmpty())
209-
hashCode ^= staticParams.hashCode();
210-
if (mapTraversal != null)
211-
hashCode ^= mapTraversal.hashCode();
212-
if (!parameters.isEmpty())
213-
hashCode ^= parameters.hashCode();
214-
return hashCode;
220+
return Objects.hash(super.hashCode(), isStart, serviceName, staticParams, mapTraversal, parameters);
215221
}
216222

217223
@Override

gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/GraphStepPlaceholder.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,21 @@ protected Traverser.Admin<E> processNextStart() {
112112
throw new IllegalStateException("GraphStepGValueContract is not executable");
113113
}
114114

115+
@Override
116+
public boolean equals(Object o) {
117+
if (this == o) return true;
118+
if (o == null || getClass() != o.getClass()) return false;
119+
if (!super.equals(o)) return false;
120+
GraphStepPlaceholder<?, ?> that = (GraphStepPlaceholder<?, ?>) o;
121+
return isStart == that.isStart &&
122+
onGraphComputer == that.onGraphComputer &&
123+
Objects.equals(returnClass, that.returnClass) &&
124+
Objects.deepEquals(ids, that.ids);
125+
}
126+
115127
@Override
116128
public int hashCode() {
117-
int result = Objects.hash(super.hashCode(), returnClass);
118-
if (ids != null) {
119-
for (Object id : ids) {
120-
result = 31 * result + Objects.hashCode(id);
121-
}
122-
}
123-
return result;
129+
return Objects.hash(super.hashCode(), returnClass, Arrays.hashCode(ids), isStart, onGraphComputer);
124130
}
125131

126132
@Override

gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/TailLocalStepPlaceholder.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,18 @@ public TailLocalStepPlaceholder<S> clone() {
5555
return clone;
5656
}
5757

58+
@Override
59+
public boolean equals(Object o) {
60+
if (this == o) return true;
61+
if (o == null || getClass() != o.getClass()) return false;
62+
if (!super.equals(o)) return false;
63+
TailLocalStepPlaceholder<?> that = (TailLocalStepPlaceholder<?>) o;
64+
return Objects.equals(limit, that.limit);
65+
}
66+
5867
@Override
5968
public int hashCode() {
60-
return super.hashCode() ^ Objects.hashCode(this.limit);
69+
return Objects.hash(super.hashCode(), limit);
6170
}
6271

6372
@Override

gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/VertexStepPlaceholder.java

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -116,36 +116,20 @@ public String toString() {
116116
return StringFactory.stepString(this, this.direction, Arrays.asList(this.edgeLabels), this.returnClass.getSimpleName().toLowerCase());
117117
}
118118

119+
@Override
120+
public boolean equals(Object o) {
121+
if (this == o) return true;
122+
if (o == null || getClass() != o.getClass()) return false;
123+
if (!super.equals(o)) return false;
124+
VertexStepPlaceholder<?> that = (VertexStepPlaceholder<?>) o;
125+
return Objects.equals(sortEdgeLabels(edgeLabels), sortEdgeLabels(that.edgeLabels)) &&
126+
direction == that.direction &&
127+
Objects.equals(returnClass, that.returnClass);
128+
}
129+
119130
@Override
120131
public int hashCode() {
121-
int result = Objects.hash(super.hashCode(), direction, returnClass);
122-
// edgeLabel's order does not matter because in("x", "y") and in("y", "x") must be considered equal.
123-
if (edgeLabels != null && edgeLabels.length > 0) {
124-
final List<GValue<String>> sortedEdgeLabels = Arrays.stream(edgeLabels)
125-
.sorted(Comparator.nullsLast(new Comparator<GValue<String>>() {
126-
@Override
127-
public int compare(GValue<String> o1, GValue<String> o2) {
128-
// variables come before non-variables
129-
if (o1.isVariable() && !o2.isVariable()) {
130-
return -1;
131-
} else if (!o1.isVariable() && o2.isVariable()) {
132-
return 1;
133-
} else if (o1.isVariable()) {
134-
if (!o2.getName().equals(o1.getName())) {
135-
return o1.getName().compareTo(o2.getName()); // compare by variable name
136-
} else {
137-
return o1.get().compareTo(o2.get()); // use value as tie-breaker
138-
}
139-
} else {
140-
return o1.get().compareTo(o2.get()); // comparison of 2 non-variables
141-
}
142-
}
143-
})).collect(Collectors.toList());
144-
for (final GValue<String> edgeLabel : sortedEdgeLabels) {
145-
result = 31 * result + Objects.hashCode(edgeLabel);
146-
}
147-
}
148-
return result;
132+
return Objects.hash(super.hashCode(), sortEdgeLabels(edgeLabels), direction, returnClass);
149133
}
150134

151135
@Override
@@ -196,4 +180,36 @@ public Collection<GValue<?>> getGValues() {
196180
public void close() throws Exception {
197181
closeIterator();
198182
}
183+
184+
/**
185+
* Helper method for hashCode() and equals() as edgeLabel's order should not influence equality.
186+
* in("x", "y") and in("y", "x") must be considered equal.
187+
*/
188+
private List<GValue<String>> sortEdgeLabels(final GValue<String>[] gValues) {
189+
if (edgeLabels == null || edgeLabels.length == 0) {
190+
return List.of();
191+
}
192+
final List<GValue<String>> sortedEdgeLabels = Arrays.stream(edgeLabels)
193+
.sorted(Comparator.nullsLast(new Comparator<GValue<String>>() {
194+
@Override
195+
public int compare(GValue<String> o1, GValue<String> o2) {
196+
// variables come before non-variables
197+
if (o1.isVariable() && !o2.isVariable()) {
198+
return -1;
199+
} else if (!o1.isVariable() && o2.isVariable()) {
200+
return 1;
201+
} else if (o1.isVariable()) {
202+
if (!o2.getName().equals(o1.getName())) {
203+
return o1.getName().compareTo(o2.getName()); // compare by variable name
204+
} else {
205+
return o1.get().compareTo(o2.get()); // use value as tie-breaker
206+
}
207+
} else {
208+
return o1.get().compareTo(o2.get()); // comparison of 2 non-variables
209+
}
210+
}
211+
})).collect(Collectors.toList());
212+
213+
return sortedEdgeLabels;
214+
}
199215
}

gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AddPropertyStepPlaceholder.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,22 @@ public void setTraversal(final Traversal.Admin<?, ?> parentTraversal) {
119119
this.getLocalChildren().forEach(this::integrateChild);
120120
}
121121

122+
@Override
123+
public boolean equals(Object o) {
124+
if (this == o) return true;
125+
if (o == null || getClass() != o.getClass()) return false;
126+
if (!super.equals(o)) return false;
127+
AddPropertyStepPlaceholder<?> that = (AddPropertyStepPlaceholder<?>) o;
128+
return Objects.equals(key, that.key) &&
129+
Objects.equals(value, that.value) &&
130+
cardinality == that.cardinality &&
131+
Objects.equals(properties, that.properties) &&
132+
Objects.equals(withConfiguration, that.withConfiguration);
133+
}
134+
122135
@Override
123136
public int hashCode() {
124-
return super.hashCode() ^ Objects.hashCode(key) ^ Objects.hashCode(value) ^ Objects.hashCode(cardinality) ^
125-
Objects.hashCode(properties) ^ Objects.hashCode(withConfiguration);
137+
return Objects.hash(super.hashCode(), key, value, cardinality, properties, withConfiguration);
126138
}
127139

128140
@Override

0 commit comments

Comments
 (0)