Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/DateRange.java @ 9155:9b4f5e61c02e
Changed to list of DateRange, added methods in DateRange to support year ranges
author | mschaefer |
---|---|
date | Tue, 19 Jun 2018 14:15:32 +0200 |
parents | af13ceeba52a |
children | 091fd9676496 |
comparison
equal
deleted
inserted
replaced
9154:cd24db77f044 | 9155:9b4f5e61c02e |
---|---|
9 package org.dive4elements.river.artifacts.model; | 9 package org.dive4elements.river.artifacts.model; |
10 | 10 |
11 import java.io.Serializable; | 11 import java.io.Serializable; |
12 import java.util.Date; | 12 import java.util.Date; |
13 | 13 |
14 import org.dive4elements.artifacts.common.utils.DateUtils; | |
15 | |
14 public class DateRange | 16 public class DateRange |
15 implements Serializable | 17 implements Serializable |
16 { | 18 { |
17 private static final long serialVersionUID = -2553914795388094818L; | 19 private static final long serialVersionUID = -2553914795388094818L; |
18 | 20 |
19 protected Date from; | 21 protected Date from; |
20 protected Date to; | 22 protected Date to; |
21 | 23 |
22 public DateRange(Date from, Date to) { | 24 public DateRange(final Date from, final Date to) { |
23 this.from = from; | 25 this.from = from; |
24 this.to = to; | 26 this.to = to; |
25 } | 27 } |
26 | 28 |
27 public Date getFrom() { | 29 public Date getFrom() { |
28 return from; | 30 return this.from; |
29 } | 31 } |
30 | 32 |
31 public void setFrom(Date from) { | 33 public void setFrom(final Date from) { |
32 this.from = from; | 34 this.from = from; |
33 } | 35 } |
34 | 36 |
35 public Date getTo() { | 37 public Date getTo() { |
36 return to; | 38 return this.to; |
37 } | 39 } |
38 | 40 |
39 public void setTo(Date to) { | 41 public void setTo(final Date to) { |
40 this.to = to; | 42 this.to = to; |
41 } | 43 } |
42 | 44 |
43 private static final boolean equalDates(Date a, Date b) { | 45 private static final boolean equalDates(final Date a, final Date b) { |
44 if (a == null && b != null) return false; | 46 if (a == null && b != null) return false; |
45 if (a != null && b == null) return false; | 47 if (a != null && b == null) return false; |
46 if (a == null) return true; | 48 if (a == null) return true; |
47 return a.equals(b); | 49 return a.equals(b); |
48 } | 50 } |
49 | 51 |
50 @Override | 52 @Override |
51 public boolean equals(Object other) { | 53 public boolean equals(final Object other) { |
52 if (!(other instanceof DateRange)) { | 54 if (!(other instanceof DateRange)) { |
53 return false; | 55 return false; |
54 } | 56 } |
55 DateRange o = (DateRange)other; | 57 final DateRange o = (DateRange)other; |
56 return equalDates(from, o.from) && equalDates(to, o.to); | 58 return equalDates(this.from, o.from) && equalDates(this.to, o.to); |
59 } | |
60 | |
61 public int getFromYear() { | |
62 return DateUtils.getYearFromDate(this.from); | |
63 } | |
64 | |
65 public int getToYear() { | |
66 return DateUtils.getYearFromDate(this.to); | |
57 } | 67 } |
58 } | 68 } |
59 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 69 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |