Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<lombok.version>1.18.28</lombok.version>
<checkerframework.version>3.32.0</checkerframework.version>
<lombok.version>1.18.38</lombok.version>
<checkerframework.version>3.49.2</checkerframework.version>
</properties>

<dependencies>
Expand All @@ -76,19 +76,19 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.2</version>
<version>5.12.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.2.0</version>
<version>5.17.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>3.14.1</version>
<version>3.19.3</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -98,15 +98,15 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version> <!-- JUnit 5 requirement -->
<version>3.5.3</version> <!-- JUnit 5 requirement -->
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<version>3.14.0</version>
<configuration>
<fork>true</fork> <!-- Must fork or else JVM arguments are ignored. -->
<showDeprecation>true</showDeprecation>
Expand Down Expand Up @@ -149,7 +149,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<version>0.8.13</version>
<executions>
<execution>
<id>prepare-agent</id>
Expand All @@ -169,7 +169,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -250,7 +250,7 @@ default TableCellRange getTableCellRange(@Nullable String firstRowPrefix, int he
return TableCellRange.EMPTY_RANGE;
}
return getTableCellRange(
getCellStringValueIgnoreCasePrefixPredicate(firstRowPrefix),
ignoreCaseStringPrefixPredicateOnObject(firstRowPrefix),
headersRowCount);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Table Wrapper API
* Copyright (C) 2022 Spacious Team <spacious-team@ya.ru>
*
* 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 <https://www.gnu.org/licenses/>.
*/

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<CharSequence> predicate = ignoreCaseStringPrefixPredicate(prefix);
return PredicateOnObjectWrapper.of(predicate);
}

public static <T extends CharSequence> Predicate<T> 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<CharSequence> predicate;

@Override
public boolean test(@Nullable Object o) {
return (o instanceof CharSequence) && predicate.test((CharSequence) o);
}
}


@ToString
@EqualsAndHashCode
static final class IgnoreCaseStringPrefixPredicate<T extends CharSequence> implements Predicate<T> {
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;
}
}
}
12 changes: 7 additions & 5 deletions src/main/java/org/spacious_team/table_wrapper/api/TableCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/org/spacious_team/table_wrapper/api/TableRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Loading