View Javadoc
1   /*
2     (C) Copyright IBM Corp. 2006, 2013
3   
4     THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
5     ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
6     CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
7   
8     You can obtain a current copy of the Eclipse Public License from
9     http://www.opensource.org/licenses/eclipse-1.0.php
10  
11    @author : Endre Bak, ebak@de.ibm.com
12   * 
13   * Flag       Date        Prog         Description
14   * -------------------------------------------------------------------------------
15   * 1565892    2006-10-09  ebak         Make SBLIM client JSR48 compliant
16   * 1737123    2007-06-15  ebak         Differences to JSR48 public review draft
17   * 2003590    2008-06-30  blaschke-oss Change licensing from CPL to EPL
18   * 2524131    2009-01-21  raman_arora  Upgrade client to JDK 1.5 (Phase 1)
19   * 2531371    2009-02-10  raman_arora  Upgrade client to JDK 1.5 (Phase 2)
20   * 2750520    2009-04-10  blaschke-oss Code cleanup from empty statement et al
21   * 2795671    2009-05-22  raman_arora  Add Type to Comparable <T>
22   * 2935258    2010-01-22  blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0
23   * 2944833    2010-02-08  blaschke-oss Need private setValue in UnsignedInteger8
24   * 2973233    2010-03-19  blaschke-oss TCK: UnsignedIntegerNN.hashCode() not working
25   *    2719    2013-12-10  blaschke-oss TCK: CIM APIs should not generate NullPointerException
26   *    2716    2013-12-11  blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V
27   */
28  
29  package org.metricshub.wbem.javax.cim;
30  
31  /*-
32   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
33   * WBEM Java Client
34   * ჻჻჻჻჻჻
35   * Copyright 2023 - 2025 MetricsHub
36   * ჻჻჻჻჻჻
37   * Licensed under the Apache License, Version 2.0 (the "License");
38   * you may not use this file except in compliance with the License.
39   * You may obtain a copy of the License at
40   *
41   *      http://www.apache.org/licenses/LICENSE-2.0
42   *
43   * Unless required by applicable law or agreed to in writing, software
44   * distributed under the License is distributed on an "AS IS" BASIS,
45   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
46   * See the License for the specific language governing permissions and
47   * limitations under the License.
48   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
49   */
50  
51  //Sync'd against JSR48 1.0.0 javadoc (version 1.7.0_03) on Tue Dec 10 07:02:50 EST 2013
52  /**
53   * This class represents an <code>UnsignedInteger8</code>. A <code>uint8</code>
54   * data type is defined by the (<a href=http://www.dmtf.org>DMTF</a>) CIM
55   * Infrastructure Specification (<a
56   * href=http://www.dmtf.org/standards/published_documents/DSP0004V2.3_final.pdf
57   * >DSP004</a>).
58   */
59  public class UnsignedInteger8 extends Number implements Comparable<UnsignedInteger8> {
60  	private static final long serialVersionUID = 4392496278679167896L;
61  
62  	/**
63  	 * The maximum possible value for an <code>UnsignedInteger8</code>.
64  	 */
65  	public static final short MAX_VALUE = 255;
66  
67  	/**
68  	 * The minimum possible value for an <code>UnsignedInteger8</code>.
69  	 */
70  	public static final short MIN_VALUE = 0;
71  
72  	private short iValue;
73  
74  	/**
75  	 * Sets the value of this integer object if it falls within the range of
76  	 * minimum and maximum values.
77  	 *
78  	 * @param pValue
79  	 *            The integer.
80  	 * @throws NumberFormatException
81  	 *             If the integer is out of range.
82  	 */
83  	private void setValue(short pValue) throws NumberFormatException {
84  		if (pValue > MAX_VALUE || pValue < MIN_VALUE) {
85  			String msg = "uint8:" + pValue + " is out of range!";
86  			throw new NumberFormatException(msg);
87  		}
88  		this.iValue = pValue;
89  	}
90  
91  	/**
92  	 * Constructs an unsigned 8-bit integer object for the specified short
93  	 * value. Only the lower 8 bits are considered.
94  	 *
95  	 * @param pValue
96  	 *            The short to be represented as an unsigned 8-bit integer
97  	 *            object.
98  	 * @throws NumberFormatException
99  	 *             If the number is out of range.
100 	 */
101 	public UnsignedInteger8(short pValue) throws NumberFormatException {
102 		setValue(pValue);
103 	}
104 
105 	/**
106 	 * Constructs an unsigned 8-bit integer object for the specified string.
107 	 * Only the lower 8 bits are considered.
108 	 *
109 	 * @param pValue
110 	 *            The string to be represented as an unsigned 8-bit integer.
111 	 * @throws NumberFormatException
112 	 *             If the number is out of range.
113 	 * @throws IllegalArgumentException
114 	 *             If value is <code>null</code>.
115 	 */
116 	public UnsignedInteger8(String pValue) throws NumberFormatException {
117 		if (pValue == null) throw new IllegalArgumentException("String value cannot be null!");
118 		setValue(Short.parseShort(pValue));
119 	}
120 
121 	/**
122 	 * Compares this object with the specified object for order. Returns a
123 	 * negative integer, zero, or a positive integer as this object is less
124 	 * than, equal to, or greater than the specified object.
125 	 *
126 	 * @param pOther
127 	 *            The Object to be compared.
128 	 * @return A negative integer, zero, or a positive integer as this object is
129 	 *         less than, equal to, or greater than the specified object.
130 	 * @throws ClassCastException
131 	 *             If the specified object's type prevents it from being
132 	 *             compared to this Object.
133 	 * @throws IllegalArgumentException
134 	 *             If value is <code>null</code>.
135 	 */
136 	public int compareTo(UnsignedInteger8 pOther) {
137 		if (pOther == null) throw new IllegalArgumentException("Other UnsignedInteger8 cannot be null!");
138 		UnsignedInteger8 that = pOther;
139 		int d = this.iValue - that.iValue;
140 		if (d == 0) return 0;
141 		return d < 0 ? -1 : 1;
142 	}
143 
144 	/**
145 	 * Compares this object against the specified object. The result is true if
146 	 * and only if the argument is not null and is an
147 	 * <code>UnsignedInteger8</code> object that represents the same value as
148 	 * this object.
149 	 *
150 	 * @param pObj
151 	 *            The object to compare.
152 	 * @return <code>true</code> if the objects are the same; <code>false</code>
153 	 *         otherwise.
154 	 */
155 	@Override
156 	public boolean equals(Object pObj) {
157 		if (!(pObj instanceof UnsignedInteger8)) return false;
158 		return this.iValue == ((UnsignedInteger8) pObj).iValue;
159 	}
160 
161 	/**
162 	 * Returns the value of this unsigned integer object as a <code>byte</code>.
163 	 *
164 	 * @return The <code>byte</code> value of this unsigned integer object.
165 	 */
166 	@Override
167 	public byte byteValue() {
168 		return (byte) this.iValue;
169 	}
170 
171 	/**
172 	 * Returns the value of this unsigned integer object as a
173 	 * <code>double</code>.
174 	 *
175 	 * @return Value of this unsigned integer object as a <code>double</code>.
176 	 */
177 	@Override
178 	public double doubleValue() {
179 		return this.iValue;
180 	}
181 
182 	/**
183 	 * Returns the value of this unsigned integer object as a <code>float</code>
184 	 * .
185 	 *
186 	 * @return Value of this unsigned integer object as a <code>float</code>.
187 	 */
188 	@Override
189 	public float floatValue() {
190 		return this.iValue;
191 	}
192 
193 	/**
194 	 * Computes the hash code for this unsigned integer object.
195 	 *
196 	 * @return The integer representing the hash code for this unsigned integer
197 	 *         object.
198 	 */
199 	@Override
200 	public int hashCode() {
201 		return Short.valueOf(this.iValue).hashCode();
202 	}
203 
204 	/**
205 	 * Returns the value of this unsigned integer object as an <code>int</code>.
206 	 *
207 	 * @return Value of this unsigned integer object as an <code>int</code>.
208 	 */
209 	@Override
210 	public int intValue() {
211 		return this.iValue;
212 	}
213 
214 	/**
215 	 * Returns the value of this unsigned integer object as a <code>long</code>.
216 	 *
217 	 * @return Value of this unsigned integer object as a <code>long</code>.
218 	 */
219 	@Override
220 	public long longValue() {
221 		return this.iValue;
222 	}
223 
224 	/**
225 	 * Returns the value of this unsigned integer object as a <code>short</code>
226 	 * .
227 	 *
228 	 * @return Value of this unsigned integer object as a <code>short</code>.
229 	 */
230 	@Override
231 	public short shortValue() {
232 		return this.iValue;
233 	}
234 
235 	/**
236 	 * Returns the text representation of this unsigned integer object.
237 	 *
238 	 * @return Text representation of this unsigned integer.
239 	 */
240 	@Override
241 	public String toString() {
242 		return Short.toString(this.iValue);
243 	}
244 }