From 0077b86fefc65331d43c2f6cc27e5ee4a7c4253d Mon Sep 17 00:00:00 2001 From: Nikolaus Krismer <nikolaus.krismer@uibk.ac.at> Date: Sun, 1 Oct 2017 12:51:34 +0200 Subject: [PATCH] fixed checkstyle warnings --- CHANGELOG.md | 1 + .../inf/isochrone/config/ConfigDataset.java | 53 +++++++++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58539325..1c595088 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ Upcoming version: ----------------- + - fixed checkstyle warnings (Nikolaus Krismer) - minor interface improvements (Nikolaus Krismer) - fixed typo in variable name (Nikolaus Krismer) - calling algorithms clear method explicitly to free memory earlier (Nikolaus Krismer) diff --git a/src/main/java/it/unibz/inf/isochrone/config/ConfigDataset.java b/src/main/java/it/unibz/inf/isochrone/config/ConfigDataset.java index 11391a3a..9b10e5a7 100644 --- a/src/main/java/it/unibz/inf/isochrone/config/ConfigDataset.java +++ b/src/main/java/it/unibz/inf/isochrone/config/ConfigDataset.java @@ -44,6 +44,7 @@ import it.unibz.inf.isochrone.db.DbUtils; /** * Configuration for individual datasets. + * A configuration is solely identified by its name (field datasetName). * * @author <a href="mailto:nikolaus.krismer@uibk.ac.at">Nikolaus Krismer</a> */ @@ -275,6 +276,7 @@ public class ConfigDataset implements Comparable<ConfigDataset> { private boolean calendarDates; private LocalDate[] calendarValidity; + @NotNull private String datasetName; private String geoType; private boolean density; @@ -316,13 +318,21 @@ public class ConfigDataset implements Comparable<ConfigDataset> { * @return the initialized dataset configuration */ public static ConfigDataset getInstance(final String datasetName, final boolean alsoSynthetic) { - if (!isAvailable(datasetName) && !alsoSynthetic) { + if (datasetName == null) { + throw new NullPointerException("DatasetName is not allowed to be null!"); + } + final String dsName = datasetName.trim(); + if (dsName.isEmpty()) { + throw new IllegalArgumentException("Empty dataset name is not allowed!"); + } + + if (!isAvailable(dsName) && !alsoSynthetic) { return null; } - ConfigDataset ds = CACHE_INSTANCE.get(datasetName); + ConfigDataset ds = CACHE_INSTANCE.get(dsName); if (ds == null) { - ds = createInstance(datasetName); + ds = createInstance(dsName); } return ds; @@ -568,11 +578,46 @@ public class ConfigDataset implements Comparable<ConfigDataset> { @Override public int compareTo(final ConfigDataset o) { final String n0 = getDatasetName(); - final String n1 = (o == null) ? null : o.getDatasetName(); + final String n1 = (o == null) ? "" : o.getDatasetName(); return n0.compareTo(n1); } + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + final ConfigDataset other = (ConfigDataset) obj; + if (datasetName == null) { + if (other.datasetName != null) { + return false; + } + } else if (!datasetName.equals(other.datasetName)) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + // CHECKSTYLE:OFF MagicNumber + final int prime = 31; + int result = 1; + result = prime * result + ((datasetName == null) ? 0 : datasetName.hashCode()); + // CHECKSTYLE:ON MagicNumber + + return result; + } + @Override public String toString() { return "ConfigDataset [datasetName=" + datasetName + ", serverSRID=" + serverSRID + ", 3D=" + threeD + "]"; -- GitLab