View Javadoc

1   /*
2    * Copyright 2012-2013 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.properties.api.core.domain;
17  
18  import java.io.Serializable;
19  
20  import de.smartics.util.lang.Arg;
21  
22  /**
23   * The name of a document is unique within a documentation in the context of a
24   * given project. The project name together with the document name makes the
25   * document uniquely identifiable.
26   */
27  public final class DocumentName implements Serializable,
28      Comparable<DocumentName>
29  {
30    // ********************************* Fields *********************************
31  
32    // --- constants ------------------------------------------------------------
33  
34    /**
35     * The class version identifier.
36     */
37    private static final long serialVersionUID = 1L;
38  
39    // --- members --------------------------------------------------------------
40  
41    /**
42     * The name identifier of the document.
43     *
44     * @serial
45     */
46    private final String name;
47  
48    // ****************************** Initializer *******************************
49  
50    // ****************************** Constructors ******************************
51  
52    /**
53     * Default constructor.
54     *
55     * @param name the name identifier of the document.
56     * @throws NullPointerException if {@code name} is <code>null</code>.
57     * @throws IllegalArgumentException if {@code name} is blank.
58     */
59    public DocumentName(final String name) throws NullPointerException,
60      IllegalArgumentException
61    {
62      this.name = Arg.checkNotBlank("name", name);
63    }
64  
65    // ****************************** Inner Classes *****************************
66  
67    // ********************************* Methods ********************************
68  
69    // --- init -----------------------------------------------------------------
70  
71    // --- get&set --------------------------------------------------------------
72  
73    // --- business -------------------------------------------------------------
74  
75    /**
76     * Returns the name identifier of the document.
77     *
78     * @return the name identifier of the document.
79     */
80    public String getName()
81    {
82      return name;
83    }
84  
85    // --- object basics --------------------------------------------------------
86  
87    /**
88     * {@inheritDoc}
89     * <p>
90     * Compares the names of the instances.
91     * </p>
92     */
93    @Override
94    public int compareTo(final DocumentName o)
95    {
96      return name.compareTo(o.name);
97    }
98  
99    /**
100    * Returns the hash code of the object.
101    *
102    * @return the hash code.
103    */
104   @Override
105   public int hashCode()
106   {
107     return name.hashCode();
108   }
109 
110   /**
111    * Returns <code>true</code> if the given object is semantically equal to the
112    * given object, <code>false</code> otherwise.
113    * <p>
114    * Two instances are considered equal, if their {@link #getName() name} is
115    * equal.
116    * </p>
117    *
118    * @param object the instance to compare to.
119    * @return <code>true</code> if the given object is semantically equal to the
120    *         given object, <code>false</code> otherwise.
121    */
122   @Override
123   public boolean equals(final Object object)
124   {
125     if (this == object)
126     {
127       return true;
128     }
129     else if (object == null || getClass() != object.getClass())
130     {
131       return false;
132     }
133 
134     final DocumentName other = (DocumentName) object;
135 
136     return (name.equals(other.name));
137   }
138 
139   /**
140    * Returns the string representation of the object.
141    *
142    * @return the string representation of the object.
143    */
144   @Override
145   public String toString()
146   {
147     return name;
148   }
149 }