changeset 9214:091fd9676496

Made DateRange class immutable
author gernotbelger
date Tue, 03 Jul 2018 14:26:56 +0200
parents e3d23e1288bb
children 0fc9c82e744e
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/DateRange.java
diffstat 1 files changed, 17 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- 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

http://dive4elements.wald.intevation.org