Skip to content

Commit

Permalink
Fix sonar warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
smithkm committed Dec 9, 2024
1 parent d78f01e commit 7620e02
Show file tree
Hide file tree
Showing 19 changed files with 190 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ void prepare(BackProcessingState state) throws ProcessingException {
final int specIndex = i + 1;
cvVolume[specIndex] = new MatrixMap2Impl<>(
List.of(UtilizationClass.values()), VdypCompatibilityVariables.VOLUME_UTILIZATION_VARIABLES,
(uc, vv) -> primaryState.getCVVolume(specIndex, uc, vv, LayerType.PRIMARY)
(uc, vv) -> primaryState.getCvVolume(specIndex, uc, vv, LayerType.PRIMARY)
);

cvBasalArea[specIndex] = new EnumMap<>(UtilizationClass.class);
cvQuadraticMeanDiameter[specIndex] = new EnumMap<>(UtilizationClass.class);
cvPrimaryLayerSmall[specIndex] = new EnumMap<>(UtilizationClassVariable.class);

for (var uc : UtilizationClass.values()) {
cvBasalArea[specIndex].put(uc, primaryState.getCVBasalArea(specIndex, uc, LayerType.PRIMARY));
cvBasalArea[specIndex].put(uc, primaryState.getCvBasalArea(specIndex, uc, LayerType.PRIMARY));
cvQuadraticMeanDiameter[specIndex]
.put(uc, primaryState.getCVQuadraticMeanDiameter(specIndex, uc, LayerType.PRIMARY));
.put(uc, primaryState.getCvQuadraticMeanDiameter(specIndex, uc, LayerType.PRIMARY));
}

for (var ucv : VdypCompatibilityVariables.SMALL_UTILIZATION_VARIABLES) {
cvPrimaryLayerSmall[specIndex].put(ucv, primaryState.getCVSmall(specIndex, ucv));
cvPrimaryLayerSmall[specIndex].put(ucv, primaryState.getCvSmall(specIndex, ucv));
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ca.bc.gov.nrs.vdyp.application;

import ca.bc.gov.nrs.vdyp.common.Utils;
import ca.bc.gov.nrs.vdyp.model.VdypPolygon;

public abstract class ProcessingEngine<E extends ProcessingEngine.ExecutionStep<E>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
import static java.lang.Math.max;
import static java.lang.Math.min;

import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -69,7 +65,6 @@
import ca.bc.gov.nrs.vdyp.model.UtilizationVector;
import ca.bc.gov.nrs.vdyp.model.VdypLayer;
import ca.bc.gov.nrs.vdyp.model.VdypSpecies;
import ca.bc.gov.nrs.vdyp.model.VdypUtilizationHolder;
import ca.bc.gov.nrs.vdyp.model.VolumeComputeMode;

public abstract class VdypStartApplication<P extends BaseVdypPolygon<L, Optional<Float>, S, I>, L extends BaseVdypLayer<S, I> & InputLayer, S extends BaseVdypSpecies<I>, I extends BaseVdypSite>
Expand Down Expand Up @@ -1453,7 +1448,7 @@ protected void computeUtilizationComponentsVeteran(VdypLayer vdypLayer, BecDefin
);

for (var accessors : ComputationMethods.UTILIZATION_VECTOR_ACCESSORS) {
UtilizationVector utilVector = (UtilizationVector) accessors.get(vdypSpecies);
UtilizationVector utilVector = accessors.get(vdypSpecies);

// Set all components other than 4 to 0.0
for (var uc : UtilizationClass.ALL_BUT_LARGEST) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import ca.bc.gov.nrs.vdyp.application.InitializationIncompleteException;
import ca.bc.gov.nrs.vdyp.common.Computed;
import ca.bc.gov.nrs.vdyp.common.Utils;
import ca.bc.gov.nrs.vdyp.io.parse.coe.GenusDefinitionParser;
import ca.bc.gov.nrs.vdyp.model.builders.ModelClassBuilder;
import ca.bc.gov.nrs.vdyp.model.builders.SpeciesGroupIdentifiedBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.function.Consumer;

import ca.bc.gov.nrs.vdyp.common.Computed;
import ca.bc.gov.nrs.vdyp.common.Utils;

public class VdypLayer extends BaseVdypLayer<VdypSpecies, VdypSite> implements VdypUtilizationHolder {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ca.bc.gov.nrs.vdyp.processing_state;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -10,7 +9,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ca.bc.gov.nrs.vdyp.application.ProcessingException;
import ca.bc.gov.nrs.vdyp.controlmap.ResolvedControlMap;
import ca.bc.gov.nrs.vdyp.model.BecDefinition;
import ca.bc.gov.nrs.vdyp.model.LayerType;
Expand Down Expand Up @@ -119,24 +117,24 @@ public void setCompatibilityVariableDetails(
}).toList());
}

public float getCVVolume(
public float getCvVolume(
int speciesIndex, UtilizationClass uc, UtilizationClassVariable volumeVariable, LayerType layerType
) {
return compatibilityVariables.orElseThrow(() -> new IllegalStateException(UNSET_CV_VOLUMES)).get(speciesIndex)
.getCvVolume(uc, volumeVariable, layerType);
}

public float getCVBasalArea(int speciesIndex, UtilizationClass uc, LayerType layerType) {
public float getCvBasalArea(int speciesIndex, UtilizationClass uc, LayerType layerType) {
return compatibilityVariables.orElseThrow(() -> new IllegalStateException(UNSET_CV_VOLUMES)).get(speciesIndex)
.getCvBasalArea(uc, layerType);
}

public float getCVQuadraticMeanDiameter(int speciesIndex, UtilizationClass uc, LayerType layerType) {
public float getCvQuadraticMeanDiameter(int speciesIndex, UtilizationClass uc, LayerType layerType) {
return compatibilityVariables.orElseThrow(() -> new IllegalStateException(UNSET_CV_VOLUMES)).get(speciesIndex)
.getCvQuadraticMeanDiameter(uc, layerType);
}

public float getCVSmall(int speciesIndex, UtilizationClassVariable variable) {
public float getCvSmall(int speciesIndex, UtilizationClassVariable variable) {
return compatibilityVariables.orElseThrow(() -> new IllegalStateException(UNSET_CV_VOLUMES)).get(speciesIndex)
.getCvPrimaryLayerSmall(variable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import ca.bc.gov.nrs.vdyp.application.VdypStartApplication;
import ca.bc.gov.nrs.vdyp.common.ControlKey;
import ca.bc.gov.nrs.vdyp.common.Utils;
import ca.bc.gov.nrs.vdyp.controlmap.ResolvedControlMap;
import ca.bc.gov.nrs.vdyp.io.FileSystemFileResolver;
import ca.bc.gov.nrs.vdyp.io.parse.common.ResourceParseException;
import ca.bc.gov.nrs.vdyp.io.parse.control.ControlMapValueReplacer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ca.bc.gov.nrs.vdyp.io.parse.model;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.*;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import ca.bc.gov.nrs.vdyp.test.TestUtils;
import ca.bc.gov.nrs.vdyp.test.VdypMatchers;

import static ca.bc.gov.nrs.vdyp.test.VdypMatchers.*;

class VdypSpeciesParserTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import ca.bc.gov.nrs.vdyp.application.InitializationIncompleteException;
import ca.bc.gov.nrs.vdyp.model.variables.UtilizationClassVariable;
import ca.bc.gov.nrs.vdyp.test.VdypMatchers;

class VdypSpeciesTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,21 @@ void cleanup() {
void testFailBeforeSet() throws ProcessingException {
assertThrows(
IllegalStateException.class,
() -> unit.getCVVolume(
() -> unit.getCvVolume(
1, UtilizationClass.ALL, UtilizationClassVariable.CLOSE_UTIL_VOL, LayerType.PRIMARY
), "getCVVolume"
);
assertThrows(
IllegalStateException.class, () -> unit.getCVBasalArea(1, UtilizationClass.ALL, LayerType.PRIMARY),
IllegalStateException.class, () -> unit.getCvBasalArea(1, UtilizationClass.ALL, LayerType.PRIMARY),
"getCVBasalArea"
);
assertThrows(
IllegalStateException.class,
() -> unit.getCVQuadraticMeanDiameter(1, UtilizationClass.ALL, LayerType.PRIMARY),
() -> unit.getCvQuadraticMeanDiameter(1, UtilizationClass.ALL, LayerType.PRIMARY),
"getCVQuadraticMeanDiameter"
);
assertThrows(
IllegalStateException.class, () -> unit.getCVSmall(1, UtilizationClassVariable.BASAL_AREA),
IllegalStateException.class, () -> unit.getCvSmall(1, UtilizationClassVariable.BASAL_AREA),
"getCVSmall"
);
}
Expand All @@ -216,7 +216,7 @@ void testSucceedAfterSet() throws ProcessingException {
assertThat(
unit,
testCV(
"getCVVolume", 1, UtilizationClass.ALL, UtilizationClassVariable.CLOSE_UTIL_VOL,
"getCvVolume", 1, UtilizationClass.ALL, UtilizationClassVariable.CLOSE_UTIL_VOL,
LayerType.PRIMARY,
is(
11f + UtilizationClassVariable.CLOSE_UTIL_VOL.ordinal() * 2f
Expand All @@ -227,21 +227,21 @@ void testSucceedAfterSet() throws ProcessingException {
assertThat(
unit,
testCV(
"getCVBasalArea", 1, UtilizationClass.ALL, LayerType.PRIMARY,
"getCvBasalArea", 1, UtilizationClass.ALL, LayerType.PRIMARY,
is(13f + UtilizationClass.ALL.ordinal() * 3f + LayerType.PRIMARY.ordinal() * 5f)
)
);
assertThat(
unit,
testCV(
"getCVQuadraticMeanDiameter", 1, UtilizationClass.U125TO175, LayerType.PRIMARY,
"getCvQuadraticMeanDiameter", 1, UtilizationClass.U125TO175, LayerType.PRIMARY,
is(17f + UtilizationClass.U125TO175.ordinal() * 3f + LayerType.PRIMARY.ordinal() * 5f)
)
);
assertThat(
unit,
testCV(
"getCVSmall", 1, UtilizationClassVariable.QUAD_MEAN_DIAMETER,
"getCvSmall", 1, UtilizationClassVariable.QUAD_MEAN_DIAMETER,
is(UtilizationClassVariable.QUAD_MEAN_DIAMETER.ordinal() * 7f)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import ca.bc.gov.nrs.vdyp.model.VdypLayer;
import ca.bc.gov.nrs.vdyp.model.VdypPolygon;
import ca.bc.gov.nrs.vdyp.model.VdypSpecies;
import ca.bc.gov.nrs.vdyp.processing_state.LayerProcessingState;
import ca.bc.gov.nrs.vdyp.processing_state.ProcessingState;

public class TestLayerProcessingState extends LayerProcessingState<ResolvedControlMap, TestLayerProcessingState> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
import ca.bc.gov.nrs.vdyp.model.VdypPolygon;
import ca.bc.gov.nrs.vdyp.processing_state.Bank;
import ca.bc.gov.nrs.vdyp.processing_state.ProcessingState;
import ca.bc.gov.nrs.vdyp.processing_state.TestProcessingState;

public class TestUtils {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ca.bc.gov.nrs.vdyp.test;

import static ca.bc.gov.nrs.vdyp.test.TestUtils.UTIL_CLASSES;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anything;
Expand Down Expand Up @@ -38,8 +37,6 @@
import org.hamcrest.Matchers;
import org.hamcrest.StringDescription;
import org.hamcrest.TypeSafeDiagnosingMatcher;
import org.junit.platform.commons.util.ReflectionUtils;

import ca.bc.gov.nrs.vdyp.common.ControlKey;
import ca.bc.gov.nrs.vdyp.common.Utils;
import ca.bc.gov.nrs.vdyp.common.ValueOrMarker;
Expand All @@ -54,7 +51,6 @@
import ca.bc.gov.nrs.vdyp.model.Coefficients;
import ca.bc.gov.nrs.vdyp.model.MatrixMap;
import ca.bc.gov.nrs.vdyp.model.PolygonIdentifier;
import ca.bc.gov.nrs.vdyp.model.Sp64DistributionSet;
import ca.bc.gov.nrs.vdyp.model.UtilizationClass;
import ca.bc.gov.nrs.vdyp.model.UtilizationVector;
import ca.bc.gov.nrs.vdyp.model.VdypCompatibilityVariables;
Expand All @@ -67,7 +63,6 @@
import ca.bc.gov.nrs.vdyp.processing_state.Bank;
import ca.bc.gov.nrs.vdyp.processing_state.LayerProcessingState;
import ca.bc.gov.nrs.vdyp.processing_state.ProcessingState;
import ca.bc.gov.nrs.vdyp.processing_state.TestProcessingState;

/**
* Custom Hamcrest Matchers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

import ca.bc.gov.nrs.vdyp.application.ProcessingException;
import ca.bc.gov.nrs.vdyp.common.Utils;
import ca.bc.gov.nrs.vdyp.controlmap.ResolvedControlMap;
import ca.bc.gov.nrs.vdyp.controlmap.ResolvedControlMapImpl;
import ca.bc.gov.nrs.vdyp.model.BecDefinition;
import ca.bc.gov.nrs.vdyp.model.LayerType;
import ca.bc.gov.nrs.vdyp.model.MatrixMap;
Expand All @@ -41,7 +39,6 @@
import ca.bc.gov.nrs.vdyp.model.VdypSpecies;
import ca.bc.gov.nrs.vdyp.model.variables.UtilizationClassVariable;
import ca.bc.gov.nrs.vdyp.processing_state.Bank;
import ca.bc.gov.nrs.vdyp.processing_state.LayerProcessingState;
import ca.bc.gov.nrs.vdyp.processing_state.TestLayerProcessingState;
import ca.bc.gov.nrs.vdyp.processing_state.TestProcessingState;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1543,19 +1543,19 @@ private void calculateSmallComponentYields(ForwardLayerProcessingState lps) thro
.getControlVariable(ControlVariable.COMPAT_VAR_APPLICATION_3);

if (controlVar3Value >= 1 /* apply compatibility variables */) {
spBaSmall += lps.getCVSmall(speciesIndex, UtilizationClassVariable.BASAL_AREA);
spBaSmall += lps.getCvSmall(speciesIndex, UtilizationClassVariable.BASAL_AREA);
if (spBaSmall < 0.0f) {
spBaSmall = 0.0f;
}
spDqSmall += lps.getCVSmall(speciesIndex, UtilizationClassVariable.QUAD_MEAN_DIAMETER);
spDqSmall += lps.getCvSmall(speciesIndex, UtilizationClassVariable.QUAD_MEAN_DIAMETER);
FloatMath.clamp(spDqSmall, 4.01f, 7.49f);

spLhSmall = 1.3f + (spLhSmall - 1.3f)
* FloatMath.exp(lps.getCVSmall(speciesIndex, UtilizationClassVariable.LOREY_HEIGHT));
* FloatMath.exp(lps.getCvSmall(speciesIndex, UtilizationClassVariable.LOREY_HEIGHT));

if (controlVar3Value >= 2 && meanVolumeSmall > 0.0f) {
meanVolumeSmall *= FloatMath
.exp(lps.getCVSmall(speciesIndex, UtilizationClassVariable.WHOLE_STEM_VOL));
.exp(lps.getCvSmall(speciesIndex, UtilizationClassVariable.WHOLE_STEM_VOL));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ca.bc.gov.nrs.vdyp.application.ProcessingEngine.ExecutionStep;
import ca.bc.gov.nrs.vdyp.application.ProcessingException;
import ca.bc.gov.nrs.vdyp.common.ControlKey;
import ca.bc.gov.nrs.vdyp.forward.test.ForwardTestUtils;
Expand Down
Loading

0 comments on commit 7620e02

Please sign in to comment.