Skip to content

Commit dd4f3de

Browse files
committed
Switched to new fastCSV library
1 parent 9855cf9 commit dd4f3de

14 files changed

+200
-218
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## NAACCR XML Version History
22

3+
**Version 11.2**
4+
5+
- Updated XStream dependency from version 1.4.20 to version 1.4.21.
6+
37
**Version 11.1**
48

59
- Fixed two minor mistakes in the NAACCR 25 base dictionary.

Diff for: build.gradle

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ plugins {
1414
id 'java-library'
1515
id 'checkstyle'
1616
id 'jacoco'
17-
id 'com.github.spotbugs' version '6.0.20'
17+
id 'com.github.spotbugs' version '6.0.26'
1818
id 'maven-publish'
1919
id 'signing'
2020
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0' // publish to Maven Central
@@ -34,15 +34,15 @@ repositories {
3434
}
3535

3636
dependencies {
37-
api 'com.thoughtworks.xstream:xstream:1.4.20'
37+
api 'com.thoughtworks.xstream:xstream:1.4.21'
3838

39-
implementation 'commons-io:commons-io:2.16.1'
40-
implementation 'org.apache.commons:commons-lang3:3.16.0'
39+
implementation 'commons-io:commons-io:2.17.0'
40+
implementation 'org.apache.commons:commons-lang3:3.17.0'
4141

4242
testImplementation 'junit:junit:4.13.2'
43-
testImplementation 'com.imsweb:data-generator:1.32'
44-
testImplementation 'com.imsweb:layout:5.6'
45-
testImplementation 'com.opencsv:opencsv:5.9'
43+
testImplementation 'com.imsweb:data-generator:1.34'
44+
testImplementation 'com.imsweb:layout:5.7'
45+
testImplementation 'de.siegmar:fastcsv:3.4.0'
4646
}
4747

4848
// enforce UTF-8, display the compilation warnings
@@ -58,8 +58,8 @@ tasks.withType(Javadoc).configureEach {
5858

5959
// generate javadoc and sources (required by Nexus)
6060
java {
61-
sourceCompatibility = JavaVersion.VERSION_1_8
62-
targetCompatibility = JavaVersion.VERSION_1_8
61+
sourceCompatibility = JavaVersion.VERSION_11
62+
targetCompatibility = JavaVersion.VERSION_11
6363

6464
withJavadocJar()
6565
withSourcesJar()
@@ -222,10 +222,10 @@ nexusPublishing {
222222

223223
// Gradle wrapper, this allows to build the project without having to install Gradle...
224224
wrapper {
225-
gradleVersion = '8.9'
225+
gradleVersion = '8.11'
226226
distributionType = Wrapper.DistributionType.ALL
227227
}
228228

229-
// the SAS library is compiled under Java 7 code-compatibility; Intellij can't handle that (only because I didn't properly set it up as a module)
229+
// the SAS library is compiled under Java 8 code-compatibility; Intellij can't handle that (only because I didn't properly set it up as a module)
230230
if (System.getProperty("idea.active") != 'true')
231231
apply from: 'gradle/sas.gradle'

Diff for: gradle/wrapper/gradle-wrapper.jar

42 Bytes
Binary file not shown.

Diff for: gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-all.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

Diff for: gradlew

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717
#
18+
# SPDX-License-Identifier: Apache-2.0
19+
#
1820

1921
##############################################################################
2022
#
@@ -55,7 +57,7 @@
5557
# Darwin, MinGW, and NonStop.
5658
#
5759
# (3) This script is generated from the Groovy template
58-
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
60+
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
5961
# within the Gradle project.
6062
#
6163
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -84,7 +86,8 @@ done
8486
# shellcheck disable=SC2034
8587
APP_BASE_NAME=${0##*/}
8688
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87-
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
89+
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
90+
' "$PWD" ) || exit
8891

8992
# Use the maximum available, or set MAX_FD != -1 to use that value.
9093
MAX_FD=maximum

Diff for: gradlew.bat

+12-10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
@rem See the License for the specific language governing permissions and
1414
@rem limitations under the License.
1515
@rem
16+
@rem SPDX-License-Identifier: Apache-2.0
17+
@rem
1618

1719
@if "%DEBUG%"=="" @echo off
1820
@rem ##########################################################################
@@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
4345
%JAVA_EXE% -version >NUL 2>&1
4446
if %ERRORLEVEL% equ 0 goto execute
4547

46-
echo.
47-
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48-
echo.
49-
echo Please set the JAVA_HOME variable in your environment to match the
50-
echo location of your Java installation.
48+
echo. 1>&2
49+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50+
echo. 1>&2
51+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52+
echo location of your Java installation. 1>&2
5153

5254
goto fail
5355

@@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
5759

5860
if exist "%JAVA_EXE%" goto execute
5961

60-
echo.
61-
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62-
echo.
63-
echo Please set the JAVA_HOME variable in your environment to match the
64-
echo location of your Java installation.
62+
echo. 1>&2
63+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64+
echo. 1>&2
65+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66+
echo location of your Java installation. 1>&2
6567

6668
goto fail
6769

Diff for: src/test/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtilsTest.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package com.imsweb.naaccrxml;
55

66
import java.io.File;
7-
import java.io.FileReader;
87
import java.io.FileWriter;
98
import java.io.IOException;
109
import java.io.InputStreamReader;
@@ -22,8 +21,8 @@
2221
import org.junit.Assert;
2322
import org.junit.Test;
2423

25-
import com.opencsv.CSVReader;
26-
import com.opencsv.exceptions.CsvException;
24+
import de.siegmar.fastcsv.reader.CsvReader;
25+
import de.siegmar.fastcsv.reader.NamedCsvRecord;
2726

2827
import com.imsweb.naaccrxml.entity.dictionary.NaaccrDictionary;
2928
import com.imsweb.naaccrxml.entity.dictionary.NaaccrDictionaryItem;
@@ -488,7 +487,7 @@ public void testValidationRegex() {
488487
Assert.assertTrue(pattern.matcher("2010-06-15T13:45:30-04:00").matches()); // UTC minus 4 hours
489488
Assert.assertTrue(pattern.matcher("2010-06-15T13:45:30+05:30").matches()); // UTC plus 5 1/2 hours
490489
Assert.assertTrue(pattern.matcher("2010-06-15T13:45:30Z").matches()); // UTC
491-
490+
492491
Assert.assertFalse(pattern.matcher("2010-06-15T00:00:30.000Z").matches()); // UTC with milliseconds - second fractions not allowed anymore
493492
Assert.assertFalse(pattern.matcher("2010-06-15T13:45:30.001-05:00").matches()); // UTC minus 5 hours, with 1/1000 of seconds (milliseconds) - second fractions not allowed anymore
494493
Assert.assertFalse(pattern.matcher("2010-06-15T13:45:30.0-05:00").matches()); // UTC minus 5 hours, with 1/10 of seconds - second fractions not allowed anymore
@@ -532,12 +531,13 @@ public void testGetMergedDictionaries() {
532531

533532
@Test
534533
@SuppressWarnings("ResultOfMethodCallIgnored")
535-
public void testWriteDictionaryToCsv() throws IOException, CsvException {
534+
public void testWriteDictionaryToCsv() throws IOException {
536535
NaaccrDictionary dictionary = NaaccrXmlDictionaryUtils.getBaseDictionaryByVersion(NaaccrFormat.NAACCR_VERSION_LATEST);
537536
File file = new File(TestingUtils.getBuildDirectory(), "dictionary.csv");
538537
NaaccrXmlDictionaryUtils.writeDictionaryToCsv(dictionary, file);
539-
try (FileReader reader = new FileReader(file)) {
540-
Assert.assertFalse(new CSVReader(reader).readAll().isEmpty());
538+
539+
try (CsvReader<NamedCsvRecord> reader = CsvReader.builder().ofNamedCsvRecord(file.toPath())) {
540+
Assert.assertFalse(reader.stream().toString().isEmpty());
541541
}
542542
finally {
543543
file.delete();

Diff for: src/test/java/lab/AddNaaccr21Items.java

+12-16
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
package lab;
55

66
import java.io.File;
7-
import java.io.FileReader;
87
import java.nio.file.Path;
98
import java.nio.file.Paths;
109
import java.util.Comparator;
1110
import java.util.stream.Collectors;
1211

13-
import com.opencsv.CSVReader;
12+
import de.siegmar.fastcsv.reader.CsvReader;
13+
import de.siegmar.fastcsv.reader.NamedCsvRecord;
1414

1515
import com.imsweb.naaccrxml.NaaccrFormat;
1616
import com.imsweb.naaccrxml.NaaccrXmlDictionaryUtils;
@@ -30,18 +30,16 @@ public static void main(String[] args) throws Exception {
3030
NaaccrDictionary dictionary = NaaccrXmlDictionaryUtils.readDictionary(path.toFile());
3131
dictionary.getItemByNaaccrId("force-caching");
3232

33-
try (CSVReader reader = new CSVReader(new FileReader(new File(TestingUtils.getWorkingDirectory() + "/docs/naaccr-21/Vol2 v21 New and Revised select fields DRAFT.csv")))) {
34-
String[] line = reader.readNext(); // ignore headers
33+
File file = new File(TestingUtils.getWorkingDirectory() + "/docs/naaccr-21/Vol2 v21 New and Revised select fields DRAFT.csv");
34+
try (CsvReader<NamedCsvRecord> reader = CsvReader.builder().ofNamedCsvRecord(file.toPath())) {
35+
reader.stream().forEach(line -> {
3536

36-
line = reader.readNext();
37-
while (line != null) {
38-
39-
Integer num = Integer.parseInt(line[0]);
40-
Integer length = Integer.parseInt(line[1]);
41-
String name = line[2];
42-
String id = line[3];
43-
String level = line[4];
44-
boolean isNew = "New".equals(line[7]);
37+
Integer num = Integer.parseInt(line.getField(0));
38+
Integer length = Integer.parseInt(line.getField(1));
39+
String name = line.getField(2);
40+
String id = line.getField(3);
41+
String level = line.getField(4);
42+
boolean isNew = "New".equals(line.getField(7));
4543

4644
if (isNew) {
4745
NaaccrDictionaryItem item = new NaaccrDictionaryItem();
@@ -60,9 +58,7 @@ public static void main(String[] args) throws Exception {
6058
else
6159
System.out.println("Need to review " + id);
6260
}
63-
64-
line = reader.readNext();
65-
}
61+
});
6662
}
6763

6864
dictionary.getItems().forEach(i -> i.setStartColumn(null));

Diff for: src/test/java/lab/AddNaaccr22Items.java

+14-17
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
*/
44
package lab;
55

6-
import java.io.FileReader;
6+
import java.io.File;
77
import java.nio.file.Path;
88
import java.nio.file.Paths;
99
import java.util.Comparator;
1010
import java.util.stream.Collectors;
1111

12-
import com.opencsv.CSVReader;
12+
import de.siegmar.fastcsv.reader.CsvReader;
13+
import de.siegmar.fastcsv.reader.NamedCsvRecord;
1314

1415
import com.imsweb.naaccrxml.NaaccrFormat;
1516
import com.imsweb.naaccrxml.NaaccrXmlDictionaryUtils;
@@ -29,19 +30,17 @@ public static void main(String[] args) throws Exception {
2930
NaaccrDictionary dictionary = NaaccrXmlDictionaryUtils.readDictionary(path.toFile());
3031
dictionary.getItemByNaaccrId("force-caching");
3132

32-
try (CSVReader reader = new CSVReader(new FileReader(TestingUtils.getWorkingDirectory() + "/docs/naaccr-22/Vol II v22 Layout for N22 Base dictionary.csv"))) {
33-
String[] line = reader.readNext(); // ignore headers
33+
File file = new File(TestingUtils.getWorkingDirectory() + "/docs/naaccr-22/Vol II v22 Layout for N22 Base dictionary.csv");
34+
try (CsvReader<NamedCsvRecord> reader = CsvReader.builder().ofNamedCsvRecord(file.toPath())) {
35+
reader.stream().forEach(line -> {
3436

35-
line = reader.readNext();
36-
while (line != null) {
37-
38-
Integer length = Integer.parseInt(line[0]);
39-
Integer num = Integer.parseInt(line[1]);
40-
String name = line[2];
41-
String id = line[3];
42-
String level = line[6];
43-
String type = line[7];
44-
boolean isNew = "New".equals(line[8]);
37+
Integer length = Integer.parseInt(line.getField(0));
38+
Integer num = Integer.parseInt(line.getField(1));
39+
String name = line.getField(2);
40+
String id = line.getField(3);
41+
String level = line.getField(6);
42+
String type = line.getField(7);
43+
boolean isNew = "New".equals(line.getField(8));
4544

4645
if (isNew) {
4746
NaaccrDictionaryItem item = new NaaccrDictionaryItem();
@@ -60,9 +59,7 @@ public static void main(String[] args) throws Exception {
6059
if (item == null)
6160
System.out.println("!!! Unable to find " + id);
6261
}
63-
64-
line = reader.readNext();
65-
}
62+
});
6663
}
6764

6865
dictionary.setItems(dictionary.getItems().stream().sorted(Comparator.comparing(NaaccrDictionaryItem::getNaaccrId)).collect(Collectors.toList()));

0 commit comments

Comments
 (0)