001 // SECTION-START[License Header]
002 // <editor-fold defaultstate="collapsed" desc=" Generated License ">
003 /*
004 * Copyright (c) 2010 The JOMC Project
005 * Copyright (c) 2005 Christian Schulte <schulte2005@users.sourceforge.net>
006 * All rights reserved.
007 *
008 * Redistribution and use in source and binary forms, with or without
009 * modification, are permitted provided that the following conditions
010 * are met:
011 *
012 * o Redistributions of source code must retain the above copyright
013 * notice, this list of conditions and the following disclaimer.
014 *
015 * o Redistributions in binary form must reproduce the above copyright
016 * notice, this list of conditions and the following disclaimer in
017 * the documentation and/or other materials provided with the
018 * distribution.
019 *
020 * THIS SOFTWARE IS PROVIDED BY THE JOMC PROJECT AND CONTRIBUTORS "AS IS"
021 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
022 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
023 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JOMC PROJECT OR
024 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
027 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
028 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
029 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
030 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031 *
032 * $Id: Sequence.java 2244 2010-06-29 07:58:09Z schulte2005 $
033 *
034 */
035 // </editor-fold>
036 // SECTION-END
037 package org.jomc.sequences;
038
039 import java.io.Serializable;
040 import java.util.Date;
041
042 // SECTION-START[Documentation]
043 // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
044 /**
045 * Sequence of numbers.
046 *
047 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0
048 * @version $Id: Sequence.java 2244 2010-06-29 07:58:09Z schulte2005 $
049 */
050 // </editor-fold>
051 // SECTION-END
052 // SECTION-START[Annotations]
053 // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
054 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
055 // </editor-fold>
056 // SECTION-END
057 public class Sequence implements Comparable<Sequence>, Cloneable, Serializable
058 {
059 // SECTION-START[Sequence]
060
061 /** Constant for the name of property {@code name}. */
062 public static final String PROP_NAME = "org.jomc.sequences.Sequence.PROP_NAME";
063
064 /** Constant for the name of property {@code minimum}. */
065 public static final String PROP_MINIMUM = "org.jomc.sequences.Sequence.PROP_MINIMUM";
066
067 /** Constant for the name of property {@code maximum}. */
068 public static final String PROP_MAXIMUM = "org.jomc.sequences.Sequence.PROP_MAXIMUM";
069
070 /** Constant for the name of property {@code increment}. */
071 public static final String PROP_INCREMENT = "org.jomc.sequences.Sequence.PROP_INCREMENT";
072
073 /** Constant for the name of property {@code value}. */
074 public static final String PROP_VALUE = "org.jomc.sequences.Sequence.PROP_VALUE";
075
076 /** Serial version UID for backwards compatibility with 1.0.x classes. */
077 private static final long serialVersionUID = 4782576402999874315L;
078
079 /**
080 * Revision of the sequence.
081 * @serial
082 */
083 private long revision;
084
085 /**
086 * Date of the revision.
087 * @serial
088 */
089 private long date;
090
091 /**
092 * Logical name of the sequence.
093 * @serial
094 */
095 private String name;
096
097 /**
098 * Minimum value of property {@code value}.
099 * @serial
100 */
101 private long minimum;
102
103 /**
104 * Maximum value of property {@code value}.
105 * @serial
106 */
107 private long maximum;
108
109 /**
110 * Delta to add to the value of property {@code value} for the next value in the sequence.
111 * @serial
112 */
113 private long increment;
114
115 /**
116 * Current value of the sequence.
117 * @serial
118 */
119 private long value;
120
121 /**
122 * Gets the revision of the entity.
123 *
124 * @return The revision of the entity.
125 */
126 public long getRevision()
127 {
128 return this.revision;
129 }
130
131 /**
132 * Gets the date of the revision of the entity.
133 *
134 * @return The date of the revision of the entity.
135 */
136 public long getDate()
137 {
138 return this.date;
139 }
140
141 /**
142 * Gets the logical name of the sequence.
143 *
144 * @return The logical name of the sequence.
145 */
146 public String getName()
147 {
148 return this.name;
149 }
150
151 /**
152 * Sets the logical name of the sequence.
153 *
154 * @param value The new logical name of the sequence.
155 */
156 public void setName( final String value )
157 {
158 this.name = value;
159 }
160
161 /**
162 * Gets the minimum value of property {@code value}.
163 *
164 * @return The minimum value of property {@code value}.
165 */
166 public long getMinimum()
167 {
168 return this.minimum;
169 }
170
171 /**
172 * Sets the minimum value of property {@code value}.
173 *
174 * @param value The new minimum value of property {@code value}.
175 */
176 public void setMinimum( final long value )
177 {
178 this.minimum = value;
179 }
180
181 /**
182 * Gets the maximum value of property {@code value}.
183 *
184 * @return The maximum value of property {@code value}.
185 */
186 public long getMaximum()
187 {
188 return this.maximum;
189 }
190
191 /**
192 * Sets the maximum value of property {@code value}.
193 *
194 * @param value The new maximum value of property {@code value}.
195 */
196 public void setMaximum( final long value )
197 {
198 this.maximum = value;
199 }
200
201 /**
202 * Gets the delta to add to the value of property {@code value} for the next value in the sequence.
203 *
204 * @return The the delta to add to the value of property {@code value} for the next value in the sequence.
205 */
206 public long getIncrement()
207 {
208 return this.increment;
209 }
210
211 /**
212 * Sets the delta to add to the value of property {@code value} for the next value in the sequence.
213 *
214 * @param value The new delta to add to the value of property {@code value} for the next value in the sequence.
215 */
216 public void setIncrement( final long value )
217 {
218 this.increment = value;
219 }
220
221 /**
222 * Gets the current value of the sequence.
223 *
224 * @return The current value of the sequence.
225 */
226 public long getValue()
227 {
228 return this.value;
229 }
230
231 /**
232 * Sets the current value of the sequence.
233 *
234 * @param value The current value of the sequence.
235 */
236 public void setValue( final long value )
237 {
238 this.value = value;
239 }
240
241 /**
242 * Creates a string representing the properties of the instance.
243 *
244 * @return A string representing the properties of the instance.
245 */
246 private String internalString()
247 {
248 return new StringBuffer( 150 ).append( '{' ).
249 append( "revision=" ).append( this.revision ).
250 append( ", date=" ).append( new Date( this.date ) ).
251 append( ", name=" ).append( this.name ).
252 append( ", minimum=" ).append( this.minimum ).
253 append( ", maximum=" ).append( this.maximum ).
254 append( ", increment=" ).append( this.increment ).
255 append( ", value=" ).append( this.value ).
256 append( '}' ).toString();
257
258 }
259
260 /**
261 * Compares this sequence with the specified sequence for order.
262 * <p>Returns a negative integer, zero, or a positive integer as this sequence is less than, equal to, or greater
263 * than the specified sequence.</p>
264 * <p><b>Note:</b><br/>This class has a natural ordering that is inconsistent with equals.</p>
265 *
266 * @param s The sequence to be compared.
267 *
268 * @return A negative integer, zero, or a positive integer as this sequence is less than, equal to, or greater than
269 * the specified sequence.
270 */
271 public int compareTo( final Sequence s )
272 {
273 int result = s == null ? 1 : 0;
274
275 if ( result == 0 )
276 {
277 if ( this.getName() == null )
278 {
279 result = s.getName() == null ? 0 : -1;
280 }
281 else
282 {
283 result = s.getName() == null ? 1 : this.getName().compareTo( s.getName() );
284 }
285 }
286
287 return result;
288 }
289
290 /**
291 * Creates and returns a copy of this object.
292 *
293 * @return A clone of this instance.
294 */
295 @Override
296 public Sequence clone()
297 {
298 try
299 {
300 return (Sequence) super.clone();
301 }
302 catch ( final CloneNotSupportedException e )
303 {
304 throw new AssertionError( e );
305 }
306 }
307
308 /**
309 * Indicates whether some other object is equal to this one by comparing the values of properties {@code name} and
310 * {@code revision}.
311 *
312 * @param o The reference object with which to compare.
313 *
314 * @return {@code true} if this object is the same as {@code o}; {@code false} otherwise.
315 */
316 @Override
317 public boolean equals( final Object o )
318 {
319 boolean ret = o == this;
320
321 if ( !ret && o instanceof Sequence )
322 {
323 final Sequence that = (Sequence) o;
324 ret = ( this.getName() == null ? that.getName() == null : this.getName().equals( that.getName() ) ) &&
325 ( this.getRevision() == that.getRevision() );
326
327 }
328
329 return ret;
330 }
331
332 /**
333 * Returns a hash code value for this object.
334 *
335 * @return A hash code value for this object.
336 */
337 @Override
338 public int hashCode()
339 {
340 int hc = 23;
341 hc = 37 * hc + ( this.getName() == null ? 0 : this.getName().hashCode() );
342 hc = 37 * hc + (int) ( this.getRevision() ^ ( this.getRevision() >>> 32 ) );
343 return hc;
344 }
345
346 /**
347 * Returns a string representation of the object.
348 *
349 * @return A string representation of the object.
350 */
351 @Override
352 public String toString()
353 {
354 return super.toString() + this.internalString();
355 }
356
357 // SECTION-END
358 // SECTION-START[Constructors]
359 // <editor-fold defaultstate="collapsed" desc=" Generated Constructors ">
360
361 /** Creates a new {@code Sequence} instance. */
362 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
363 public Sequence()
364 {
365 // SECTION-START[Default Constructor]
366 super();
367 // SECTION-END
368 }
369 // </editor-fold>
370 // SECTION-END
371 // SECTION-START[Dependencies]
372 // SECTION-END
373 // SECTION-START[Properties]
374 // SECTION-END
375 // SECTION-START[Messages]
376 // SECTION-END
377 }