View Javadoc

1   /*
2    * Copyright 2010-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.testdoc.report.resource;
17  
18  import java.io.Serializable;
19  import java.net.URL;
20  
21  import org.apache.commons.lang.ObjectUtils;
22  import org.apache.commons.lang.StringUtils;
23  
24  import de.smartics.testdoc.core.BlankArgumentException;
25  
26  /**
27   * Descriptor of a category.
28   *
29   * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a>
30   * @version $Revision:591 $
31   */
32  public class CategoryResource implements Serializable
33  {
34    // ********************************* Fields *********************************
35  
36    // --- constants ------------------------------------------------------------
37  
38    /**
39     * The class version identifier.
40     * <p>
41     * The value of this constant is {@value}.
42     */
43    private static final long serialVersionUID = 1L;
44  
45    // --- members --------------------------------------------------------------
46  
47    /**
48     * The label of the category to be displayed.
49     */
50    private final String label;
51  
52    /**
53     * The location of the category icon.
54     */
55    private final URL iconLocation;
56  
57    // ****************************** Initializer *******************************
58  
59    // ****************************** Constructors ******************************
60  
61    /**
62     * Convenience constructor if icon location is <code>null</code>.
63     *
64     * @param label the label of the category to be displayed.
65     * @throws BlankArgumentException if <code>label</code> is blank.
66     */
67    public CategoryResource(final String label)
68    {
69      this(label, null);
70    }
71  
72    /**
73     * Default constructor.
74     *
75     * @param label the label of the category to be displayed.
76     * @param iconLocation the location of the category icon.
77     * @throws BlankArgumentException if <code>label</code> is blank.
78     */
79    public CategoryResource(final String label, final URL iconLocation)
80    {
81      if (StringUtils.isBlank(label))
82      {
83        throw new BlankArgumentException("label");
84      }
85  
86      this.label = label;
87      this.iconLocation = iconLocation;
88    }
89  
90    // ****************************** Inner Classes *****************************
91  
92    // ********************************* Methods ********************************
93  
94    // --- init -----------------------------------------------------------------
95  
96    // --- get&set --------------------------------------------------------------
97  
98    /**
99     * Returns the label of the category to be displayed.
100    *
101    * @return the label of the category to be displayed.
102    */
103   public String getLabel()
104   {
105     return label;
106   }
107 
108   /**
109    * Returns the location of the category icon.
110    *
111    * @return the location of the category icon.
112    */
113   public URL getIconLocation()
114   {
115     return iconLocation;
116   }
117 
118   // --- business -------------------------------------------------------------
119 
120   // --- object basics --------------------------------------------------------
121 
122   /**
123    * Returns the hash code of the object.
124    *
125    * @return the hash code.
126    */
127   @Override
128   public int hashCode()
129   {
130     int result = 17;
131     result = 37 * result + label.hashCode();
132     result = 37 * result + ObjectUtils.hashCode(iconLocation);
133 
134     return result;
135   }
136 
137   /**
138    * Returns <code>true</code> if the given object is semantically equal to the
139    * given object, <code>false</code> otherwise.
140    *
141    * @param object the instance to compare to.
142    * @return <code>true</code> if the given object is semantically equal to the
143    *         given object, <code>false</code> otherwise.
144    */
145   @Override
146   public boolean equals(final Object object)
147   {
148     if (this == object)
149     {
150       return true;
151     }
152     else if (object == null || getClass() != object.getClass())
153     {
154       return false;
155     }
156 
157     final CategoryResource other = (CategoryResource) object;
158 
159     return (label.equals(other.label) && ObjectUtils.equals(iconLocation,
160         other.iconLocation));
161   }
162 
163   /**
164    * Returns the string representation of the object.
165    *
166    * @return the string representation of the object.
167    */
168   @Override
169   public String toString()
170   {
171     return label
172            + (iconLocation != null ? '/' + iconLocation.toExternalForm() : "");
173   }
174 }