Skip to content

Commit

Permalink
#901
Browse files Browse the repository at this point in the history
  • Loading branch information
babyfish-ct committed Nov 26, 2024
1 parent 0cc2756 commit ceb72f0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,7 @@ void merge(E data) {
return;
}
int arrLen = originalArr == null ? 1 : originalArr.length;
this.originalCount++;
if (originalCount > arrLen) {
if (originalCount >= arrLen) {
E[] arr = (E[])new Object[arrLen * 2];
if (arrLen == 1) {
arr[0] = this.data;
Expand All @@ -350,7 +349,7 @@ void merge(E data) {
this.originalArr = arr;
}
assert originalArr != null;
originalArr[arrLen] = data;
originalArr[originalCount++] = data;
this.data = data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,32 @@ public void testDuplicateKey() {
books.items().toString()
);
}

@Test
public void testEsNode() {
EsNode<Book> books = new EsNode<>(
0,
Immutables.createBook(draft -> {}),
null,
null,
null
);
assertContentEquals("[{}]", books.getOriginalEntities());
books.merge(Immutables.createBook(draft -> {}));
assertContentEquals("[{}, {}]", books.getOriginalEntities());
books.merge(Immutables.createBook(draft -> {}));
assertContentEquals("[{}, {}, {}]", books.getOriginalEntities());
books.merge(Immutables.createBook(draft -> {}));
assertContentEquals("[{}, {}, {}, {}]", books.getOriginalEntities());
books.merge(Immutables.createBook(draft -> {}));
assertContentEquals("[{}, {}, {}, {}, {}]", books.getOriginalEntities());
books.merge(Immutables.createBook(draft -> {}));
assertContentEquals("[{}, {}, {}, {}, {}, {}]", books.getOriginalEntities());
books.merge(Immutables.createBook(draft -> {}));
assertContentEquals("[{}, {}, {}, {}, {}, {}, {}]", books.getOriginalEntities());
books.merge(Immutables.createBook(draft -> {}));
assertContentEquals("[{}, {}, {}, {}, {}, {}, {}, {}]", books.getOriginalEntities());
books.merge(Immutables.createBook(draft -> {}));
assertContentEquals("[{}, {}, {}, {}, {}, {}, {}, {}, {}]", books.getOriginalEntities());
}
}

0 comments on commit ceb72f0

Please sign in to comment.