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.code;
17  
18  /**
19   * This {@link de.smartics.exceptions.core.Code} implementation models the
20   * exception code as a number. It supports a component identifier as an
21   * arbitrary string and provides a facility to specify the number as a major and
22   * a minor number that will be displayed separately.
23   *
24   * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a>
25   * @version $Revision:591 $
26   */
27  public class TwoNumberCodeInfo extends NumberCodeInfo
28  {
29    // ********************************* Fields *********************************
30  
31    // --- constants ------------------------------------------------------------
32  
33    /**
34     * The class version identifier.
35     * <p>
36     * The value of this constant is {@value}.
37     */
38    private static final long serialVersionUID = 1L;
39  
40    // --- members --------------------------------------------------------------
41  
42    // ****************************** Initializer *******************************
43  
44    // ****************************** Constructors ******************************
45  
46    /**
47     * Convenience constructor.
48     *
49     * @param majorNumber the major number of the code defines a group of codes.
50     */
51    public TwoNumberCodeInfo(final Integer majorNumber)
52    {
53      this(null, majorNumber);
54    }
55  
56    /**
57     * Convenience constructor.
58     *
59     * @param componentId the identifier of the component this code belongs to.
60     * @param majorNumber the major number of the code defines a group of codes.
61     */
62    public TwoNumberCodeInfo(final String componentId, final Integer majorNumber)
63    {
64      this(componentId, majorNumber, null);
65    }
66  
67    /**
68     * Default constructor.
69     *
70     * @param componentId the identifier of the component this code belongs to.
71     * @param majorNumber the major number of the code defines a group of codes.
72     * @param minorNumber the minor number gives additional information about the
73     *          problem.
74     * @throws NullPointerException if the major number is <code>null</code>.
75     */
76    public TwoNumberCodeInfo(final String componentId, final Integer majorNumber,
77        final Integer minorNumber) throws NullPointerException
78    {
79      super(componentId, majorNumber, minorNumber);
80    }
81  
82    // ****************************** Inner Classes *****************************
83  
84    // ********************************* Methods ********************************
85  
86    // --- init -----------------------------------------------------------------
87  
88    // --- get&set --------------------------------------------------------------
89  
90    // --- business -------------------------------------------------------------
91  
92    /**
93     * {@inheritDoc}
94     */
95    @Override
96    public String getCode()
97    {
98      final StringBuilder buffer = new StringBuilder();
99      buffer.append(majorNumber);
100     if (minorNumber != null)
101     {
102       buffer.append('-').append(minorNumber);
103     }
104     return buffer.toString();
105   }
106 
107   /**
108    * {@inheritDoc}
109    *
110    * @see de.smartics.exceptions.core.Code#getDisplayId()
111    */
112   @Override
113   public String getDisplayId()
114   {
115     final StringBuilder buffer = new StringBuilder();
116 
117     if (componentId != null)
118     {
119       buffer.append(componentId).append('-');
120     }
121     buffer.append(getCode());
122 
123     return buffer.toString();
124   }
125 
126   // --- object basics --------------------------------------------------------
127 }