Skip to content

Commit 5209a96

Browse files
committed
Changing hasIncompleteVersionstamp to use iteration rather than stream processing
1 parent 59cdb8a commit 5209a96

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

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

Lines changed: 1 addition & 1 deletion
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
/**

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

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -776,25 +776,44 @@ else if(item instanceof Tuple)
776776
return packedSize;
777777
}
778778

779-
static boolean hasIncompleteVersionstamp(Stream<?> items) {
780-
return items.anyMatch(item -> {
781-
if(item == null) {
782-
return false;
783-
}
784-
else if(item instanceof Versionstamp) {
785-
return !((Versionstamp) item).isComplete();
786-
}
787-
else if(item instanceof Tuple) {
788-
return hasIncompleteVersionstamp(((Tuple) item).stream());
789-
}
790-
else if(item instanceof Collection<?>) {
791-
return hasIncompleteVersionstamp(((Collection<?>) item).stream());
792-
}
793-
else {
794-
return false;
795-
}
796-
});
797-
}
779+
static boolean hasIncompleteVersionstamp(Collection<?> items){
780+
boolean isComplete = true;
781+
for(Object itm: items){
782+
if(itm instanceof Versionstamp){
783+
isComplete = ((Versionstamp)itm).isComplete();
784+
}else if(itm instanceof Tuple){
785+
isComplete = hasIncompleteVersionstamp(((Tuple)itm).getItems());
786+
}else if(itm instanceof Collection<?>){
787+
isComplete = hasIncompleteVersionstamp((Collection<?>)itm);
788+
}
789+
790+
791+
if(!isComplete){
792+
break;
793+
}
794+
}
795+
return !isComplete;
796+
}
797+
798+
// static boolean hasIncompleteVersionstamp(Stream<?> items) {
799+
// return items.anyMatch(item -> {
800+
// if(item == null) {
801+
// return false;
802+
// }
803+
// else if(item instanceof Versionstamp) {
804+
// return !((Versionstamp) item).isComplete();
805+
// }
806+
// else if(item instanceof Tuple) {
807+
// return hasIncompleteVersionstamp(((Tuple) item).stream());
808+
// }
809+
// else if(item instanceof Collection<?>) {
810+
// return hasIncompleteVersionstamp(((Collection<?>) item).stream());
811+
// }
812+
// else {
813+
// return false;
814+
// }
815+
// });
816+
// }
798817

799818
public static void main(String[] args) {
800819
try {

0 commit comments

Comments
 (0)