-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add a replaceColumn method to Page #22493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -456,6 +456,24 @@ private long updateRetainedSize() | |
| return retainedSizeInBytes.longValue(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a new page with the same columns as the original page except for the one column replaced. | ||
| * | ||
| * @param channelIndex the column to replace | ||
| * @param column the replacement column | ||
| * @return a new page with the replacement column substituted for the old column | ||
| */ | ||
| public Page replaceColumn(int channelIndex, Block column) | ||
| { | ||
| if (column.getPositionCount() != positionCount) { | ||
| throw new IllegalArgumentException("New column does not have same number of rows as old column"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace: New column does not have same number of rows as old column -> New block does not have the same number of rows as the page Technically current page implementation allows to have blocks with different number of rows, but I think it's ok to enforce this constraint.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. appendColumn and prependColumn do check for this though interestingly, as you point out, the constructor does not. |
||
| } | ||
|
|
||
| Block[] newBlocks = Arrays.copyOf(blocks, blocks.length); | ||
| newBlocks[channelIndex] = column; | ||
| return Page.wrapBlocksWithoutCopy(newBlocks.length, newBlocks); | ||
| } | ||
|
|
||
| private static class DictionaryBlockIndexes | ||
| { | ||
| private final List<DictionaryBlock> blocks = new ArrayList<>(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check and throw if the channelIndex is invalid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are unit tests that verify the correct exception is thrown in this case.