1 /* 2 * Copyright 2007-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.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 public class TwoNumberCodeInfo extends NumberCodeInfo 25 { 26 // ********************************* Fields ********************************* 27 28 // --- constants ------------------------------------------------------------ 29 30 /** 31 * The class version identifier. 32 * <p> 33 * The value of this constant is {@value}. 34 * </p> 35 */ 36 private static final long serialVersionUID = 1L; 37 38 // --- members -------------------------------------------------------------- 39 40 // ****************************** Initializer ******************************* 41 42 // ****************************** Constructors ****************************** 43 44 /** 45 * Convenience constructor. 46 * 47 * @param majorNumber the major number of the code defines a group of codes. 48 */ 49 public TwoNumberCodeInfo(final Integer majorNumber) 50 { 51 this(null, majorNumber); 52 } 53 54 /** 55 * Convenience constructor. 56 * 57 * @param componentId the identifier of the component this code belongs to. 58 * @param majorNumber the major number of the code defines a group of codes. 59 */ 60 public TwoNumberCodeInfo(final String componentId, final Integer majorNumber) 61 { 62 this(componentId, majorNumber, null); 63 } 64 65 /** 66 * Default constructor. 67 * 68 * @param componentId the identifier of the component this code belongs to. 69 * @param majorNumber the major number of the code defines a group of codes. 70 * @param minorNumber the minor number gives additional information about the 71 * problem. 72 * @throws NullPointerException if the major number is <code>null</code>. 73 */ 74 public TwoNumberCodeInfo(final String componentId, final Integer majorNumber, 75 final Integer minorNumber) throws NullPointerException 76 { 77 super(componentId, majorNumber, minorNumber); 78 } 79 80 // ****************************** Inner Classes ***************************** 81 82 // ********************************* Methods ******************************** 83 84 // --- init ----------------------------------------------------------------- 85 86 // --- get&set -------------------------------------------------------------- 87 88 // --- business ------------------------------------------------------------- 89 90 @Override 91 public String getCode() 92 { 93 final StringBuilder buffer = new StringBuilder(); 94 buffer.append(majorNumber); 95 if (minorNumber != null) 96 { 97 buffer.append('-').append(minorNumber); 98 } 99 return buffer.toString(); 100 } 101 102 @Override 103 public String getDisplayId() 104 { 105 final StringBuilder buffer = new StringBuilder(); 106 107 if (componentId != null) 108 { 109 buffer.append(componentId).append('-'); 110 } 111 buffer.append(getCode()); 112 113 return buffer.toString(); 114 } 115 116 // --- object basics -------------------------------------------------------- 117 }