Skip to content

Commit 954309e

Browse files
committed
Made code compatible with Java 8 again
1 parent 28b9ff7 commit 954309e

15 files changed

Lines changed: 316 additions & 352 deletions

‎README.md‎

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -87,40 +87,6 @@ If histology is not in the range 9590-9993, one of the following solid tumors se
8787
If DX year is 2006 or earlier and the case is not Benign Brain (C700-C729, C751-C753 with behavior 0/1), the "2006 and earlier Solid Malignant" rules will be used.<br/><br/>
8888
If DX year is 2006 or earlier and the case is Benign Brain (C700-C729, C751-C753 with behavior 0/1), the "2006 and earlier Benign Brain" rules will be used.
8989

90-
## Testing Data
91-
92-
The project contains [a lab class](https://github.com/imsweb/mph/blob/master/src/test/java/lab/TestingDataCreation.java) that can be used to generate CSV files
93-
that contains fake data along with the library result.
94-
95-
A sample testing file is available in the project: [mph-testing-2000-2022.csv.gz](https://github.com/imsweb/mph/blob/master/src/test/resources/mph-testing-2000-2022.csv.gz)
96-
97-
To create larger file, clone the project and execute the main method of that class locally.
98-
99-
The class allows the following parameters (defined in the top of the main method):
100-
- numTests: the number of rows for the generated CSV file
101-
- minDxYear: the minimum DX year to use
102-
- maxDxYear: the maximum DX year to use
103-
104-
The CSV files will contain the following columns:
105-
- year1
106-
- month1
107-
- day1
108-
- site1
109-
- hist1
110-
- beh1
111-
- lat1
112-
- year2
113-
- month2
114-
- day2
115-
- site2
116-
- hist2
117-
- beh2
118-
- lat2
119-
- result
120-
- reason
121-
122-
The lab class uses the [Data Generator](https://github.com/imsweb/data-generator) library to create the fake data.
123-
12490
## About SEER
12591

12692
This library was developed through the [SEER](http://seer.cancer.gov/) program.

‎build.gradle‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import com.vanniktech.maven.publish.*
1+
import com.vanniktech.maven.publish.JavaLibrary
2+
import com.vanniktech.maven.publish.JavadocJar
3+
import com.vanniktech.maven.publish.SonatypeHost
24

35
plugins {
46
id 'java-library'
57
id 'jacoco'
6-
id 'com.vanniktech.maven.publish' version '0.34.0' // publish to Maven Central
8+
id 'com.vanniktech.maven.publish' version '0.31.0' // publish to Maven Central
79
id 'com.github.ben-manes.versions' version '0.52.0' // check for out-of-date dependencies (run 'dependencyUpdates' manually)
810
id 'com.github.spotbugs' version '6.4.2' // spotbugs code analysis
911
id 'org.sonarqube' version '6.3.1.5724' // sonarQube analysis
@@ -20,12 +22,8 @@ repositories {
2022
}
2123

2224
dependencies {
23-
implementation 'org.apache.commons:commons-lang3:3.18.0'
24-
implementation 'de.siegmar:fastcsv:3.7.0'
25-
2625
testImplementation 'junit:junit:4.13.2'
2726
testImplementation 'com.imsweb:seerapi-client-java:5.9'
28-
testImplementation 'com.imsweb:data-generator:2.2'
2927
}
3028

3129
// enforce UTF-8, display the compilation warnings
@@ -35,8 +33,8 @@ tasks.withType(JavaCompile).configureEach {
3533
}
3634

3735
java {
38-
sourceCompatibility = JavaVersion.VERSION_11
39-
targetCompatibility = JavaVersion.VERSION_11
36+
sourceCompatibility = JavaVersion.VERSION_1_8
37+
targetCompatibility = JavaVersion.VERSION_1_8
4038
}
4139

4240
tasks.withType(JavaCompile).configureEach {
@@ -110,7 +108,7 @@ tasks.register('hematoDataTest', Test) {
110108
mavenPublishing {
111109
configure(new JavaLibrary(new JavadocJar.Javadoc(), true))
112110

113-
publishToMavenCentral(true)
111+
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, true) // to upgrade teh plugin, just remove the first parameter...
114112
signAllPublications()
115113

116114
pom {

‎src/main/java/com/imsweb/mph/DefaultHematoDataProvider.java‎

Lines changed: 4 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,15 @@
55

66
import java.io.IOException;
77
import java.io.InputStream;
8-
import java.io.InputStreamReader;
9-
import java.io.Reader;
10-
import java.nio.charset.StandardCharsets;
118
import java.text.ParseException;
129
import java.text.SimpleDateFormat;
13-
import java.util.ArrayList;
1410
import java.util.Collections;
1511
import java.util.Date;
16-
import java.util.HashMap;
1712
import java.util.List;
1813
import java.util.Map;
1914
import java.util.Properties;
2015

21-
import org.apache.commons.lang3.StringUtils;
22-
23-
import de.siegmar.fastcsv.reader.CsvReader;
24-
import de.siegmar.fastcsv.reader.NamedCsvRecord;
25-
16+
import com.imsweb.mph.internal.CsvUtils;
2617
import com.imsweb.mph.internal.HematoDTO;
2718

2819
/**
@@ -36,79 +27,9 @@ public class DefaultHematoDataProvider implements HematoDataProvider {
3627
private final Map<String, List<HematoDTO>> _transformFromDto;
3728

3829
public DefaultHematoDataProvider() {
39-
40-
_samePrimaryDto = new HashMap<>();
41-
try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("Hematopoietic2010SamePrimaryPairs.csv")) {
42-
if (is == null)
43-
throw new IllegalStateException("Unable to get Hematopoietic2010SamePrimaryPairs.csv");
44-
try (Reader reader = new InputStreamReader(is, StandardCharsets.US_ASCII); CsvReader<NamedCsvRecord> csvReader = CsvReader.builder().ofNamedCsvRecord(reader)) {
45-
csvReader.stream().forEach(line -> {
46-
Short validStartYear = StringUtils.isNotBlank(line.getField(1)) ? Short.valueOf(line.getField(1)) : null;
47-
Short validEndYear = StringUtils.isNotBlank(line.getField(2)) ? Short.valueOf(line.getField(2)) : null;
48-
Short startYear = StringUtils.isNotBlank(line.getField(3)) ? Short.valueOf(line.getField(3)) : null;
49-
Short endYear = StringUtils.isNotBlank(line.getField(4)) ? Short.valueOf(line.getField(4)) : null;
50-
if (_samePrimaryDto.containsKey(line.getField(0)))
51-
_samePrimaryDto.get(line.getField(0)).add(new HematoDTO(validStartYear, validEndYear, startYear, endYear, line.getField(5)));
52-
else {
53-
List<HematoDTO> list = new ArrayList<>();
54-
list.add(new HematoDTO(validStartYear, validEndYear, startYear, endYear, line.getField(5)));
55-
_samePrimaryDto.put(line.getField(0), list);
56-
}
57-
});
58-
}
59-
}
60-
catch (IOException e) {
61-
throw new IllegalStateException(e);
62-
}
63-
64-
_transformToDto = new HashMap<>();
65-
try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("Hematopoietic2010TransformToPairs.csv")) {
66-
if (is == null)
67-
throw new IllegalStateException("Unable to get Hematopoietic2010TransformToPairs.csv");
68-
try (Reader reader = new InputStreamReader(is, StandardCharsets.US_ASCII); CsvReader<NamedCsvRecord> csvReader = CsvReader.builder().ofNamedCsvRecord(reader)) {
69-
csvReader.stream().forEach(line -> {
70-
Short validStartYear = StringUtils.isNotBlank(line.getField(1)) ? Short.valueOf(line.getField(1)) : null;
71-
Short validEndYear = StringUtils.isNotBlank(line.getField(2)) ? Short.valueOf(line.getField(2)) : null;
72-
Short startYear = StringUtils.isNotBlank(line.getField(3)) ? Short.valueOf(line.getField(3)) : null;
73-
Short endYear = StringUtils.isNotBlank(line.getField(4)) ? Short.valueOf(line.getField(4)) : null;
74-
if (_transformToDto.containsKey(line.getField(0)))
75-
_transformToDto.get(line.getField(0)).add(new HematoDTO(validStartYear, validEndYear, startYear, endYear, line.getField(5)));
76-
else {
77-
List<HematoDTO> list = new ArrayList<>();
78-
list.add(new HematoDTO(validStartYear, validEndYear, startYear, endYear, line.getField(5)));
79-
_transformToDto.put(line.getField(0), list);
80-
}
81-
});
82-
}
83-
}
84-
catch (IOException e) {
85-
throw new IllegalStateException(e);
86-
}
87-
88-
_transformFromDto = new HashMap<>();
89-
try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("Hematopoietic2010TransformFromPairs.csv")) {
90-
if (is == null)
91-
throw new IllegalStateException("Unable to get Hematopoietic2010TransformFromPairs.csv");
92-
try (Reader reader = new InputStreamReader(is, StandardCharsets.US_ASCII); CsvReader<NamedCsvRecord> csvReader = CsvReader.builder().ofNamedCsvRecord(reader)) {
93-
csvReader.stream().forEach(line -> {
94-
Short validStartYear = StringUtils.isNotBlank(line.getField(1)) ? Short.valueOf(line.getField(1)) : null;
95-
Short validEndYear = StringUtils.isNotBlank(line.getField(2)) ? Short.valueOf(line.getField(2)) : null;
96-
Short startYear = StringUtils.isNotBlank(line.getField(3)) ? Short.valueOf(line.getField(3)) : null;
97-
Short endYear = StringUtils.isNotBlank(line.getField(4)) ? Short.valueOf(line.getField(4)) : null;
98-
if (_transformFromDto.containsKey(line.getField(0)))
99-
_transformFromDto.get(line.getField(0)).add(new HematoDTO(validStartYear, validEndYear, startYear, endYear, line.getField(5)));
100-
else {
101-
List<HematoDTO> list = new ArrayList<>();
102-
list.add(new HematoDTO(validStartYear, validEndYear, startYear, endYear, line.getField(5)));
103-
_transformFromDto.put(line.getField(0), list);
104-
}
105-
});
106-
}
107-
}
108-
catch (IOException e) {
109-
throw new IllegalStateException(e);
110-
}
111-
30+
_samePrimaryDto = CsvUtils.parseHematoCsvFile("Hematopoietic2010SamePrimaryPairs.csv");
31+
_transformToDto = CsvUtils.parseHematoCsvFile("Hematopoietic2010TransformToPairs.csv");
32+
_transformFromDto = CsvUtils.parseHematoCsvFile("Hematopoietic2010TransformFromPairs.csv");
11233
}
11334

11435
@Override

‎src/main/java/com/imsweb/mph/MphGroup.java‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import java.util.ArrayList;
77
import java.util.List;
88

9-
import org.apache.commons.lang3.Range;
10-
9+
import com.imsweb.mph.internal.Range;
1110
import com.imsweb.mph.mpgroups.GroupUtility;
1211

12+
@SuppressWarnings("unused")
1313
public abstract class MphGroup {
1414

1515
protected String _id;
@@ -30,17 +30,17 @@ public abstract class MphGroup {
3030

3131
protected List<MphRule> _rules;
3232

33-
private List<Range<Integer>> _siteIncRanges;
33+
private final List<Range> _siteIncRanges;
3434

35-
private List<Range<Integer>> _siteExcRanges;
35+
private final List<Range> _siteExcRanges;
3636

37-
private List<Range<Integer>> _histIncRanges;
37+
private final List<Range> _histIncRanges;
3838

39-
private List<Range<Integer>> _histExcRanges;
39+
private final List<Range> _histExcRanges;
4040

41-
private List<Range<Integer>> _behavIncRanges;
41+
private final List<Range> _behavIncRanges;
4242

43-
private List<Range<Integer>> _yearIncRanges;
43+
private final List<Range> _yearIncRanges;
4444

4545
protected MphGroup(String id, String name, String siteInclusions, String siteExclusions, String histInclusions, String histExclusions, String behavInclusions, String yearInclusions) {
4646
_id = id;

‎src/main/java/com/imsweb/mph/MphInput.java‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
*/
44
package com.imsweb.mph;
55

6-
import org.apache.commons.lang3.math.NumberUtils;
7-
86
import com.imsweb.mph.mpgroups.GroupUtility;
97

108
/**
@@ -43,7 +41,6 @@ public void setPrimarySite(String primarySite) {
4341
_primarySite = primarySite;
4442
}
4543

46-
4744
public void setHistologyIcdO3(String histologyIcdO3) {
4845
_histologyIcdO3 = histologyIcdO3;
4946
}
@@ -61,12 +58,12 @@ public void setBehaviorIcdO2(String behaviorIcdO2) {
6158
}
6259

6360
public String getHistology() {
64-
int year = NumberUtils.isDigits(_dateOfDiagnosisYear) ? Integer.parseInt(_dateOfDiagnosisYear) : 9999;
61+
int year = MphUtils.isDigits(_dateOfDiagnosisYear) ? Integer.parseInt(_dateOfDiagnosisYear) : 9999;
6562
return year < 2001 && GroupUtility.validateHistology(_histologyIcdO2) ? _histologyIcdO2 : _histologyIcdO3;
6663
}
6764

6865
public String getBehavior() {
69-
int year = NumberUtils.isDigits(_dateOfDiagnosisYear) ? Integer.parseInt(_dateOfDiagnosisYear) : 9999;
66+
int year = MphUtils.isDigits(_dateOfDiagnosisYear) ? Integer.parseInt(_dateOfDiagnosisYear) : 9999;
7067
return year < 2001 && GroupUtility.validateBehavior(_behaviorIcdO2) ? _behaviorIcdO2 : _behaviorIcdO3;
7168
}
7269

@@ -102,7 +99,6 @@ public void setDateOfDiagnosisDay(String dateOfDiagnosisDay) {
10299
_dateOfDiagnosisDay = dateOfDiagnosisDay;
103100
}
104101

105-
106102
public String getIcdCode() {
107103
return getHistology() + "/" + getBehavior();
108104
}

‎src/main/java/com/imsweb/mph/MphUtils.java‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
import java.util.Map;
1212
import java.util.regex.Pattern;
1313

14-
import org.apache.commons.lang3.StringUtils;
15-
import org.apache.commons.lang3.math.NumberUtils;
16-
1714
import com.imsweb.mph.internal.TempRuleResult;
1815
import com.imsweb.mph.mpgroups.GroupUtility;
1916
import com.imsweb.mph.mpgroups.Mp1998HematopoieticGroup;
@@ -60,7 +57,9 @@
6057
*/
6158
public final class MphUtils {
6259

63-
private final Pattern _morphology = Pattern.compile("^(\\d{4}/\\d)");
60+
private final static Pattern _MORPHOLOGY_PATTERN = Pattern.compile("^(\\d{4}/\\d)");
61+
62+
private final static Pattern _DIGITS_PATTERN = Pattern.compile("\\d+");
6463

6564
/**
6665
* The possible result of determining if two tumors are single or multiple primaries.
@@ -117,6 +116,10 @@ public static synchronized MphUtils getInstance() {
117116
return _INSTANCE;
118117
}
119118

119+
public static boolean isDigits(String value) {
120+
return value != null && _DIGITS_PATTERN.matcher(value).matches();
121+
}
122+
120123
/**
121124
* Constructor
122125
* This will use the default hemato db provider
@@ -201,8 +204,8 @@ public MphUtils(HematoDataProvider provider) {
201204
public MphOutput computePrimaries(MphInput input1, MphInput input2) {
202205
MphOutput output = new MphOutput();
203206

204-
int year1 = NumberUtils.isDigits(input1.getDateOfDiagnosisYear()) ? Integer.parseInt(input1.getDateOfDiagnosisYear()) : -1;
205-
int year2 = NumberUtils.isDigits(input2.getDateOfDiagnosisYear()) ? Integer.parseInt(input2.getDateOfDiagnosisYear()) : -1;
207+
int year1 = isDigits(input1.getDateOfDiagnosisYear()) ? Integer.parseInt(input1.getDateOfDiagnosisYear()) : -1;
208+
int year2 = isDigits(input2.getDateOfDiagnosisYear()) ? Integer.parseInt(input2.getDateOfDiagnosisYear()) : -1;
206209
String site1 = input1.getPrimarySite();
207210
String site2 = input2.getPrimarySite();
208211
String hist1 = input1.getHistology();
@@ -273,7 +276,7 @@ else if (result.getFinalResult() != null) {
273276
if (potentialResult == null || potentialResult.getPotentialResult().equals(result.getFinalResult())) {
274277
output.setResult(result.getFinalResult());
275278
output.setStep(rule.getStep());
276-
output.setReason(StringUtils.isNotBlank(result.getMessage()) ? result.getMessage() : rule.getReason());
279+
output.setReason(result.getMessage() != null && !result.getMessage().trim().isEmpty() ? result.getMessage() : rule.getReason());
277280
if (potentialResult != null && potentialResult.getPotentialResult().equals(result.getFinalResult()))
278281
output.getAppliedRules().addAll(rulesAppliedAfterQuestionable);
279282
}
@@ -332,7 +335,7 @@ public Date getHematoDataLastUpdated() {
332335
* @return true if two diseases are same primary and false otherwise.
333336
*/
334337
public boolean isHematoSamePrimary(String morph1, String morph2, int year1, int year2) {
335-
if (morph1 == null || morph2 == null || !_morphology.matcher(morph1).matches() || !_morphology.matcher(morph2).matches())
338+
if (morph1 == null || morph2 == null || !_MORPHOLOGY_PATTERN.matcher(morph1).matches() || !_MORPHOLOGY_PATTERN.matcher(morph2).matches())
336339
return false;
337340
if (morph1.equals(morph2))
338341
return true;

0 commit comments

Comments
 (0)