Skip to content

Commit

Permalink
Cleanup of code, removed unsused/deprecated code. (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilbrand authored Sep 24, 2024
1 parent 984f259 commit fbe55ef
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package nl.overheid.aerius.shared.domain.calculation;
package nl.overheid.aerius.gml;

import java.util.Locale;

import nl.overheid.aerius.shared.domain.calculation.CalculationMethod;

/**
* Type of calculation. It be a radius from the source point or to only
* calculate points within nature areas.
*/
public enum CalculationType {
enum CalculationType {

/**
* Calculate with custom points (fixed set of receptors or user defined points).
Expand All @@ -47,7 +49,7 @@ public enum CalculationType {

private CalculationMethod calculationMethod;

private CalculationType(final CalculationMethod calculationMethod) {
CalculationType(final CalculationMethod calculationMethod) {
this.calculationMethod = calculationMethod;
}

Expand Down Expand Up @@ -78,10 +80,6 @@ public static CalculationType safeValueOf(final String value) {
}
}

public String type() {
return name();
}

/**
* Returns the name in lowercase.
* @return name in lowercase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import nl.overheid.aerius.shared.domain.calculation.CalculationJobType;
import nl.overheid.aerius.shared.domain.calculation.CalculationMethod;
import nl.overheid.aerius.shared.domain.calculation.CalculationSetOptions;
import nl.overheid.aerius.shared.domain.calculation.CalculationType;
import nl.overheid.aerius.shared.domain.v2.scenario.ScenarioMetaData;
import nl.overheid.aerius.util.OptionsMetadataUtil;

Expand Down Expand Up @@ -82,7 +81,7 @@ public CalculationSetOptions readCalculationSetOptions(final Theme theme) {
* @param calculationMetaData
* @param options
*/
private void setCalculationMethod(final IsCalculationMetaData calculationMetaData, final CalculationSetOptions options) {
private static void setCalculationMethod(final IsCalculationMetaData calculationMetaData, final CalculationSetOptions options) {
final String method = calculationMetaData.getCalculationMethod();

options.setCalculationMethod(
Expand All @@ -92,7 +91,7 @@ private void setCalculationMethod(final IsCalculationMetaData calculationMetaDat
/**
* Set the calculation job type.
*/
private void setCalculationJobType(final IsCalculationMetaData calculationMetaData, final CalculationSetOptions options) {
private static void setCalculationJobType(final IsCalculationMetaData calculationMetaData, final CalculationSetOptions options) {
final String jobType = calculationMetaData.getCalculationJobType();

options.setCalculationJobType(jobType == null ? null : CalculationJobType.safeValueOf(jobType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
package nl.overheid.aerius.gml;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -56,7 +58,7 @@ class GMLCalculationSetOptionsReaderTest {
private static final String CALCULATION_JOB_TYPE = "MAX_TEMPORARY_EFFECT";

@Test
void getCalculationMethod() {
void testGetCalculationMethod() {
final FeatureCollection featureCollection = mock(FeatureCollection.class);
when(featureCollection.getMetaData()).thenReturn(null);

Expand Down Expand Up @@ -229,11 +231,11 @@ void testNCAReadCalculationSetOptions(final Boolean spatiallyVaryingRoughness) {
assertEquals(4.2, admsOptions.getMsMinMoninObukhovLength(), "MsMinMoninObukhovLength");
assertEquals(5.3, admsOptions.getMsSurfaceAlbedo(), "MsSurfaceAlbedo");
assertEquals(6.4, admsOptions.getMsPriestleyTaylorParameter(), "MsPriestleyTaylorParameter");
assertEquals(true, admsOptions.isPlumeDepletionNH3(), "PlumeDepletionNH3");
assertEquals(true, admsOptions.isPlumeDepletionNOX(), "PlumeDepletionNOX");
assertTrue(admsOptions.isPlumeDepletionNH3(), "PlumeDepletionNH3");
assertTrue(admsOptions.isPlumeDepletionNOX(), "PlumeDepletionNOX");
assertEquals(spatiallyVaryingRoughness == null || spatiallyVaryingRoughness, admsOptions.isSpatiallyVaryingRoughness(),
"SpatiallyVaryingRoughness");
assertEquals(true, admsOptions.isComplexTerrain(), "ComplexTerrain");
assertTrue(admsOptions.isComplexTerrain(), "ComplexTerrain");

assertEquals(40.0, options.getCalculateMaximumRange(), "Maximum range read");
}
Expand All @@ -258,23 +260,22 @@ void testReadCalculationSetOptionsEmptyOptions() {
assertNull(options.getCalculationJobType(), "CalculationJobType");
final NCACalculationOptions ncaOptions = options.getNcaCalculationOptions();
assertNull(ncaOptions.getPermitArea(), "PermitArea");
assertNull(ncaOptions.getMeteoSiteLocation(), "MeteoSiteLocation");
assertEquals(List.of(), ncaOptions.getMeteoYears(), "MeteoYears");
final ADMSOptions admsOptions = ncaOptions.getAdmsOptions();
assertEquals(ADMSLimits.MIN_MONIN_OBUKHOV_LENGTH_DEFAULT, admsOptions.getMinMoninObukhovLength(),
"MinMoninObukhovLength");
assertEquals(ADMSLimits.SURFACE_ALBEDO_DEFAULT, admsOptions.getSurfaceAlbedo(), "SurfaceAlbedo");
assertEquals(ADMSLimits.PRIESTLEY_TAYLOR_PARAMETER_DEFAULT, admsOptions.getPriestleyTaylorParameter(),
"PriestleyTaylorParameter");
assertEquals(0, admsOptions.getMetSiteId(), "MetSiteId");
assertEquals(List.of(), admsOptions.getMetYears(), "MeteoYears");
assertEquals(0.0, admsOptions.getMsRoughness(), "MsRoughness");
assertEquals(0.0, admsOptions.getMsMinMoninObukhovLength(), "MsMinMoninObukhovLength");
assertEquals(0.0, admsOptions.getMsSurfaceAlbedo(), "MsSurfaceAlbedo");
assertEquals(0.0, admsOptions.getMsPriestleyTaylorParameter(), "MsPriestleyTaylorParameter");
assertEquals(false, admsOptions.isPlumeDepletionNH3(), "PlumeDepletionNH3");
assertEquals(false, admsOptions.isPlumeDepletionNOX(), "PlumeDepletionNOX");
assertEquals(true, admsOptions.isSpatiallyVaryingRoughness(), "SpatiallyVaryingRoughness");
assertEquals(false, admsOptions.isComplexTerrain(), "ComplexTerrain");
assertFalse(admsOptions.isPlumeDepletionNH3(), "PlumeDepletionNH3");
assertFalse(admsOptions.isPlumeDepletionNOX(), "PlumeDepletionNOX");
assertTrue(admsOptions.isSpatiallyVaryingRoughness(), "SpatiallyVaryingRoughness");
assertFalse(admsOptions.isComplexTerrain(), "ComplexTerrain");

assertEquals(0.0, options.getCalculateMaximumRange(), "Maximum range read");
}
Expand Down Expand Up @@ -314,21 +315,20 @@ void testReadCalculationSetOptionsWnb() {
assertEquals(CalculationMethod.FORMAL_ASSESSMENT, options.getCalculationMethod(), "Calculation type should match");
final NCACalculationOptions ncaOptions = options.getNcaCalculationOptions();
assertNull(ncaOptions.getPermitArea(), "PermitArea");
assertNull(ncaOptions.getMeteoSiteLocation(), "MeteoSiteLocation");
assertEquals(List.of(), ncaOptions.getMeteoYears(), "MeteoYears");
final ADMSOptions admsOptions = ncaOptions.getAdmsOptions();
assertEquals(0.0, admsOptions.getMinMoninObukhovLength(), "MinMoninObukhovLength");
assertEquals(0.0, admsOptions.getSurfaceAlbedo(), "SurfaceAlbedo");
assertEquals(0.0, admsOptions.getPriestleyTaylorParameter(), "PriestleyTaylorParameter");
assertEquals(0, admsOptions.getMetSiteId(), "MetSiteId");
assertEquals(List.of(), admsOptions.getMetYears(), "MeteoYears");
assertEquals(0.0, admsOptions.getMsRoughness(), "MsRoughness");
assertEquals(0.0, admsOptions.getMsMinMoninObukhovLength(), "MsMinMoninObukhovLength");
assertEquals(0.0, admsOptions.getMsSurfaceAlbedo(), "MsSurfaceAlbedo");
assertEquals(0.0, admsOptions.getMsPriestleyTaylorParameter(), "MsPriestleyTaylorParameter");
assertEquals(false, admsOptions.isPlumeDepletionNH3(), "PlumeDepletionNH3");
assertEquals(false, admsOptions.isPlumeDepletionNOX(), "PlumeDepletionNOX");
assertEquals(false, admsOptions.isSpatiallyVaryingRoughness(), "SpatiallyVaryingRoughness");
assertEquals(false, admsOptions.isComplexTerrain(), "ComplexTerrain");
assertFalse(admsOptions.isPlumeDepletionNH3(), "PlumeDepletionNH3");
assertFalse(admsOptions.isPlumeDepletionNOX(), "PlumeDepletionNOX");
assertFalse(admsOptions.isSpatiallyVaryingRoughness(), "SpatiallyVaryingRoughness");
assertFalse(admsOptions.isComplexTerrain(), "ComplexTerrain");

assertEquals(40.0, options.getCalculateMaximumRange(), "Maximum range read");
}
Expand Down Expand Up @@ -357,10 +357,10 @@ void testReadCalculationSetOptionsUnexpectedValues() {
assertNotNull(options, "returned options shouldn't be null");
final NCACalculationOptions ncaOptions = options.getNcaCalculationOptions();
final ADMSOptions admsOptions = ncaOptions.getAdmsOptions();
assertEquals(false, admsOptions.isPlumeDepletionNH3(), "PlumeDepletionNH3");
assertEquals(false, admsOptions.isPlumeDepletionNOX(), "PlumeDepletionNOX");
assertEquals(false, admsOptions.isSpatiallyVaryingRoughness(), "SpatiallyVaryingRoughness");
assertEquals(false, admsOptions.isComplexTerrain(), "ComplexTerrain");
assertFalse(admsOptions.isPlumeDepletionNH3(), "PlumeDepletionNH3");
assertFalse(admsOptions.isPlumeDepletionNOX(), "PlumeDepletionNOX");
assertFalse(admsOptions.isSpatiallyVaryingRoughness(), "SpatiallyVaryingRoughness");
assertFalse(admsOptions.isComplexTerrain(), "ComplexTerrain");
}

@ParameterizedTest
Expand All @@ -383,7 +383,8 @@ void testReadCalculationSetOptionsUnparseableValues(final String key, final Stri

final GMLCalculationSetOptionsReader reader = new GMLCalculationSetOptionsReader(featureCollection);

assertThrows(expectedException, () -> reader.readCalculationSetOptions(Theme.NCA));
assertThrows(expectedException, () -> reader.readCalculationSetOptions(Theme.NCA),
" Should throw the expected exception because values are not readable.");
}

private static Stream<Arguments> unparseableValues() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,7 @@ public enum CalculationMethod {
/**
* Calculates using less detailed (background) data to get indicative results.
*/
QUICK_RUN,
/**
* Calculates using calculation points and settings established by formal assessment.
*
* @Deprecated Replaced by FORMAL_ASSESSMENT, up for removal.
*/
@Deprecated
PERMIT;
QUICK_RUN;

/**
* Safely returns a CalculationMethod. It is case independent and returns null in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import java.util.HashSet;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonProperty;

import nl.overheid.aerius.shared.domain.Substance;
import nl.overheid.aerius.shared.domain.result.EmissionResultKey;

Expand All @@ -40,7 +38,7 @@ public class CalculationSetOptions implements Serializable {
private boolean useInCombinationArchive;
private final ArrayList<Substance> substances = new ArrayList<>();
private final Set<EmissionResultKey> emissionResultKeys = new HashSet<>();
private WNBCalculationOptions owN2000CalculationOptions = new WNBCalculationOptions();
private OwN2000CalculationOptions owN2000CalculationOptions = new OwN2000CalculationOptions();
private RBLCalculationOptions rblCalculationOptions = new RBLCalculationOptions();
private NCACalculationOptions ncaCalculationOptions = new NCACalculationOptions();
private Serializable experimentalOptions;
Expand Down Expand Up @@ -140,15 +138,6 @@ public OwN2000CalculationOptions getOwN2000CalculationOptions() {
return owN2000CalculationOptions;
}

/**
* @deprecated replace calls with {@link #getOwN2000CalculationOptions()}
*/
@Deprecated
@JsonProperty("owN2000CalculationOptions")
public WNBCalculationOptions getWnbCalculationOptions() {
return owN2000CalculationOptions;
}

public RBLCalculationOptions getRblCalculationOptions() {
return rblCalculationOptions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,38 +75,6 @@ public void setPermitArea(final String permitArea) {
this.permitArea = permitArea;
}

/**
* @Deprecated Use Met information on ADMSOptions instead.
*/
@Deprecated
public String getMeteoSiteLocation() {
return meteoSiteLocation;
}

/**
* @Deprecated Use Met information on ADMSOptions instead.
*/
@Deprecated
public void setMeteoSiteLocation(final String meteoSiteLocation) {
this.meteoSiteLocation = meteoSiteLocation;
}

/**
* @Deprecated Use Met information on ADMSOptions instead.
*/
@Deprecated
public List<String> getMeteoYears() {
return meteoYears;
}

/**
* @Deprecated Use Met information on ADMSOptions instead.
*/
@Deprecated
public void setMeteoYears(final List<String> meteoYears) {
this.meteoYears = meteoYears;
}

public ADMSOptions getAdmsOptions() {
return admsOptions;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,4 @@ public static int getDistanceLevelForCircle(final double radius, final HexagonZo
// sqrt(4/3) would be 1 ( 4 / 3 = 1) however, so use 2/sqrt(3)
return (int) Math.ceil((2 / Math.sqrt(3)) * radius / zoomLevel.getHexagonHeight());
}

/**
* <pre>
* a (radius * 0.5)
* _____
* | /
* | /
* (height/2) b | / c (radius)
* | /
* |/
*
* a = x * 0.5;
* b = half the hexagon height
* c = x
*
* Therefore b = sqrt((halfHeight ^ 2 * 4) / 3)
* </pre>
*
* Model.
*
* @param halfHeight of the hexagon
*
* @return x
*/
public static double convertHalfHeightToRadius(final double halfHeight) {
return Math.sqrt((Math.pow(halfHeight, 2) * 4) / 3);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,6 @@ private static List<File> getFilesInDirectoryWithExtension(final File path, fina
return files;
}

/**
* Get an (Aerius) file name without extension.
* Format: prefix_datestring[_optionalName]
* @param prefix Prefix to use in the filename.
* @param optionalName The optional name to use in the filename.
* @param optionalDate The optional date to use for the datestring. If null, current time will be used.
* @return The file name that can be used without extension.
*/
public static String getFileName(final String prefix, final String optionalName, final Date optionalDate) {
if (prefix == null) {
throw new IllegalArgumentException("Prefix not allowed to be null.");
}
return getActualFileName(prefix, null, optionalName, optionalDate);
}

/**
* Get an (Aerius) file name.
* Format: prefix_datestring[_optionalName][.]extension
Expand Down
Loading

0 comments on commit fbe55ef

Please sign in to comment.