Skip to content

Commit afa1120

Browse files
committed
Changing hasIncompleteVersionstamp to use iteration rather than stream processing #7543
1 parent 4103b16 commit afa1120

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

bindings/java/src/main/com/apple/foundationdb/tuple/Tuple.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private Tuple(Tuple original, Object newItem, boolean itemHasIncompleteVersionst
8686

8787
private Tuple(List<Object> elements) {
8888
this.elements = elements;
89-
incompleteVersionstamp = TupleUtil.hasIncompleteVersionstamp(elements.stream());
89+
incompleteVersionstamp = TupleUtil.hasIncompleteVersionstamp(elements);
9090
}
9191

9292
/**
@@ -265,7 +265,7 @@ public Tuple add(Versionstamp v) {
265265
* @return a newly created {@code Tuple}
266266
*/
267267
public Tuple add(List<?> l) {
268-
return new Tuple(this, l, TupleUtil.hasIncompleteVersionstamp(l.stream()));
268+
return new Tuple(this, l, TupleUtil.hasIncompleteVersionstamp(l));
269269
}
270270

271271
/**
@@ -483,6 +483,15 @@ public List<Object> getItems() {
483483
return new ArrayList<>(elements);
484484
}
485485

486+
/**
487+
* Gets the unserialized contents of this {@code Tuple} without copying into a new list.
488+
*
489+
* @return the elements that make up this {@code Tuple}.
490+
*/
491+
List<Object> getRawItems() {
492+
return elements;
493+
}
494+
486495
/**
487496
* Gets a {@link Stream} of the unserialized contents of this {@code Tuple}.
488497
*

bindings/java/src/main/com/apple/foundationdb/tuple/TupleUtil.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -776,24 +776,26 @@ else if(item instanceof Tuple)
776776
return packedSize;
777777
}
778778

779-
static boolean hasIncompleteVersionstamp(Stream<?> items) {
780-
return items.anyMatch(item -> {
779+
static boolean hasIncompleteVersionstamp(Collection<?> items) {
780+
boolean hasIncompleteVersionstamp = false;
781+
for (Object item: items) {
781782
if(item == null) {
782-
return false;
783+
continue;
783784
}
784785
else if(item instanceof Versionstamp) {
785-
return !((Versionstamp) item).isComplete();
786+
hasIncompleteVersionstamp = !((Versionstamp) item).isComplete();
786787
}
787788
else if(item instanceof Tuple) {
788-
return hasIncompleteVersionstamp(((Tuple) item).stream());
789+
hasIncompleteVersionstamp = hasIncompleteVersionstamp(((Tuple) item).getRawItems());
789790
}
790791
else if(item instanceof Collection<?>) {
791-
return hasIncompleteVersionstamp(((Collection<?>) item).stream());
792+
hasIncompleteVersionstamp = hasIncompleteVersionstamp( (Collection<?>) item);
792793
}
793-
else {
794-
return false;
794+
if (hasIncompleteVersionstamp) {
795+
return hasIncompleteVersionstamp;
795796
}
796-
});
797+
};
798+
return hasIncompleteVersionstamp;
797799
}
798800

799801
public static void main(String[] args) {

0 commit comments

Comments
 (0)