This is an automated email from the ASF dual-hosted git repository.
pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git
The following commit(s) were added to refs/heads/trunk by this push:
new 580c119660 use Set.of (#1198)
580c119660 is described below
commit 580c1196603a8e7a385053fec03d6dc585dfc781
Author: PJ Fanning <[email protected]>
AuthorDate: Sat Aug 1 20:10:19 2026 +0100
use Set.of (#1198)
* use Set.of
* Update StressTestUtils.java
* Revert "Update StressTestUtils.java"
This reverts commit 2b702e606f642e0e04f5c9be8a5801cd41681c7f.
* Update AbstractFileHandler.java
---
.../org/apache/poi/stress/AbstractFileHandler.java | 3 +--
.../org/apache/poi/stress/StressTestUtils.java | 5 +---
.../dsig/SignatureMarshalDefaultListener.java | 4 +--
.../poi/xssf/extractor/XSSFImportFromXML.java | 6 ++---
.../apache/poi/xssf/usermodel/TestXSSFSheet.java | 14 +++++-----
.../apache/poi/hslf/dev/BaseTestPPTIterating.java | 10 +++----
.../poi/ss/formula/atp/WorkdayCalculator.java | 31 ++++++++++------------
.../formula/function/FunctionMetadataReader.java | 9 +++----
.../org/apache/poi/hssf/usermodel/TestBugs.java | 9 +++----
9 files changed, 36 insertions(+), 55 deletions(-)
diff --git
a/poi-integration/src/test/java/org/apache/poi/stress/AbstractFileHandler.java
b/poi-integration/src/test/java/org/apache/poi/stress/AbstractFileHandler.java
index ec651afb13..14c74a4301 100644
---
a/poi-integration/src/test/java/org/apache/poi/stress/AbstractFileHandler.java
+++
b/poi-integration/src/test/java/org/apache/poi/stress/AbstractFileHandler.java
@@ -109,8 +109,7 @@ public abstract class AbstractFileHandler implements
FileHandler {
assertEquals(length, file.length(), "File should not be
modified by extractor");
assertEquals(modified, file.lastModified(), "File should not
be modified by extractor");
- if (extractor instanceof POIOLE2TextExtractor) {
- POIOLE2TextExtractor ole2Extractor =
(POIOLE2TextExtractor) extractor;
+ if (extractor instanceof POIOLE2TextExtractor ole2Extractor) {
ole2Extractor.getRoot();
if (!(ole2Extractor instanceof EventBasedExcelExtractor)) {
ole2Extractor.getSummaryInformation();
diff --git
a/poi-integration/src/test/java/org/apache/poi/stress/StressTestUtils.java
b/poi-integration/src/test/java/org/apache/poi/stress/StressTestUtils.java
index 8e10d7add5..afa079cecf 100644
--- a/poi-integration/src/test/java/org/apache/poi/stress/StressTestUtils.java
+++ b/poi-integration/src/test/java/org/apache/poi/stress/StressTestUtils.java
@@ -18,14 +18,11 @@ package org.apache.poi.stress;
import org.apache.poi.util.IOUtils;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.Set;
public class StressTestUtils {
static Set<String> unmodifiableHashSet(String... a) {
- return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(a)));
+ return Set.of(a);
}
static boolean excludeFile(String path, Set<String> excludeSet) {
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/SignatureMarshalDefaultListener.java
b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/SignatureMarshalDefaultListener.java
index de6f6816a7..c4c8ac99be 100644
---
a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/SignatureMarshalDefaultListener.java
+++
b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/SignatureMarshalDefaultListener.java
@@ -23,7 +23,6 @@ import static
org.apache.poi.poifs.crypt.dsig.facets.SignatureFacet.XML_DIGSIG_N
import static org.apache.poi.poifs.crypt.dsig.facets.SignatureFacet.XML_NS;
import java.util.Arrays;
-import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -52,8 +51,7 @@ public class SignatureMarshalDefaultListener implements
SignatureMarshalListener
private static final String OBJECT_TAG = "Object";
private static final Set<String> IGNORE_NS = new
HashSet<>(Arrays.asList(null, XML_NS, XML_DIGSIG_NS));
- private static final List<String> DIRECT_NS = Collections.unmodifiableList(
- Arrays.asList(OO_DIGSIG_NS, MS_DIGSIG_NS));
+ private static final List<String> DIRECT_NS = List.of(OO_DIGSIG_NS,
MS_DIGSIG_NS);
@Override
public void handleElement(SignatureInfo signatureInfo, Document doc,
EventTarget target, EventListener parentListener) {
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java
b/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java
index aee3afa186..9447e75e18 100644
---
a/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java
+++
b/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java
@@ -22,9 +22,7 @@ import java.io.StringReader;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.Arrays;
import java.util.Date;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -176,10 +174,10 @@ public class XSSFImportFromXML {
STRING("string"), //
DATE("date");
- private Set<String> xmlDataTypes;
+ private final Set<String> xmlDataTypes;
DataType(String... xmlDataTypes) {
- this.xmlDataTypes = new HashSet<>(Arrays.asList(xmlDataTypes));
+ this.xmlDataTypes = Set.of(xmlDataTypes);
}
public static DataType getDataType(String xmlDataType) {
diff --git
a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
index 1f5e62fb74..23bb0babcb 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
@@ -31,10 +31,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -371,9 +369,9 @@ public final class TestXSSFSheet extends BaseTestXSheet {
assertEquals(4, sheet.getNumMergedRegions());
assertEquals(4, ctWorksheet.getMergeCells().getCount());
// test invalid indexes OOBE
- Set<Integer> rmIdx = new HashSet<>(Arrays.asList(5, 6));
+ Set<Integer> rmIdx = Set.of(5, 6);
sheet.removeMergedRegions(rmIdx);
- rmIdx = new HashSet<>(Arrays.asList(1, 3));
+ rmIdx = Set.of(1, 3);
sheet.removeMergedRegions(rmIdx);
assertEquals(2, sheet.getNumMergedRegions());
assertEquals(2, ctWorksheet.getMergeCells().getCount());
@@ -1559,7 +1557,7 @@ public final class TestXSSFSheet extends BaseTestXSheet {
XSSFPivotTable pivotTable =
sheet.createPivotTable(wb.getCreationHelper().createAreaReference("A1:B2"),
new CellReference("H5"));
assertNotNull(pivotTable);
- assertTrue(wb.getPivotTables().size() > 0);
+ assertFalse(wb.getPivotTables().isEmpty());
XSSFPivotTable pivotTable2 =
sheet.createPivotTable(wb.getCreationHelper().createAreaReference("A1:B2"),
new CellReference("L5"), sheet);
assertNotNull(pivotTable2);
@@ -1576,13 +1574,13 @@ public final class TestXSSFSheet extends BaseTestXSheet
{
assertNotNull(sheet);
XSSFPivotTable pivotTable =
sheet.createPivotTable(wb.getCreationHelper().createAreaReference("A1:B2"), new
CellReference("H5"));
assertNotNull(pivotTable);
- assertTrue(wb.getPivotTables().size() > 0);
+ assertFalse(wb.getPivotTables().isEmpty());
assertNotNull(wb);
XSSFSheet sheet2 = wb.createSheet();
XSSFPivotTable pivotTable2 =
sheet2.createPivotTable(wb.getCreationHelper().createAreaReference("A1:B2"),
new CellReference("H5"), sheet);
assertNotNull(pivotTable2);
- assertTrue(wb.getPivotTables().size() > 1);
+ assertFalse(wb.getPivotTables().isEmpty());
}
}
@@ -1595,7 +1593,7 @@ public final class TestXSSFSheet extends BaseTestXSheet {
assertNotNull(sheet);
XSSFPivotTable pivotTable =
sheet.createPivotTable(wb.getCreationHelper().createAreaReference("A1:B2"), new
CellReference("H5"));
assertNotNull(pivotTable);
- assertTrue(wb.getPivotTables().size() > 0);
+ assertFalse(wb.getPivotTables().isEmpty());
}
}
diff --git
a/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/BaseTestPPTIterating.java
b/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/BaseTestPPTIterating.java
index e1458db0cb..5409e9aa64 100644
---
a/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/BaseTestPPTIterating.java
+++
b/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/BaseTestPPTIterating.java
@@ -24,9 +24,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -47,17 +45,17 @@ import org.junit.jupiter.params.provider.MethodSource;
@Isolated // this test changes global static BYTE_ARRAY_MAX_OVERRIDE
public abstract class BaseTestPPTIterating {
- static final Set<String> OLD_FILES = new HashSet<>(Arrays.asList(
+ static final Set<String> OLD_FILES = Set.of(
"PPT95.ppt", "pp40only.ppt"
- ));
+ );
- static final Set<String> ENCRYPTED_FILES = new HashSet<>(Arrays.asList(
+ static final Set<String> ENCRYPTED_FILES = Set.of(
"cryptoapi-proc2356.ppt",
"Password_Protected-np-hello.ppt",
"Password_Protected-56-hello.ppt",
"Password_Protected-hello.ppt",
"ppt_with_png_encrypted.ppt"
- ));
+ );
static final Map<String,Class<? extends Throwable>> EXCLUDED = new
HashMap<>();
static {
diff --git
a/poi/src/main/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java
b/poi/src/main/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java
index 03afebdd1a..887cbb419b 100644
--- a/poi/src/main/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java
+++ b/poi/src/main/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java
@@ -17,12 +17,9 @@
package org.apache.poi.ss.formula.atp;
-import java.util.Arrays;
import java.util.Calendar;
-import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -37,26 +34,26 @@ public class WorkdayCalculator {
public static final WorkdayCalculator instance = new WorkdayCalculator();
private static final Set<Integer> standardWeekend =
- new HashSet<>(Arrays.asList(Calendar.SATURDAY, Calendar.SUNDAY));
+ Set.of(Calendar.SATURDAY, Calendar.SUNDAY);
private static final Set<Integer> sunMonWeekend =
- new HashSet<>(Arrays.asList(Calendar.SUNDAY, Calendar.MONDAY));
+ Set.of(Calendar.SUNDAY, Calendar.MONDAY);
private static final Set<Integer> monTuesWeekend =
- new HashSet<>(Arrays.asList(Calendar.MONDAY, Calendar.TUESDAY));
+ Set.of(Calendar.MONDAY, Calendar.TUESDAY);
private static final Set<Integer> tuesWedsWeekend =
- new HashSet<>(Arrays.asList(Calendar.TUESDAY, Calendar.WEDNESDAY));
+ Set.of(Calendar.TUESDAY, Calendar.WEDNESDAY);
private static final Set<Integer> wedsThursWeekend =
- new HashSet<>(Arrays.asList(Calendar.WEDNESDAY,
Calendar.THURSDAY));
+ Set.of(Calendar.WEDNESDAY, Calendar.THURSDAY);
private static final Set<Integer> thursFriWeekend =
- new HashSet<>(Arrays.asList(Calendar.THURSDAY, Calendar.FRIDAY));
+ Set.of(Calendar.THURSDAY, Calendar.FRIDAY);
private static final Set<Integer> friSatWeekend =
- new HashSet<>(Arrays.asList(Calendar.FRIDAY, Calendar.SATURDAY));
- private static final Set<Integer> monWeekend =
Collections.singleton(Calendar.MONDAY);
- private static final Set<Integer> tuesWeekend =
Collections.singleton(Calendar.TUESDAY);
- private static final Set<Integer> wedsWeekend =
Collections.singleton(Calendar.WEDNESDAY);
- private static final Set<Integer> thursWeekend =
Collections.singleton(Calendar.THURSDAY);
- private static final Set<Integer> friWeekend =
Collections.singleton(Calendar.FRIDAY);
- private static final Set<Integer> satWeekend =
Collections.singleton(Calendar.SATURDAY);
- private static final Set<Integer> sunWeekend =
Collections.singleton(Calendar.SUNDAY);
+ Set.of(Calendar.FRIDAY, Calendar.SATURDAY);
+ private static final Set<Integer> monWeekend = Set.of(Calendar.MONDAY);
+ private static final Set<Integer> tuesWeekend = Set.of(Calendar.TUESDAY);
+ private static final Set<Integer> wedsWeekend =
Set.of(Calendar.WEDNESDAY);
+ private static final Set<Integer> thursWeekend = Set.of(Calendar.THURSDAY);
+ private static final Set<Integer> friWeekend = Set.of(Calendar.FRIDAY);
+ private static final Set<Integer> satWeekend = Set.of(Calendar.SATURDAY);
+ private static final Set<Integer> sunWeekend = Set.of(Calendar.SUNDAY);
private static final Map<Integer, Set<Integer>> weekendTypeMap = new
HashMap<>();
static {
diff --git
a/poi/src/main/java/org/apache/poi/ss/formula/function/FunctionMetadataReader.java
b/poi/src/main/java/org/apache/poi/ss/formula/function/FunctionMetadataReader.java
index ad62636a6c..a98f6924e9 100644
---
a/poi/src/main/java/org/apache/poi/ss/formula/function/FunctionMetadataReader.java
+++
b/poi/src/main/java/org/apache/poi/ss/formula/function/FunctionMetadataReader.java
@@ -23,7 +23,6 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
-import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
@@ -54,7 +53,7 @@ final class FunctionMetadataReader {
// except in these cases
"LOG10", "ATAN2", "DAYS360", "SUMXMY2", "SUMX2MY2", "SUMX2PY2",
"A1.R1C1",
};
- private static final Set<String> DIGIT_ENDING_FUNCTION_NAMES_SET = new
HashSet<>(Arrays.asList(DIGIT_ENDING_FUNCTION_NAMES));
+ private static final Set<String> DIGIT_ENDING_FUNCTION_NAMES_SET =
Set.of(DIGIT_ENDING_FUNCTION_NAMES);
/**
* @param length the max record length allowed for FunctionMetadataReader
@@ -95,11 +94,11 @@ final class FunctionMetadataReader {
if (line == null) {
break;
}
- if (line.length() < 1 || line.charAt(0) == '#') {
+ if (line.isEmpty() || line.charAt(0) == '#') {
continue;
}
String trimLine = line.trim();
- if (trimLine.length() < 1) {
+ if (trimLine.isEmpty()) {
continue;
}
processLine(fdb, line);
@@ -141,7 +140,7 @@ final class FunctionMetadataReader {
}
private static byte[] parseOperandTypeCodes(String codes) {
- if(codes.length() < 1) {
+ if(codes.isEmpty()) {
return EMPTY_BYTE_ARRAY; // happens for GETPIVOTDATA
}
if(isDash(codes)) {
diff --git a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestBugs.java
b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestBugs.java
index 0c528cafd1..c1f8d813b2 100644
--- a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestBugs.java
+++ b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestBugs.java
@@ -32,7 +32,6 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
@@ -755,9 +754,7 @@ final class TestBugs extends BaseTestBugzillaIssues {
int i = 0;
for (Iterator<CellValueRecordInterface> it =
ns.getSheet().getCellValueIterator(); it.hasNext(); i++) {
CellValueRecordInterface cvr = it.next();
- if (cvr instanceof FormulaRecordAggregate) {
- FormulaRecordAggregate fr = (FormulaRecordAggregate)
cvr;
-
+ if (cvr instanceof FormulaRecordAggregate fr) {
if (i == 0) {
assertEquals(70164.0,
fr.getFormulaRecord().getValue(), 0.0001);
assertNull(fr.getStringRecord());
@@ -1554,14 +1551,14 @@ final class TestBugs extends BaseTestBugzillaIssues {
@Test
void bug49751() throws Exception {
- Set<String> exp = new HashSet<>(Arrays.asList(
+ Set<String> exp = Set.of(
"20% - Accent1", "20% - Accent2", "20% - Accent3", "20% -
Accent4", "20% - Accent5",
"20% - Accent6", "40% - Accent1", "40% - Accent2", "40% -
Accent3", "40% - Accent4",
"40% - Accent5", "40% - Accent6", "60% - Accent1", "60% -
Accent2", "60% - Accent3",
"60% - Accent4", "60% - Accent5", "60% - Accent6", "Accent1",
"Accent2", "Accent3",
"Accent4", "Accent5", "Accent6", "Bad", "Calculation", "Check
Cell", "Explanatory Text",
"Good", "Heading 1", "Heading 2", "Heading 3", "Heading 4",
"Input", "Linked Cell",
- "Neutral", "Note", "Output", "Title", "Total", "Warning Text"));
+ "Neutral", "Note", "Output", "Title", "Total", "Warning Text");
try (HSSFWorkbook wb = openSampleWorkbook("49751.xls")) {
Set<String> act = IntStream
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]