View Javadoc

1   /*
2    * Copyright 2007-2011 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.exceptions.id;
17  
18  import de.smartics.exceptions.core.ExceptionId;
19  
20  /**
21   * An implementation where the exception identifier is modeled as a long value.
22   *
23   * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a>
24   * @version $Revision$
25   */
26  public class LongExceptionId implements ExceptionId<Long>
27  {
28    // ********************************* Fields *********************************
29  
30    // --- constants ------------------------------------------------------------
31  
32    /**
33     * The class version identifier.
34     */
35    private static final long serialVersionUID = 1L;
36  
37    // --- members --------------------------------------------------------------
38  
39    /**
40     * The implementing identifier.
41     *
42     * @serial
43     */
44    private final Long id;
45  
46    // ****************************** Initializer *******************************
47  
48    // ****************************** Constructors ******************************
49  
50    /**
51     * Default constructor that creates the identifier instance.
52     *
53     * @param id the value of the unique identifier.
54     */
55    public LongExceptionId(final long id)
56    {
57      this.id = Long.valueOf(id);
58    }
59  
60    // ****************************** Inner Classes *****************************
61  
62    // ********************************* Methods ********************************
63  
64    // --- init -----------------------------------------------------------------
65  
66    // --- get&set --------------------------------------------------------------
67  
68    /**
69     * {@inheritDoc}
70     *
71     * @see de.smartics.exceptions.core.ExceptionId#getId()
72     */
73    public Long getId()
74    {
75      return id;
76    }
77  
78    // --- business -------------------------------------------------------------
79  
80    // --- object basics --------------------------------------------------------
81  
82    /**
83     * Returns <code>true</code> if the given object is semantically equal to the
84     * given object, <code>false</code> otherwise.
85     * <p>
86     * Two instances o this class are equal if they have the same identifier.
87     *
88     * @param object the instance to compare to.
89     * @return <code>true</code> if the given object is semantically equal to the
90     *         given object, <code>false</code> otherwise.
91     */
92    public boolean equals(final Object object)
93    {
94      if (this == object)
95      {
96        return true;
97      }
98      else if (object == null || getClass() != object.getClass())
99      {
100       return false;
101     }
102 
103     final LongExceptionId other = (LongExceptionId) object;
104 
105     return id.equals(other.id);
106   }
107 
108   /**
109    * Returns the hashcode of the object.
110    * <p>
111    * It is the hashcode of the UUID instance.
112    *
113    * @return the hash code.
114    */
115   public int hashCode()
116   {
117     return id.hashCode();
118   }
119 
120   /**
121    * Returns the UUID as a string.
122    *
123    * @return the UUID as a string.
124    * @see java.lang.Object#toString()
125    */
126   @Override
127   public String toString()
128   {
129     return id.toString();
130   }
131 }