View Javadoc

1   /*
2    * Copyright 2006-2012 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.maven.util.report.link;
17  
18  import java.io.Serializable;
19  
20  import org.apache.commons.lang.StringUtils;
21  
22  /**
23   * Identifies a specific report of a project to reference to.
24   *
25   * @todo check serial tampering
26   */
27  public class ReportId implements Serializable
28  {
29    // ********************************* Fields *********************************
30  
31    // --- constants ------------------------------------------------------------
32  
33    /**
34     * The class version identifier.
35     * <p>
36     * The value of this constant is {@value}.
37     * </p>
38     */
39    private static final long serialVersionUID = 1L;
40  
41    /**
42     * Defines the type for normal reports.
43     * <p>
44     * The value of this constant is {@value}.
45     * </p>
46     */
47    public static final String NORMAL_REPORT = "normal";
48  
49    /**
50     * Defines the type for test reports.
51     * <p>
52     * The value of this constant is {@value}.
53     * </p>
54     */
55    public static final String TEST_REPORT = "test";
56  
57    // --- members --------------------------------------------------------------
58  
59    /**
60     * The report artifact ID this strategy is constructed for.
61     *
62     * @serial
63     */
64    private final String reportArtifactId;
65  
66    /**
67     * The type of report generated by the {@link #getReportArtifactId()} to
68     * reference. Typically there can be two kinds of reports: one on the
69     * production and one on the test code.
70     *
71     * @serial
72     */
73    private final String reportType;
74  
75    // ****************************** Initializer *******************************
76  
77    // ****************************** Constructors ******************************
78  
79    /**
80     * Default constructor.
81     *
82     * @param reportArtifactId the report artifact ID this strategy is constructed
83     *          for.
84     * @param reportType the type of report generated by the
85     *          {@link #getReportArtifactId()} to reference.
86     */
87    public ReportId(final String reportArtifactId, final String reportType)
88    {
89      checkArguments(reportArtifactId, reportType);
90      this.reportArtifactId = reportArtifactId;
91      this.reportType = reportType;
92    }
93  
94    private static void checkArguments(final String reportArtifactId,
95        final String reportType)
96    {
97      if (StringUtils.isBlank(reportArtifactId))
98      {
99        throw new IllegalArgumentException(
100           "The artifact ID of the report must not be blank.");
101     }
102     if (StringUtils.isBlank(reportType))
103     {
104       throw new IllegalArgumentException(
105           "The type of the report must not be blank.");
106     }
107   }
108 
109   // ****************************** Inner Classes *****************************
110 
111   // ********************************* Methods ********************************
112 
113   // --- init -----------------------------------------------------------------
114 
115   // --- get&set --------------------------------------------------------------
116 
117   /**
118    * Returns the report artifact ID this strategy is constructed for.
119    *
120    * @return the report artifact ID this strategy is constructed for.
121    */
122   public String getReportArtifactId()
123   {
124     return reportArtifactId;
125   }
126 
127   /**
128    * Returns the type of report generated by the {@link #getReportArtifactId()}
129    * to reference. Typically there can be two kinds of reports: one on the
130    * production and one on the test code.
131    *
132    * @return the type of report generated by the {@link #getReportArtifactId()}
133    *         to reference.
134    */
135   public String getReportType()
136   {
137     return reportType;
138   }
139 
140   // --- business -------------------------------------------------------------
141 
142   /**
143    * Returns the hash code of the object.
144    *
145    * @return the hash code.
146    */
147   @Override
148   public int hashCode()
149   {
150     int result = 17;
151     result = 37 * result + reportArtifactId.hashCode();
152     result = 37 * result + reportType.hashCode();
153 
154     return result;
155   }
156 
157   /**
158    * Returns <code>true</code> if the given object is semantically equal to the
159    * given object, <code>false</code> otherwise.
160    *
161    * @param object the instance to compare to.
162    * @return <code>true</code> if the given object is semantically equal to the
163    *         given object, <code>false</code> otherwise.
164    */
165   @Override
166   public boolean equals(final Object object)
167   {
168     if (this == object)
169     {
170       return true;
171     }
172     else if (object == null || getClass() != object.getClass())
173     {
174       return false;
175     }
176 
177     final ReportId other = (ReportId) object;
178 
179     return (reportArtifactId.equals(other.reportArtifactId) && reportType
180         .equals(other.reportType));
181   }
182 
183   // --- object basics --------------------------------------------------------
184 
185   /**
186    * Returns the string representation of the object.
187    *
188    * @return the string representation of the object.
189    */
190   @Override
191   public String toString()
192   {
193     final StringBuilder buffer = new StringBuilder();
194     buffer.append(reportArtifactId).append('/').append(reportType);
195     return buffer.toString();
196   }
197 }