Skip to content

Commit

Permalink
Cleanup of code, removed unsused/deprecated code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilbrand committed Sep 9, 2024
1 parent 984f259 commit 2936cc7
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 136 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 @@ -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
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* Test class for {@link ImaerFileUtil}.
*/
public class ImaerFileUtilTest {
class ImaerFileUtilTest {

private static final String TEST_FILE_NAME = "someFile";
private static final String TEST_FILE_NAME_WITH_SPACES = "some Fil e ";
Expand Down Expand Up @@ -61,7 +61,7 @@ public boolean accept(final File dir, final String name) {
}

@Test
public void testGetSafeFilename() {
void testGetSafeFilename() {
String fileName = ImaerFileUtil.getSafeFilename(null);
assertNull(fileName, "Supplying null should return null");
fileName = ImaerFileUtil.getSafeFilename("");
Expand All @@ -73,7 +73,7 @@ public void testGetSafeFilename() {
}

@Test
public void testGetFileName() {
void testGetFileName() {
String fileName = ImaerFileUtil.getFileName(TEST_FILE_PREFIX, TEST_FILE_NAME_EXTENSION, null, null);
assertNotNull(fileName, "filename returned shouldn't be null");
assertTrue(fileName.startsWith(TEST_FILE_PREFIX), "filename should start with prefix. " + fileName);
Expand All @@ -92,31 +92,23 @@ public void testGetFileName() {
}

@Test
public void testGetFileNameWithoutExtendsionNullPrefix() {
assertThrows(
IllegalArgumentException.class,
() -> ImaerFileUtil.getFileName(null, null, null),
"Expected IllegalArgumentException");
}

@Test
public void testGetFileNameNullPrefix() {
void testGetFileNameNullPrefix() {
assertThrows(
IllegalArgumentException.class,
() -> ImaerFileUtil.getFileName(null, TEST_FILE_NAME_EXTENSION, null, null),
"Expected IllegalArgumentException");
}

@Test
public void testGetFileNameNullExtension() {
void testGetFileNameNullExtension() {
assertThrows(
IllegalArgumentException.class,
() -> ImaerFileUtil.getFileName(TEST_FILE_NAME, null, null, null),
"Expected IllegalArgumentException");
}

@Test
public void testGetFileNameOptional() {
void testGetFileNameOptional() {
String longFileName = TEST_LONG_FILE_NAME;
while (longFileName.length() < ImaerFileUtil.MAX_OPTIONAL_FILENAME_LENGTH) {
longFileName += TEST_LONG_FILE_NAME;
Expand All @@ -127,13 +119,4 @@ public void testGetFileNameOptional() {
assertFalse(fileName.contains(longFileName.substring(0, ImaerFileUtil.MAX_OPTIONAL_FILENAME_LENGTH + 1)),
"filename shouldn't contain more than the first X letters of the optional name. " + fileName);
}

@Test
public void testGetFileNameEmpty() {
final String fileName = ImaerFileUtil.getFileName(TEST_FILE_PREFIX, null, null);
assertNotNull(fileName, "filename returned shouldn't be null");
assertTrue(fileName.startsWith(TEST_FILE_PREFIX), "filename should start with prefix. " + fileName);
assertFalse(fileName.endsWith("."), "filename should end with extension. " + fileName);
}

}

0 comments on commit 2936cc7

Please sign in to comment.