use isEmpty()

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896541 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-12-30 20:34:10 +00:00
parent 15b1c51f33
commit 9de29ea3fc
27 changed files with 34 additions and 39 deletions

View File

@ -537,8 +537,8 @@ public final class ZipPackage extends OPCPackage {
try { try {
// If the core properties part does not exist in the part list, // If the core properties part does not exist in the part list,
// we save it as well // we save it as well
if (this.getPartsByRelationshipType(PackageRelationshipTypes.CORE_PROPERTIES).size() == 0 && if (this.getPartsByRelationshipType(PackageRelationshipTypes.CORE_PROPERTIES).isEmpty() &&
this.getPartsByRelationshipType(PackageRelationshipTypes.CORE_PROPERTIES_ECMA376).size() == 0 ) { this.getPartsByRelationshipType(PackageRelationshipTypes.CORE_PROPERTIES_ECMA376).isEmpty()) {
LOG.atDebug().log("Save core properties part"); LOG.atDebug().log("Save core properties part");
// Ensure that core properties are added if missing // Ensure that core properties are added if missing

View File

@ -108,7 +108,7 @@ public class XSSFBReader extends XSSFReader {
public XSSFBStylesTable getXSSFBStylesTable() throws IOException { public XSSFBStylesTable getXSSFBStylesTable() throws IOException {
ArrayList<PackagePart> parts = pkg.getPartsByContentType(XSSFBRelation.STYLES_BINARY.getContentType()); ArrayList<PackagePart> parts = pkg.getPartsByContentType(XSSFBRelation.STYLES_BINARY.getContentType());
if(parts.size() == 0) return null; if(parts.isEmpty()) return null;
// Create the Styles Table, and associate the Themes if present // Create the Styles Table, and associate the Themes if present
try (InputStream stream = parts.get(0).getInputStream()) { try (InputStream stream = parts.get(0).getInputStream()) {

View File

@ -144,7 +144,7 @@ public class XSSFReader {
public SharedStrings getSharedStringsTable() throws IOException, InvalidFormatException { public SharedStrings getSharedStringsTable() throws IOException, InvalidFormatException {
ArrayList<PackagePart> parts = pkg.getPartsByContentType(XSSFRelation.SHARED_STRINGS.getContentType()); ArrayList<PackagePart> parts = pkg.getPartsByContentType(XSSFRelation.SHARED_STRINGS.getContentType());
try { try {
return parts.size() == 0 ? null : return parts.isEmpty() ? null :
useReadOnlySharedStringsTable ? new ReadOnlySharedStringsTable(parts.get(0)) : useReadOnlySharedStringsTable ? new ReadOnlySharedStringsTable(parts.get(0)) :
new SharedStringsTable(parts.get(0)); new SharedStringsTable(parts.get(0));
} catch (SAXException se) { } catch (SAXException se) {
@ -158,7 +158,7 @@ public class XSSFReader {
*/ */
public StylesTable getStylesTable() throws IOException, InvalidFormatException { public StylesTable getStylesTable() throws IOException, InvalidFormatException {
ArrayList<PackagePart> parts = pkg.getPartsByContentType(XSSFRelation.STYLES.getContentType()); ArrayList<PackagePart> parts = pkg.getPartsByContentType(XSSFRelation.STYLES.getContentType());
if (parts.size() == 0) return null; if (parts.isEmpty()) return null;
// Create the Styles Table, and associate the Themes if present // Create the Styles Table, and associate the Themes if present
StylesTable styles = new StylesTable(parts.get(0)); StylesTable styles = new StylesTable(parts.get(0));

View File

@ -198,7 +198,7 @@ public class SXSSFSheet implements Sheet, OoxmlSheetExtensions {
if(_writer.getNumberOfFlushedRows() > 0) { if(_writer.getNumberOfFlushedRows() > 0) {
return _writer.getLowestIndexOfFlushedRows(); return _writer.getLowestIndexOfFlushedRows();
} }
return _rows.size() == 0 ? -1 : _rows.firstKey(); return _rows.isEmpty() ? -1 : _rows.firstKey();
} }
/** /**
@ -208,7 +208,7 @@ public class SXSSFSheet implements Sheet, OoxmlSheetExtensions {
*/ */
@Override @Override
public int getLastRowNum() { public int getLastRowNum() {
return _rows.size() == 0 ? -1 : _rows.lastKey(); return _rows.isEmpty() ? -1 : _rows.lastKey();
} }
/** /**

View File

@ -304,7 +304,7 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
*/ */
@Override @Override
public short getFirstCellNum() { public short getFirstCellNum() {
return (short)(_cells.size() == 0 ? -1 : _cells.firstKey()); return (short)(_cells.isEmpty() ? -1 : _cells.firstKey());
} }
/** /**
@ -328,7 +328,7 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
*/ */
@Override @Override
public short getLastCellNum() { public short getLastCellNum() {
return (short)(_cells.size() == 0 ? -1 : (_cells.lastKey() + 1)); return (short)(_cells.isEmpty() ? -1 : (_cells.lastKey() + 1));
} }
/** /**

View File

@ -2835,7 +2835,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet, OoxmlSheetEx
*/ */
@Beta @Beta
public void copyRows(List<? extends Row> srcRows, int destStartRow, CellCopyPolicy policy) { public void copyRows(List<? extends Row> srcRows, int destStartRow, CellCopyPolicy policy) {
if (srcRows == null || srcRows.size() == 0) { if (srcRows == null || srcRows.isEmpty()) {
throw new IllegalArgumentException("No rows to copy"); throw new IllegalArgumentException("No rows to copy");
} }
final Row srcStartRow = srcRows.get(0); final Row srcStartRow = srcRows.get(0);

View File

@ -1383,7 +1383,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
sheets.remove(index); sheets.remove(index);
// only set new sheet if there are still some left // only set new sheet if there are still some left
if(sheets.size() == 0) { if(sheets.isEmpty()) {
return; return;
} }

View File

@ -503,7 +503,7 @@ public abstract class XWPFAbstractFootnoteEndnote implements Iterable<XWPFParag
*/ */
public XWPFTable createTable() { public XWPFTable createTable() {
XWPFTable table = new XWPFTable(ctFtnEdn.addNewTbl(), this); XWPFTable table = new XWPFTable(ctFtnEdn.addNewTbl(), this);
if (bodyElements.size() == 0) { if (bodyElements.isEmpty()) {
XWPFParagraph p = createParagraph(); XWPFParagraph p = createParagraph();
ensureFootnoteRef(p); ensureFootnoteRef(p);
} }

View File

@ -618,7 +618,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
*/ */
private int getBodyElementSpecificPos(int pos, List<? extends IBodyElement> list) { private int getBodyElementSpecificPos(int pos, List<? extends IBodyElement> list) {
// If there's nothing to find, skip it // If there's nothing to find, skip it
if (list.size() == 0) { if (list.isEmpty()) {
return -1; return -1;
} }

View File

@ -603,7 +603,7 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo
@Override @Override
protected void prepareForCommit() { protected void prepareForCommit() {
// must contain at least an empty paragraph // must contain at least an empty paragraph
if (bodyElements.size() == 0) { if (bodyElements.isEmpty()) {
createParagraph(); createParagraph();
} }
@ -611,7 +611,7 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo
for (XWPFTable tbl : tables) { for (XWPFTable tbl : tables) {
for (XWPFTableRow row : tbl.tableRows) { for (XWPFTableRow row : tbl.tableRows) {
for (XWPFTableCell cell : row.getTableCells()) { for (XWPFTableCell cell : row.getTableCells()) {
if (cell.getBodyElements().size() == 0) { if (cell.getBodyElements().isEmpty()) {
cell.addParagraph(); cell.addParagraph();
} }
} }

View File

@ -237,10 +237,10 @@ public class XWPFTable implements IBodyElement, ISDTContents {
/** /**
* Add a new cell at the end of each row in this table, creating a new column. * Add a new cell at the end of each row in this table, creating a new column.
* If rows have different numbers of columns, will still append a cell to each row. * If rows have different numbers of columns, will still append a cell to each row.
* Currently does not match the width of existing columns. * Currently, does not match the width of existing columns.
*/ */
public void addNewCol() { public void addNewCol() {
if (tableRows.size() == 0) { if (tableRows.isEmpty()) {
createRow(); createRow();
} }
for (XWPFTableRow tableRow : tableRows) { for (XWPFTableRow tableRow : tableRows) {

View File

@ -441,7 +441,7 @@ public class XWPFTableCell implements IBody, ICell {
} }
public void setText(String text) { public void setText(String text) {
XWPFParagraph par = (paragraphs.size() == 0) ? addParagraph() : paragraphs.get(0); XWPFParagraph par = paragraphs.isEmpty() ? addParagraph() : paragraphs.get(0);
par.createRun().setText(text); par.createRun().setText(text);
} }

View File

@ -31,7 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
/** /**
* Testcase for function XLOOKUP() * Testcase for function XLOOKUP()
*/ */
public class TestXSSFXLookupFunction { class TestXSSFXLookupFunction {
//https://support.microsoft.com/en-us/office/xlookup-function-b7fd680e-6d10-43e6-84f9-88eae8bf5929 //https://support.microsoft.com/en-us/office/xlookup-function-b7fd680e-6d10-43e6-84f9-88eae8bf5929

View File

@ -242,7 +242,7 @@ public class CHPBinTable
} }
} }
if ( chpxs.size() == 0 ) if ( chpxs.isEmpty() )
{ {
LOG.atWarn().log("Text piece [{}; {}) has no CHPX. Creating new one.", box(startInclusive),box(boundary)); LOG.atWarn().log("Text piece [{}; {}) has no CHPX. Creating new one.", box(startInclusive),box(boundary));
// create it manually // create it manually

View File

@ -215,7 +215,7 @@ public class PAPBinTable
lastPapxIndex = oldPapxSortedByEndPos.size() - 1; lastPapxIndex = oldPapxSortedByEndPos.size() - 1;
} }
if ( papxs.size() == 0 ) if ( papxs.isEmpty() )
{ {
LOG.atWarn().log("Paragraph [{}; {}) has no PAPX. Creating new one.", box(startInclusive),box(endExclusive)); LOG.atWarn().log("Paragraph [{}; {}) has no PAPX. Creating new one.", box(startInclusive),box(endExclusive));
// create it manually // create it manually

View File

@ -889,7 +889,7 @@ public class Range {
private static int binarySearchStart( List<? extends PropertyNode<?>> rpl, private static int binarySearchStart( List<? extends PropertyNode<?>> rpl,
int start ) int start )
{ {
if ( rpl.size() == 0 ) if ( rpl.isEmpty())
return -1; return -1;
if ( rpl.get( 0 ).getStart() >= start ) if ( rpl.get( 0 ).getStart() >= start )
return 0; return 0;

View File

@ -347,7 +347,7 @@ public final class ExtractorFactory {
} }
// Create the extractors // Create the extractors
if(dirs.size() == 0 && nonPOIFS.size() == 0){ if(dirs.isEmpty() && nonPOIFS.isEmpty()){
return new POITextExtractor[0]; return new POITextExtractor[0];
} }

View File

@ -117,7 +117,7 @@ public abstract class AbstractEscherHolderRecord extends Record {
@Override @Override
public int getRecordSize() { public int getRecordSize() {
byte[] rawData = getRawData(); byte[] rawData = getRawData();
if (escherRecords.size() == 0 && rawData != null) { if (escherRecords.isEmpty() && rawData != null) {
// XXX: It should be possible to derive this without concatenating the array, too. // XXX: It should be possible to derive this without concatenating the array, too.
return rawData.length; return rawData.length;
} }

View File

@ -82,7 +82,7 @@ public final class DrawingGroupRecord extends AbstractEscherHolderRecord {
public int serialize(int offset, byte[] data) public int serialize(int offset, byte[] data)
{ {
byte[] rawData = getRawData(); byte[] rawData = getRawData();
if (getEscherRecords().size() == 0 && rawData != null) if (getEscherRecords().isEmpty() && rawData != null)
{ {
return writeData( offset, data, rawData ); return writeData( offset, data, rawData );
} }
@ -117,8 +117,7 @@ public final class DrawingGroupRecord extends AbstractEscherHolderRecord {
private int getRawDataSize() { private int getRawDataSize() {
List<EscherRecord> escherRecords = getEscherRecords(); List<EscherRecord> escherRecords = getEscherRecords();
byte[] rawData = getRawData(); byte[] rawData = getRawData();
if (escherRecords.size() == 0 && rawData != null) if (escherRecords.isEmpty() && rawData != null) {
{
return rawData.length; return rawData.length;
} }
int size = 0; int size = 0;

View File

@ -337,7 +337,7 @@ public class UnicodeString implements Comparable<UnicodeString>, Duplicatable, G
public void removeFormatRun(FormatRun r) { public void removeFormatRun(FormatRun r) {
field_4_format_runs.remove(r); field_4_format_runs.remove(r);
if (field_4_format_runs.size() == 0) { if (field_4_format_runs.isEmpty()) {
field_4_format_runs = null; field_4_format_runs = null;
field_2_optionflags = richText.clearByte(field_2_optionflags); field_2_optionflags = richText.clearByte(field_2_optionflags);
} }

View File

@ -316,7 +316,7 @@ public final class HSSFSheet implements Sheet {
_sheet.removeRow(hrow.getRowRecord()); _sheet.removeRow(hrow.getRowRecord());
// if there are no more rows, then reset first/last // if there are no more rows, then reset first/last
if(_rows.size() == 0) { if(_rows.isEmpty()) {
_firstrow = -1; _firstrow = -1;
_lastrow = -1; _lastrow = -1;
} }

View File

@ -150,13 +150,11 @@ class POIFSReaderRegistry
} }
private void dropDocument(final POIFSReaderListener listener, private void dropDocument(final POIFSReaderListener listener,
final DocumentDescriptor descriptor) final DocumentDescriptor descriptor) {
{
Set<POIFSReaderListener> listeners = chosenDocumentDescriptors.get(descriptor); Set<POIFSReaderListener> listeners = chosenDocumentDescriptors.get(descriptor);
listeners.remove(listener); listeners.remove(listener);
if (listeners.size() == 0) if (listeners.isEmpty()) {
{
chosenDocumentDescriptors.remove(descriptor); chosenDocumentDescriptors.remove(descriptor);
} }
} }

View File

@ -583,7 +583,7 @@ public class POIFSFileSystem extends BlockStore
offset++; offset++;
// Chain it // Chain it
if (_xbat_blocks.size() == 0) { if (_xbat_blocks.isEmpty()) {
_header.setXBATStart(offset); _header.setXBATStart(offset);
} else { } else {
_xbat_blocks.get(_xbat_blocks.size() - 1).setValueAt( _xbat_blocks.get(_xbat_blocks.size() - 1).setValueAt(

View File

@ -48,7 +48,7 @@ import static org.apache.poi.ss.format.CellFormatter.quote;
*/ */
@SuppressWarnings("RegExpRepeatedSpace") @SuppressWarnings("RegExpRepeatedSpace")
public class CellFormatPart { public class CellFormatPart {
private static final Logger LOG = LogManager.getLogger(CellFormat.class.getName()); private static final Logger LOG = LogManager.getLogger(CellFormatPart.class);
static final Map<String, Color> NAMED_COLORS; static final Map<String, Color> NAMED_COLORS;

View File

@ -598,7 +598,7 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
} }
final Set<ValueAndFormat> avgSet = new LinkedHashSet<>(1); final Set<ValueAndFormat> avgSet = new LinkedHashSet<>(1);
avgSet.add(new ValueAndFormat(allValues.size() == 0 ? 0 : total / allValues.size(), null, decimalTextFormat)); avgSet.add(new ValueAndFormat(allValues.isEmpty() ? 0 : total / allValues.size(), null, decimalTextFormat));
final double stdDev = allValues.size() <= 1 ? 0 : ((NumberEval) AggregateFunction.STDEV.evaluate(pop, 0, 0)).getNumberValue(); final double stdDev = allValues.size() <= 1 ? 0 : ((NumberEval) AggregateFunction.STDEV.evaluate(pop, 0, 0)).getNumberValue();
avgSet.add(new ValueAndFormat(stdDev, null, decimalTextFormat)); avgSet.add(new ValueAndFormat(stdDev, null, decimalTextFormat));

View File

@ -93,7 +93,7 @@ final class TextJoinFunction implements FreeRefFunction {
} }
// Join the list of values with the specified delimiter and return // Join the list of values with the specified delimiter and return
if (delimiterArgs.size() == 0) { if (delimiterArgs.isEmpty()) {
return new StringEval(String.join("", textValues)); return new StringEval(String.join("", textValues));
} else if (delimiterArgs.size() == 1) { } else if (delimiterArgs.size() == 1) {
String delimiter = laxValueToString(delimiterArgs.get(0)); String delimiter = laxValueToString(delimiterArgs.get(0));

View File

@ -22,8 +22,6 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;