View Javadoc

1   /*
2    UnmodifiableDate.java
3    Creation date : 3/06/2011
4    Copyright © Benjamin Croizet (graffity2199@yahoo.fr)
5   
6    This program is free software; you can redistribute it and/or
7    modify it under the terms of the GNU General Public License
8    or GNU Lesser General Public License as published by the
9    Free Software Foundation; either version 3 of the License,
10   or (at your option) any later version.
11  
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16  
17   You should have received copies of the GNU General Public License
18   and GNU Lesser General Public License along with this program;
19   if not, write to the Free Software Foundation, Inc.,
20   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21   http://www.fsf.org/licensing/licenses/gpl.html
22   http://www.gnu.org/licenses/lgpl.html
23   */
24  
25  package net.sourceforge.plantumldependency.common.utils.date;
26  
27  import static net.sourceforge.plantumldependency.common.constants.log.ErrorConstants.IMMUTABLE_DATE_ERROR;
28  import static net.sourceforge.plantumldependency.common.utils.log.LogUtils.buildLogString;
29  
30  import java.util.Date;
31  
32  /**
33   * An immutable version of the {@link Date} class.
34   *
35   * @author Benjamin Croizet (<a href="mailto:graffity2199@yahoo.fr>graffity2199@yahoo.fr</a>)
36   * @since 1.3.0
37   * @version 1.3.0
38   */
39  public class UnmodifiableDate extends Date {
40  
41      /** Serial version UID. */
42      private static final long serialVersionUID = -1580684205510917528L;
43  
44      /**
45       * Default constructor.
46       *
47       * @since 1.3.0
48       */
49      public UnmodifiableDate() {
50          super();
51      }
52  
53      /**
54       * Medium constructor, with a {@link Date} instance.
55       *
56       * @param date
57       *            the original {@link Date} instance to get immutable.
58       * @since 1.3.0
59       */
60      public UnmodifiableDate(final Date date) {
61          super(date.getTime());
62      }
63  
64      /**
65       * Allocates a <code>Date</code> object and initializes it to represent the specified number of
66       * milliseconds since the standard base time known as "the epoch", namely January 1, 1970,
67       * 00:00:00 GMT.
68       *
69       * @param date
70       *            the milliseconds since January 1, 1970, 00:00:00 GMT.
71       * @see java.lang.System#currentTimeMillis()
72       * @since 1.3.0
73       */
74      public UnmodifiableDate(final long date) {
75          super(date);
76      }
77  
78      /**
79       * {@inheritDoc}
80       *
81       * @since 1.3.0
82       */
83      @Override
84      public void setDate(final int date) {
85          throw new IllegalArgumentException(buildLogString(IMMUTABLE_DATE_ERROR, this));
86      }
87  
88      /**
89       * {@inheritDoc}
90       *
91       * @since 1.3.0
92       */
93      @Override
94      public void setHours(final int hours) {
95          throw new IllegalArgumentException(buildLogString(IMMUTABLE_DATE_ERROR, this));
96      }
97  
98      /**
99       * {@inheritDoc}
100      *
101      * @since 1.3.0
102      */
103     @Override
104     public void setMinutes(final int minutes) {
105         throw new IllegalArgumentException(buildLogString(IMMUTABLE_DATE_ERROR, this));
106     }
107 
108     /**
109      * {@inheritDoc}
110      *
111      * @since 1.3.0
112      */
113     @Override
114     public void setMonth(final int month) {
115         throw new IllegalArgumentException(buildLogString(IMMUTABLE_DATE_ERROR, this));
116     }
117 
118     /**
119      * {@inheritDoc}
120      *
121      * @since 1.3.0
122      */
123     @Override
124     public void setSeconds(final int seconds) {
125         throw new IllegalArgumentException(buildLogString(IMMUTABLE_DATE_ERROR, this));
126     }
127 
128     /**
129      * {@inheritDoc}
130      *
131      * @since 1.3.0
132      */
133     @Override
134     public void setTime(final long time) {
135         throw new IllegalArgumentException(buildLogString(IMMUTABLE_DATE_ERROR, this));
136     }
137 
138     /**
139      * {@inheritDoc}
140      *
141      * @since 1.3.0
142      */
143     @Override
144     public void setYear(final int year) {
145         throw new IllegalArgumentException(buildLogString(IMMUTABLE_DATE_ERROR, this));
146     }
147 }