Skip to content

Commit 4c14955

Browse files
committed
Fix warnings and code smells
1 parent ebb1080 commit 4c14955

File tree

15 files changed

+29
-49
lines changed

15 files changed

+29
-49
lines changed

vdyp-common/src/main/java/ca/bc/gov/nrs/vdyp/common/ExpectationDifference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static <U> ExpectationDifference<U> difference(Collection<U> values, Coll
3434
missing.removeAll(values);
3535
var unexpected = new HashSet<U>(values);
3636
unexpected.removeAll(expected);
37-
return new ExpectationDifference<U>(missing, unexpected);
37+
return new ExpectationDifference<>(missing, unexpected);
3838
}
3939

4040
/**

vdyp-common/src/main/java/ca/bc/gov/nrs/vdyp/common/ValueOrMarker.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public <T> T handle(Function<Value, T> valueHandler, Function<Marker, T> markerH
8888
* @return
8989
*/
9090
public static <Value, Marker> Builder<Value, Marker> builder(Class<Value> vClazz, Class<Marker> mClazz) {
91-
return new Builder<Value, Marker>();
91+
return new Builder<>();
9292
}
9393

9494
/**
@@ -110,14 +110,14 @@ public Builder() {
110110
* Create a ValueOrMarker with a Marker
111111
*/
112112
public ValueOrMarker<Value, Marker> marker(Marker m) {
113-
return new ValueOrMarker<Value, Marker>(m, true);
113+
return new ValueOrMarker<>(m, true);
114114
}
115115

116116
/**
117117
* Create a ValueOrMarker with a Value
118118
*/
119119
public ValueOrMarker<Value, Marker> value(Value v) {
120-
return new ValueOrMarker<Value, Marker>(v, false);
120+
return new ValueOrMarker<>(v, false);
121121
}
122122
}
123123
}

vdyp-common/src/main/java/ca/bc/gov/nrs/vdyp/io/parse/GenusDefinitionParser.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.util.List;
88
import java.util.Map;
99
import java.util.Optional;
10-
import java.util.stream.Collectors;
1110

1211
import ca.bc.gov.nrs.vdyp.common.Utils;
1312
import ca.bc.gov.nrs.vdyp.model.GenusDefinition;
@@ -60,9 +59,9 @@ public GenusDefinitionParser() {
6059
this.numSp0 = 16;
6160
}
6261

63-
public GenusDefinitionParser(int num_sp0) {
62+
public GenusDefinitionParser(int numSp0) {
6463
super();
65-
this.numSp0 = num_sp0;
64+
this.numSp0 = numSp0;
6665
}
6766

6867
@SuppressWarnings("unchecked")

vdyp-common/src/main/java/ca/bc/gov/nrs/vdyp/model/BaseVdypPolygon.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package ca.bc.gov.nrs.vdyp.model;
22

33
import java.util.Collection;
4-
import java.util.Collections;
54
import java.util.EnumMap;
65
import java.util.LinkedHashMap;
76
import java.util.LinkedList;

vdyp-common/src/main/java/ca/bc/gov/nrs/vdyp/model/VdypLayer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package ca.bc.gov.nrs.vdyp.model;
22

3-
import java.util.Arrays;
43
import java.util.Optional;
54
import java.util.function.Consumer;
65

vdyp-common/src/main/java/ca/bc/gov/nrs/vdyp/model/VdypPolygon.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public <O extends BaseVdypPolygon<?, U>, U> VdypPolygon(O toCopy, Function<U, Fl
3333

3434
@Computed
3535
public int getInventoryTypeGroup() {
36-
return this.getLayers().get(LayerType.PRIMARY).getInventoryTypeGroup().get();
36+
return this.getLayers().get(LayerType.PRIMARY).getInventoryTypeGroup().orElseThrow(
37+
() -> new IllegalArgumentException("Inventory Type Group does not exist if there is no primary layer")
38+
);
3739
}
3840

3941
@Computed

vdyp-common/src/test/java/ca/bc/gov/nrs/vdyp/io/parse/BecDefinitionParserTest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,15 @@
55
import static org.hamcrest.MatcherAssert.assertThat;
66
import static org.hamcrest.Matchers.allOf;
77
import static org.hamcrest.Matchers.hasProperty;
8-
import static org.hamcrest.Matchers.is;
98
import static org.hamcrest.Matchers.sameInstance;
109
import static org.junit.jupiter.api.Assertions.assertThrows;
1110

12-
import java.util.ArrayList;
1311
import java.util.Collections;
14-
import java.util.List;
15-
import java.util.Map;
16-
1712
import static org.hamcrest.Matchers.equalTo;
1813

1914
import org.hamcrest.Matchers;
2015
import org.junit.jupiter.api.Test;
2116

22-
import ca.bc.gov.nrs.vdyp.model.BecDefinition;
23-
import ca.bc.gov.nrs.vdyp.model.BecLookup;
2417
import ca.bc.gov.nrs.vdyp.model.Region;
2518
import ca.bc.gov.nrs.vdyp.test.TestUtils;
2619

vdyp-common/src/test/java/ca/bc/gov/nrs/vdyp/io/parse/ValueParserTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package ca.bc.gov.nrs.vdyp.io.parse;
22

3-
import static ca.bc.gov.nrs.vdyp.common.Utils.constMap;
4-
import static ca.bc.gov.nrs.vdyp.test.VdypMatchers.isMarker;
5-
import static ca.bc.gov.nrs.vdyp.test.VdypMatchers.isValue;
63
import static ca.bc.gov.nrs.vdyp.test.VdypMatchers.notPresent;
74
import static ca.bc.gov.nrs.vdyp.test.VdypMatchers.present;
85
import static org.hamcrest.MatcherAssert.assertThat;
96
import static org.hamcrest.Matchers.aMapWithSize;
10-
import static org.hamcrest.Matchers.equalTo;
117
import static org.hamcrest.Matchers.hasEntry;
128
import static org.hamcrest.Matchers.hasProperty;
139
import static org.hamcrest.Matchers.is;
@@ -19,7 +15,6 @@
1915

2016
import org.junit.jupiter.api.Test;
2117

22-
import ca.bc.gov.nrs.vdyp.common.Utils;
2318
import ca.bc.gov.nrs.vdyp.model.LayerType;
2419

2520
class ValueParserTest {

vdyp-common/src/test/java/ca/bc/gov/nrs/vdyp/io/write/VriAdjustInputWriterTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,14 @@
77
import java.io.IOException;
88
import java.io.InputStream;
99
import java.io.OutputStream;
10-
import java.util.Collections;
1110
import java.util.HashMap;
12-
import java.util.List;
1311
import java.util.Map;
14-
import java.util.Optional;
15-
1612
import org.junit.jupiter.api.BeforeEach;
1713
import org.junit.jupiter.api.Test;
1814

1915
import ca.bc.gov.nrs.vdyp.common.ControlKeys;
2016
import ca.bc.gov.nrs.vdyp.common.Utils;
2117
import ca.bc.gov.nrs.vdyp.io.FileResolver;
22-
import ca.bc.gov.nrs.vdyp.model.Coefficients;
2318
import ca.bc.gov.nrs.vdyp.model.FipMode;
2419
import ca.bc.gov.nrs.vdyp.model.LayerType;
2520
import ca.bc.gov.nrs.vdyp.model.VdypLayer;

vdyp-common/src/test/java/ca/bc/gov/nrs/vdyp/model/FipModeTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212
class FipModeTest {
1313

1414
@ParameterizedTest()
15-
@EnumSource(FipMode.class)
16-
void testGetByCodeExpected(FipMode mode){
15+
@EnumSource(FipMode.class)
16+
void testGetByCodeExpected(FipMode mode) {
1717
var result = FipMode.getByCode(mode.getCode());
1818
assertThat(result, present(is(mode)));
1919
}
20-
20+
2121
@ParameterizedTest()
22-
@ValueSource(ints= {-2, Integer.MIN_VALUE, Integer.MAX_VALUE, 42})
23-
void testGetByCodeUnexpected(int code){
22+
@ValueSource(ints = { -2, Integer.MIN_VALUE, Integer.MAX_VALUE, 42 })
23+
void testGetByCodeUnexpected(int code) {
2424
var result = FipMode.getByCode(code);
2525
assertThat(result, present(is(FipMode.DONT_PROCESS)));
2626
}
27-
27+
2828
@ParameterizedTest()
29-
@ValueSource(ints= {0})
30-
void testGetByCodeMissing(int code){
29+
@ValueSource(ints = { 0 })
30+
void testGetByCodeMissing(int code) {
3131
var result = FipMode.getByCode(code);
3232
assertThat(result, notPresent());
3333
}

vdyp-common/src/test/java/ca/bc/gov/nrs/vdyp/model/VdypPolygonTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import static org.junit.jupiter.api.Assertions.assertThrows;
66

77
import org.easymock.EasyMock;
8-
import org.hamcrest.Matchers;
98
import org.junit.jupiter.api.Test;
109

1110
class VdypPolygonTest {

vdyp-common/src/test/java/ca/bc/gov/nrs/vdyp/model/VdypSpeciesTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import static org.hamcrest.Matchers.*;
55
import static org.junit.jupiter.api.Assertions.assertThrows;
66

7-
import org.easymock.EasyMock;
87
import org.junit.jupiter.api.Test;
98

109
class VdypSpeciesTest {

vdyp-fip/src/main/java/ca/bc/gov/nrs/vdyp/fip/FipStart.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,13 @@ VdypPolygon createVdypPolygon(FipPolygon fipPolygon, Map<LayerType, VdypLayer> p
366366

367367
float percentAvailable = estimatePercentForestLand(fipPolygon, fipVetLayer, fipPrimaryLayer);
368368

369-
var vdypPolygon = VdypPolygon.build(builder -> {
370-
builder.copy(fipPolygon, (x) -> percentAvailable);
371-
});
369+
var vdypPolygon = VdypPolygon.build(builder -> builder.copy(fipPolygon, x -> percentAvailable));
372370
vdypPolygon.setLayers(processedLayers);
373371
return vdypPolygon;
374372
}
375373

376374
// FIPLAND
375+
@SuppressWarnings("java:S3655")
377376
float estimatePercentForestLand(FipPolygon fipPolygon, FipLayer fipVetLayer, FipLayerPrimary fipPrimaryLayer)
378377
throws ProcessingException {
379378
if (fipPolygon.getPercentAvailable().isPresent()) {
@@ -1575,6 +1574,7 @@ void reconcileComponents(
15751574
private static final List<UtilizationClass> MODE_1_RECONCILE_AVAILABILITY_CLASSES = List
15761575
.of(UtilizationClass.OVER225, UtilizationClass.U175TO225, UtilizationClass.U125TO175);
15771576

1577+
@SuppressWarnings("java:S3655")
15781578
void reconcileComponentsMode1(
15791579
Coefficients baseAreaUtil, Coefficients treesPerHectareUtil, Coefficients quadMeanDiameterUtil,
15801580
float tphSumHigh
@@ -1741,6 +1741,7 @@ private void reconcileComponentsMode2(
17411741
}
17421742
}
17431743

1744+
@SuppressWarnings("java:S3655")
17441745
void reconcileComponentsMode3(
17451746
Coefficients baseAreaUtil, Coefficients treesPerHectareUtil, Coefficients quadMeanDiameterUtil
17461747
) {
@@ -1876,6 +1877,8 @@ void estimateQuadMeanDiameterByUtilization(BecDefinition bec, Coefficients quadM
18761877
throw new IllegalStateException(
18771878
"Should not be attempting to process small component or all large components"
18781879
);
1880+
default:
1881+
throw new IllegalStateException("Unknown utilization class " + uc);
18791882
}
18801883

18811884
log.atDebug().setMessage("Util DQ for class {} is {}").addArgument(uc.name)
@@ -1915,15 +1918,14 @@ List<FipSpecies> findPrimarySpecies(Map<String, FipSpecies> allSpecies) {
19151918
// Start with a deep copy of the species map so there are no side effects from
19161919
// the manipulation this method does.
19171920
var combined = new HashMap<String, FipSpecies>(allSpecies.size());
1918-
allSpecies.entrySet().stream().forEach(spec -> {
1919-
combined.put(spec.getKey(), new FipSpecies(spec.getValue()));
1920-
});
1921+
allSpecies.entrySet().stream().forEach(spec -> combined.put(spec.getKey(), new FipSpecies(spec.getValue())));
19211922

19221923
for (var combinationGroup : PRIMARY_SPECIES_TO_COMBINE) {
19231924
var groupSpecies = combinationGroup.stream().map(combined::get).filter(Objects::nonNull).toList();
19241925
if (groupSpecies.size() < 2) {
19251926
continue;
19261927
}
1928+
@SuppressWarnings("java:S3655")
19271929
var groupPrimary = new FipSpecies(groupSpecies.stream().sorted(PERCENT_GENUS_DESCENDING).findFirst().get());
19281930
var total = (float) groupSpecies.stream().mapToDouble(FipSpecies::getPercentGenus).sum();
19291931
combinationGroup.forEach(combined::remove);
@@ -2522,9 +2524,7 @@ float normalizeUtilizationComponents(Coefficients components) throws ProcessingE
25222524
if (sum <= 0f) {
25232525
throw new ProcessingException("Total volume " + sum + " was not positive.");
25242526
}
2525-
UTIL_CLASSES.forEach(uc -> {
2526-
components.setCoe(uc.index, components.getCoe(uc.index) * k);
2527-
});
2527+
UTIL_CLASSES.forEach(uc -> components.setCoe(uc.index, components.getCoe(uc.index) * k));
25282528
return k;
25292529
}
25302530

@@ -3052,7 +3052,9 @@ public void estimateSmallComponents(FipPolygon fPoly, VdypLayer layer) {
30523052
float treesPerHectareSum = 0f;
30533053
float volumeSum = 0f;
30543054

3055-
Region region = BecDefinitionParser.getBecs(controlMap).get(fPoly.getBiogeoclimaticZone()).get().getRegion();
3055+
Region region = BecDefinitionParser.getBecs(controlMap).get(fPoly.getBiogeoclimaticZone())
3056+
.orElseThrow(() -> new IllegalStateException("Could not find BEC " + fPoly.getBiogeoclimaticZone()))
3057+
.getRegion();
30563058

30573059
for (VdypSpecies spec : layer.getSpecies().values()) {
30583060
float loreyHeightSpec = spec.getLoreyHeightByUtilization().getCoe(UTIL_ALL); // HLsp

vdyp-fip/src/test/java/ca/bc/gov/nrs/vdyp/fip/FipStartTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
import org.easymock.EasyMock;
4040
import org.easymock.IMocksControl;
41-
import org.easymock.bytebuddy.agent.builder.AgentBuilder;
4241
import org.hamcrest.Description;
4342
import org.hamcrest.Matcher;
4443
import org.hamcrest.Matchers;

vdyp-fip/src/test/java/ca/bc/gov/nrs/vdyp/fip/RootFinderTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import static org.hamcrest.Matchers.contains;
66

77
import java.util.Arrays;
8-
import java.util.LinkedHashMap;
98
import java.util.Map;
109
import org.apache.commons.math3.analysis.MultivariateMatrixFunction;
1110
import org.apache.commons.math3.analysis.MultivariateVectorFunction;

0 commit comments

Comments
 (0)