diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml
index 1d4fc8b..53aabcc 100644
--- a/.github/workflows/unit-tests.yml
+++ b/.github/workflows/unit-tests.yml
@@ -30,7 +30,7 @@ jobs:
run: mvn --batch-mode clean test
- name: Test Coverage
- uses: codecov/codecov-action@v4.0.1
+ uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
diff --git a/pom.xml b/pom.xml
index 5cd605b..d6cf3f7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -49,8 +49,8 @@
11UTF-8UTF-8
- 1.18.28
- 3.32.0
+ 1.18.38
+ 3.49.2
@@ -76,19 +76,19 @@
org.junit.jupiterjunit-jupiter
- 5.9.2
+ 5.12.2testorg.mockitomockito-junit-jupiter
- 5.2.0
+ 5.17.0testnl.jqno.equalsverifierequalsverifier
- 3.14.1
+ 3.19.3test
@@ -98,7 +98,7 @@
maven-surefire-plugin
- 2.22.2
+ 3.5.3
@@ -106,7 +106,7 @@
org.apache.maven.pluginsmaven-compiler-plugin
- 3.10.1
+ 3.14.0truetrue
@@ -149,7 +149,7 @@
org.jacocojacoco-maven-plugin
- 0.8.8
+ 0.8.13prepare-agent
@@ -169,7 +169,7 @@
org.apache.maven.pluginsmaven-source-plugin
- 3.2.1
+ 3.3.1attach-sources
diff --git a/src/main/java/org/spacious_team/table_wrapper/api/ReportPage.java b/src/main/java/org/spacious_team/table_wrapper/api/ReportPage.java
index 8964ee4..f407a82 100644
--- a/src/main/java/org/spacious_team/table_wrapper/api/ReportPage.java
+++ b/src/main/java/org/spacious_team/table_wrapper/api/ReportPage.java
@@ -23,7 +23,7 @@
import java.util.function.Predicate;
import static java.util.Objects.requireNonNull;
-import static org.spacious_team.table_wrapper.api.ReportPageHelper.getCellStringValueIgnoreCasePrefixPredicate;
+import static org.spacious_team.table_wrapper.api.StringPrefixPredicate.ignoreCaseStringPrefixPredicateOnObject;
@SuppressWarnings({"unused", "UnusedReturnValue"})
public interface ReportPage {
@@ -157,7 +157,7 @@ default TableCellAddress findByPrefix(String prefix, int startRow, int endRow) {
default TableCellAddress findByPrefix(@Nullable String prefix, int startRow, int endRow, int startColumn, int endColumn) {
return (prefix == null || prefix.isEmpty()) ?
TableCellAddress.NOT_FOUND :
- find(startRow, endRow, startColumn, endColumn, getCellStringValueIgnoreCasePrefixPredicate(prefix));
+ find(startRow, endRow, startColumn, endColumn, ignoreCaseStringPrefixPredicateOnObject(prefix));
}
/**
@@ -208,9 +208,9 @@ default TableCellRange getTableCellRange(@Nullable String firstRowPrefix,
return TableCellRange.EMPTY_RANGE;
}
return getTableCellRange(
- getCellStringValueIgnoreCasePrefixPredicate(firstRowPrefix),
+ ignoreCaseStringPrefixPredicateOnObject(firstRowPrefix),
headersRowCount,
- getCellStringValueIgnoreCasePrefixPredicate(lastRowPrefix));
+ ignoreCaseStringPrefixPredicateOnObject(lastRowPrefix));
}
/**
@@ -250,7 +250,7 @@ default TableCellRange getTableCellRange(@Nullable String firstRowPrefix, int he
return TableCellRange.EMPTY_RANGE;
}
return getTableCellRange(
- getCellStringValueIgnoreCasePrefixPredicate(firstRowPrefix),
+ ignoreCaseStringPrefixPredicateOnObject(firstRowPrefix),
headersRowCount);
}
diff --git a/src/main/java/org/spacious_team/table_wrapper/api/ReportPageHelper.java b/src/main/java/org/spacious_team/table_wrapper/api/ReportPageHelper.java
deleted file mode 100644
index 3fdcd65..0000000
--- a/src/main/java/org/spacious_team/table_wrapper/api/ReportPageHelper.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Table Wrapper API
- * Copyright (C) 2022 Spacious Team
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-package org.spacious_team.table_wrapper.api;
-
-import lombok.EqualsAndHashCode;
-import lombok.RequiredArgsConstructor;
-import lombok.ToString;
-import org.checkerframework.checker.nullness.qual.Nullable;
-
-import java.util.function.Predicate;
-
-import static lombok.AccessLevel.PRIVATE;
-
-@RequiredArgsConstructor(access = PRIVATE)
-final class ReportPageHelper {
-
- static Predicate<@Nullable Object> getCellStringValueIgnoreCasePrefixPredicate(String prefix) {
- return new StringIgnoreCasePrefixPredicate(prefix);
- }
-
- @ToString
- @EqualsAndHashCode
- static final class StringIgnoreCasePrefixPredicate implements Predicate<@Nullable Object> {
- private final String lowercasePrefix;
-
- private StringIgnoreCasePrefixPredicate(String prefix) {
- this.lowercasePrefix = prefix.trim().toLowerCase();
- }
-
- @Override
- public boolean test(@Nullable Object cell) {
- return (cell instanceof String) &&
- ((String) cell).trim().toLowerCase().startsWith(lowercasePrefix);
- }
- }
-}
diff --git a/src/main/java/org/spacious_team/table_wrapper/api/StringPrefixPredicate.java b/src/main/java/org/spacious_team/table_wrapper/api/StringPrefixPredicate.java
new file mode 100644
index 0000000..de2efd4
--- /dev/null
+++ b/src/main/java/org/spacious_team/table_wrapper/api/StringPrefixPredicate.java
@@ -0,0 +1,87 @@
+/*
+ * Table Wrapper API
+ * Copyright (C) 2022 Spacious Team
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package org.spacious_team.table_wrapper.api;
+
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+import lombok.RequiredArgsConstructor;
+import lombok.ToString;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.function.Predicate;
+
+import static java.lang.Character.isWhitespace;
+import static lombok.AccessLevel.PRIVATE;
+
+@NoArgsConstructor(access = PRIVATE)
+public final class StringPrefixPredicate {
+
+ public static Predicate<@Nullable Object> ignoreCaseStringPrefixPredicateOnObject(CharSequence prefix) {
+ Predicate predicate = ignoreCaseStringPrefixPredicate(prefix);
+ return PredicateOnObjectWrapper.of(predicate);
+ }
+
+ public static Predicate ignoreCaseStringPrefixPredicate(CharSequence prefix) {
+ return new IgnoreCaseStringPrefixPredicate<>(prefix);
+ }
+
+
+ @ToString
+ @EqualsAndHashCode
+ @RequiredArgsConstructor(staticName = "of", access = PRIVATE)
+ static final class PredicateOnObjectWrapper implements Predicate<@Nullable Object> {
+ private final Predicate predicate;
+
+ @Override
+ public boolean test(@Nullable Object o) {
+ return (o instanceof CharSequence) && predicate.test((CharSequence) o);
+ }
+ }
+
+
+ @ToString
+ @EqualsAndHashCode
+ static final class IgnoreCaseStringPrefixPredicate implements Predicate {
+ private final String prefix;
+
+ private IgnoreCaseStringPrefixPredicate(CharSequence prefix) {
+ this.prefix = prefix.toString().strip();
+ }
+
+ @Override
+ public boolean test(T cs) {
+ int nonWhitespaceIndex = getIndexOfNonWhitespace(cs);
+ if (nonWhitespaceIndex == -1) {
+ return false;
+ }
+ String string = cs.toString();
+ return string.regionMatches(true, nonWhitespaceIndex, prefix, 0, prefix.length());
+ }
+
+ private static int getIndexOfNonWhitespace(CharSequence cs) {
+ for (int i = 0, n = cs.length(); i < n; i++) {
+ char c = cs.charAt(i);
+ if (!isWhitespace(c)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+ }
+}
diff --git a/src/main/java/org/spacious_team/table_wrapper/api/TableCell.java b/src/main/java/org/spacious_team/table_wrapper/api/TableCell.java
index bc7aeb9..0173886 100644
--- a/src/main/java/org/spacious_team/table_wrapper/api/TableCell.java
+++ b/src/main/java/org/spacious_team/table_wrapper/api/TableCell.java
@@ -19,6 +19,8 @@
package org.spacious_team.table_wrapper.api;
import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.checker.nullness.qual.PolyNull;
+
import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;
@@ -125,7 +127,7 @@ default double getDoubleValueOrDefault(double defaultValue) {
/**
* @return return cell value or defaultValue if the cell is missing or the type does not match the expected
*/
- default BigDecimal getBigDecimalValueOrDefault(BigDecimal defaultValue) {
+ default @PolyNull BigDecimal getBigDecimalValueOrDefault(@PolyNull BigDecimal defaultValue) {
try {
return getBigDecimalValue();
} catch (Exception e) {
@@ -136,7 +138,7 @@ default BigDecimal getBigDecimalValueOrDefault(BigDecimal defaultValue) {
/**
* @return return cell value or defaultValue if the cell is missing or the type does not match the expected
*/
- default String getStringValueOrDefault(String defaultValue) {
+ default @PolyNull String getStringValueOrDefault(@PolyNull String defaultValue) {
try {
return getStringValue();
} catch (Exception e) {
@@ -147,7 +149,7 @@ default String getStringValueOrDefault(String defaultValue) {
/**
* @return return cell value or defaultValue if the cell is missing or the type does not match the expected
*/
- default Instant getInstantValueOrDefault(Instant defaultValue) {
+ default @PolyNull Instant getInstantValueOrDefault(@PolyNull Instant defaultValue) {
try {
return getInstantValue();
} catch (Exception e) {
@@ -158,7 +160,7 @@ default Instant getInstantValueOrDefault(Instant defaultValue) {
/**
* @return return cell value or defaultValue if the cell is missing or the type does not match the expected
*/
- default LocalDateTime getLocalDateTimeValueOrDefault(LocalDateTime defaultValue) {
+ default @PolyNull LocalDateTime getLocalDateTimeValueOrDefault(@PolyNull LocalDateTime defaultValue) {
try {
return getLocalDateTimeValue();
} catch (Exception e) {
@@ -169,7 +171,7 @@ default LocalDateTime getLocalDateTimeValueOrDefault(LocalDateTime defaultValue)
/**
* @return return cell value or defaultValue if the cell is missing or the type does not match the expected
*/
- default LocalDateTime getLocalDateTimeValueOrDefault(ZoneId zoneId, LocalDateTime defaultValue) {
+ default @PolyNull LocalDateTime getLocalDateTimeValueOrDefault(ZoneId zoneId, @PolyNull LocalDateTime defaultValue) {
try {
return getLocalDateTimeValue(zoneId);
} catch (Exception e) {
diff --git a/src/main/java/org/spacious_team/table_wrapper/api/TableRow.java b/src/main/java/org/spacious_team/table_wrapper/api/TableRow.java
index 792ad54..9bd359f 100644
--- a/src/main/java/org/spacious_team/table_wrapper/api/TableRow.java
+++ b/src/main/java/org/spacious_team/table_wrapper/api/TableRow.java
@@ -19,6 +19,8 @@
package org.spacious_team.table_wrapper.api;
import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.checker.nullness.qual.PolyNull;
+
import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;
@@ -128,7 +130,7 @@ default double getDoubleCellValueOrDefault(TableHeaderColumn column, double defa
/**
* @return return cell value or defaultValue if the cell is missing or the type does not match the expected
*/
- default BigDecimal getBigDecimalCellValueOrDefault(TableHeaderColumn column, BigDecimal defaultValue) {
+ default @PolyNull BigDecimal getBigDecimalCellValueOrDefault(TableHeaderColumn column, @PolyNull BigDecimal defaultValue) {
try {
return getBigDecimalCellValue(column);
} catch (Exception e) {
@@ -139,7 +141,7 @@ default BigDecimal getBigDecimalCellValueOrDefault(TableHeaderColumn column, Big
/**
* @return return cell value or defaultValue if the cell is missing or the type does not match the expected
*/
- default String getStringCellValueOrDefault(TableHeaderColumn column, String defaultValue) {
+ default @PolyNull String getStringCellValueOrDefault(TableHeaderColumn column, @PolyNull String defaultValue) {
try {
return getStringCellValue(column);
} catch (Exception e) {
@@ -150,7 +152,7 @@ default String getStringCellValueOrDefault(TableHeaderColumn column, String defa
/**
* @return return cell value or defaultValue if the cell is missing or the type does not match the expected
*/
- default Instant getInstantCellValueOrDefault(TableHeaderColumn column, Instant defaultValue) {
+ default @PolyNull Instant getInstantCellValueOrDefault(TableHeaderColumn column, @PolyNull Instant defaultValue) {
try {
return getInstantCellValue(column);
} catch (Exception e) {
@@ -161,7 +163,7 @@ default Instant getInstantCellValueOrDefault(TableHeaderColumn column, Instant d
/**
* @return return cell value or defaultValue if the cell is missing or the type does not match the expected
*/
- default LocalDateTime getLocalDateTimeCellValueOrDefault(TableHeaderColumn column, LocalDateTime defaultValue) {
+ default @PolyNull LocalDateTime getLocalDateTimeCellValueOrDefault(TableHeaderColumn column, @PolyNull LocalDateTime defaultValue) {
try {
return getLocalDateTimeCellValue(column);
} catch (Exception e) {
@@ -172,7 +174,7 @@ default LocalDateTime getLocalDateTimeCellValueOrDefault(TableHeaderColumn colum
/**
* @return return cell value or defaultValue if the cell is missing or the type does not match the expected
*/
- default LocalDateTime getLocalDateTimeCellValueOrDefault(TableHeaderColumn column, ZoneId zoneId, LocalDateTime defaultValue) {
+ default @PolyNull LocalDateTime getLocalDateTimeCellValueOrDefault(TableHeaderColumn column, ZoneId zoneId, @PolyNull LocalDateTime defaultValue) {
try {
return getLocalDateTimeCellValue(column, zoneId);
} catch (Exception e) {
diff --git a/src/test/java/org/spacious_team/table_wrapper/api/ReportPageHelperTest.java b/src/test/java/org/spacious_team/table_wrapper/api/ReportPageHelperTest.java
deleted file mode 100644
index 8e36ac1..0000000
--- a/src/test/java/org/spacious_team/table_wrapper/api/ReportPageHelperTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Table Wrapper API
- * Copyright (C) 2022 Spacious Team
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-package org.spacious_team.table_wrapper.api;
-
-import nl.jqno.equalsverifier.EqualsVerifier;
-import org.junit.jupiter.api.Test;
-import org.spacious_team.table_wrapper.api.ReportPageHelper.StringIgnoreCasePrefixPredicate;
-
-import static org.junit.jupiter.api.Assertions.*;
-import static org.spacious_team.table_wrapper.api.ReportPageHelper.getCellStringValueIgnoreCasePrefixPredicate;
-
-class ReportPageHelperTest {
-
- @Test
- void test() {
- assertTrue(getCellStringValueIgnoreCasePrefixPredicate("First").test("First second"));
- assertTrue(getCellStringValueIgnoreCasePrefixPredicate("First").test("first second"));
- assertTrue(getCellStringValueIgnoreCasePrefixPredicate("first").test("First second"));
- assertTrue(getCellStringValueIgnoreCasePrefixPredicate("first").test("first second"));
- assertTrue(getCellStringValueIgnoreCasePrefixPredicate("FIRST").test("first second"));
- assertFalse(getCellStringValueIgnoreCasePrefixPredicate("First").test("One two"));
- //noinspection ConstantConditions
- assertFalse(getCellStringValueIgnoreCasePrefixPredicate("First").test(null));
- assertFalse(getCellStringValueIgnoreCasePrefixPredicate("First").test(1));
- assertFalse(getCellStringValueIgnoreCasePrefixPredicate("First").test(1.1));
- assertFalse(getCellStringValueIgnoreCasePrefixPredicate("First").test(new Object()));
- }
-
- @Test
- void testEqualsAndHashCode() {
- EqualsVerifier
- .forClass(StringIgnoreCasePrefixPredicate.class)
- .verify();
- }
-
- @Test
- void testToString() {
- assertEquals(
- "ReportPageHelper.StringIgnoreCasePrefixPredicate(lowercasePrefix=first)",
- getCellStringValueIgnoreCasePrefixPredicate("First").toString());
- }
-}
\ No newline at end of file
diff --git a/src/test/java/org/spacious_team/table_wrapper/api/ReportPageTest.java b/src/test/java/org/spacious_team/table_wrapper/api/ReportPageTest.java
index c850360..c040091 100644
--- a/src/test/java/org/spacious_team/table_wrapper/api/ReportPageTest.java
+++ b/src/test/java/org/spacious_team/table_wrapper/api/ReportPageTest.java
@@ -34,7 +34,7 @@
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
-import static org.spacious_team.table_wrapper.api.ReportPageHelper.getCellStringValueIgnoreCasePrefixPredicate;
+import static org.spacious_team.table_wrapper.api.StringPrefixPredicate.ignoreCaseStringPrefixPredicateOnObject;
import static org.spacious_team.table_wrapper.api.ReportPageRowHelper.cell;
import static org.spacious_team.table_wrapper.api.ReportPageRowHelper.getRow;
import static org.spacious_team.table_wrapper.api.TableCellAddress.NOT_FOUND;
@@ -50,8 +50,8 @@ class ReportPageTest {
TableCellAddress address2 = TableCellAddress.of(3, 4);
String prefix1 = "A";
String prefix2 = "B";
- Predicate