-
Notifications
You must be signed in to change notification settings - Fork 72
fix!: use the same cell reference constructor in order to ensure consistency #4634
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
base: main
Are you sure you want to change the base?
Changes from all commits
245d39b
2af83b6
fe708df
6227ec5
268ff65
066e1d2
7105375
893994a
31fa8ac
8f08024
9158159
5476fdd
09928c6
530e9e7
27ce9d9
f58821b
60dd913
e20b0fe
e380adc
8760538
b02d467
ce3b070
ef5e461
e874832
2327868
98e7b94
b236546
ae9f2d2
ae25f93
30c0bcb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. Would it make sense to make The @Override
public boolean contains(Object object) {
if (this.isEmpty()) {
return false;
}
if (object instanceof CellReference cellReference) {
if (cellReference.getSheetName() == null) {
CellReference cellWithSheetName = new CellReference(
this.iterator().next().getSheetName(),
cellReference.getRow(), cellReference.getCol(),
cellReference.isRowAbsolute(),
cellReference.isColAbsolute());
return super.contains(cellWithSheetName);
}
}
return super.contains(object); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/** | ||
* Copyright 2000-2023 Vaadin Ltd. | ||
* | ||
* This program is available under Vaadin Commercial License and Service Terms. | ||
* | ||
* See {@literal <https://vaadin.com/commercial-license-and-service-terms>} for the full | ||
* license. | ||
*/ | ||
package com.vaadin.flow.component.spreadsheet; | ||
|
||
import java.util.Collections; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
import org.apache.poi.ss.util.CellReference; | ||
|
||
/** | ||
* CellSet is a set of cells that also provides utilities regarding the contents | ||
* of the set. | ||
*/ | ||
public class CellSet { | ||
|
||
private final Set<CellReference> cells; | ||
|
||
/** | ||
* Creates a set with the specified cells | ||
* | ||
* @param cells | ||
* cells to construct the set with, not {@code null} | ||
*/ | ||
public CellSet(Set<CellReference> cells) { | ||
Objects.requireNonNull(cells, "Cells cannot be null"); | ||
this.cells = cells; | ||
} | ||
|
||
/** | ||
* Gets an unmodifiable set of the cells | ||
* | ||
* @return an unmodifiable set of the cells | ||
*/ | ||
public Set<CellReference> getCells() { | ||
return Collections.unmodifiableSet(cells); | ||
} | ||
|
||
/** | ||
* Gets the number of the cells | ||
* | ||
* @return number of cells | ||
*/ | ||
public int size() { | ||
return cells.size(); | ||
} | ||
|
||
/** | ||
* Whether the set contains the specified cell. Does not take the sheet | ||
* names of the cells in set into account if the sheet name of the cell | ||
* reference is {@code null}. | ||
* | ||
* @param cellReference | ||
* cell to be checked whether it exists in the set | ||
* @return {@code true} if set contains the specified cell, {@code false} | ||
* otherwise | ||
*/ | ||
public boolean contains(CellReference cellReference) { | ||
if (cells.isEmpty()) { | ||
return false; | ||
} | ||
if (cellReference.getSheetName() == null) { | ||
CellReference cellWithSheetName = new CellReference( | ||
cells.iterator().next().getSheetName(), | ||
cellReference.getRow(), cellReference.getCol(), | ||
cellReference.isRowAbsolute(), | ||
cellReference.isColAbsolute()); | ||
return cells.contains(cellWithSheetName); | ||
} | ||
return cells.contains(cellReference); | ||
} | ||
|
||
/** | ||
* Whether the set contains the specified cell. Does not take the sheet | ||
* names of the cells in set into account. | ||
* | ||
* @param row | ||
* row index of the cell, 0-based | ||
* @param col | ||
* col index of the cell, 0-based | ||
* @return {@code true} if set contains the specified cell, {@code false} | ||
* otherwise | ||
*/ | ||
public boolean contains(int row, int col) { | ||
return contains(new CellReference(row, col)); | ||
} | ||
|
||
/** | ||
* Whether the set contains the specified cell | ||
* | ||
* @param row | ||
* row index of the cell, 0-based | ||
* @param col | ||
* col index of the cell, 0-based | ||
* @param sheetName | ||
* sheet name of the cell, not {@code null} | ||
* @return {@code true} if set contains the specified cell, {@code false} | ||
* otherwise | ||
*/ | ||
public boolean contains(int row, int col, String sheetName) { | ||
Objects.requireNonNull(sheetName, "The sheet name cannot be null"); | ||
return contains(new CellReference(sheetName, row, col, false, false)); | ||
} | ||
} |
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.
NULL_DEREFERENCE: object
selectedCellReference
last assigned on line 398 could be null and is dereferenced by call toisCellInRange(...)
at line 401.ℹ️ Learn about @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
@sonatype-lift ignore
@sonatype-lift ignoreall
@sonatype-lift exclude <file|issue|path|tool>
file|issue|path|tool
from Lift findings by updating your config.toml fileNote: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.
Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]