[PATCH] Made DateRange class immutable
Wald Commits
scm-commit at wald.intevation.org
Tue Jul 3 14:27:00 CEST 2018
# HG changeset patch
# User gernotbelger
# Date 1530620816 -7200
# Node ID 091fd9676496aa63ea4b5723d191f124336432c7
# Parent e3d23e1288bbc2e7bf57eb2cb8ccffe4dba2256b
Made DateRange class immutable
diff -r e3d23e1288bb -r 091fd9676496 artifacts/src/main/java/org/dive4elements/river/artifacts/model/DateRange.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/DateRange.java Tue Jul 03 13:35:36 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/DateRange.java Tue Jul 03 14:26:56 2018 +0200
@@ -13,48 +13,44 @@
import org.dive4elements.artifacts.common.utils.DateUtils;
-public class DateRange
-implements Serializable
-{
+public class DateRange implements Serializable {
private static final long serialVersionUID = -2553914795388094818L;
- protected Date from;
- protected Date to;
+ private final Date from;
+ private final Date to;
public DateRange(final Date from, final Date to) {
this.from = from;
- this.to = to;
+ this.to = to;
}
public Date getFrom() {
return this.from;
}
- public void setFrom(final Date from) {
- this.from = from;
- }
-
public Date getTo() {
return this.to;
}
- public void setTo(final Date to) {
- this.to = to;
- }
+ private static final boolean equalDates(final Date a, final Date b) {
+ if (a == null && b != null)
+ return false;
- private static final boolean equalDates(final Date a, final Date b) {
- if (a == null && b != null) return false;
- if (a != null && b == null) return false;
- if (a == null) return true;
+ if (a != null && b == null)
+ return false;
+
+ if (a == null)
+ return true;
+
return a.equals(b);
}
@Override
public boolean equals(final Object other) {
- if (!(other instanceof DateRange)) {
+ if (!(other instanceof DateRange))
return false;
- }
- final DateRange o = (DateRange)other;
+
+ final DateRange o = (DateRange) other;
return equalDates(this.from, o.from) && equalDates(this.to, o.to);
}
@@ -65,5 +61,4 @@
public int getToYear() {
return DateUtils.getYearFromDate(this.to);
}
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+}
\ No newline at end of file
More information about the Dive4Elements-commits
mailing list