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   * 2003590    2008-06-30  blaschke-oss Change licensing from CPL to EPL
17   * 2524131    2009-01-21  raman_arora  Upgrade client to JDK 1.5 (Phase 1)
18   * 2531371    2009-02-10  raman_arora  Upgrade client to JDK 1.5 (Phase 2)
19   * 2750520    2009-04-10  blaschke-oss Code cleanup from empty statement et al
20   * 2795671    2009-05-22  raman_arora  Add Type to Comparable <T>
21   * 2935258    2010-01-19  blaschke-oss Sync up javax.cim.* javadoc with JSR48 1.0.0
22   * 2973230    2010-03-19  blaschke-oss TCK: UnsignedInteger64.equals() does not handle null
23   *    2719    2013-12-10  blaschke-oss TCK: CIM APIs should not generate NullPointerException
24   *    2716    2013-12-11  blaschke-oss Sync up javax.* javadoc with JSR48 1.0.0 Final V
25   */
26  
27  package org.metricshub.wbem.javax.cim;
28  
29  /*-
30   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
31   * WBEM Java Client
32   * ჻჻჻჻჻჻
33   * Copyright 2023 - 2025 MetricsHub
34   * ჻჻჻჻჻჻
35   * Licensed under the Apache License, Version 2.0 (the "License");
36   * you may not use this file except in compliance with the License.
37   * You may obtain a copy of the License at
38   *
39   *      http://www.apache.org/licenses/LICENSE-2.0
40   *
41   * Unless required by applicable law or agreed to in writing, software
42   * distributed under the License is distributed on an "AS IS" BASIS,
43   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
44   * See the License for the specific language governing permissions and
45   * limitations under the License.
46   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
47   */
48  
49  import java.math.BigInteger;
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>UnsignedInteger64</code>. A
54   * <code>uint64</code> data type is defined by the (<a
55   * href=http://www.dmtf.org>DMTF</a>) CIM Infrastructure Specification (<a
56   * href=http://www.dmtf.org/standards/published_documents/DSP0004V2.3_final.pdf
57   * >DSP004</a>).
58   */
59  public class UnsignedInteger64 extends Number implements Comparable<UnsignedInteger64> {
60  	private static final long serialVersionUID = -3734165689168941119L;
61  
62  	/**
63  	 * The maximum value for an <code>UnsignedInteger64</code>.
64  	 */
65  	public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
66  
67  	/**
68  	 * The minimum value for an <code>UnsignedInteger64</code>.
69  	 */
70  	public static final BigInteger MIN_VALUE = BigInteger.ZERO;
71  
72  	private BigInteger 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(BigInteger pValue) throws NumberFormatException {
84  		if (pValue.compareTo(MAX_VALUE) > 0 || pValue.compareTo(MIN_VALUE) < 0) {
85  			String msg = "uint64:" + pValue + " is out of range!";
86  			throw new NumberFormatException(msg);
87  		}
88  		this.iValue = pValue;
89  	}
90  
91  	/**
92  	 * Constructs an unsigned 64-bit integer object for the specified
93  	 * <code>BigInteger</code>. Only the lower 64 bits are considered.
94  	 *
95  	 * @param pValue
96  	 *            The <code>BigInteger</code> to be represented as an unsigned
97  	 *            64-bit integer.
98  	 * @throws NumberFormatException
99  	 *             If the number is out of range.
100 	 * @throws IllegalArgumentException
101 	 *             If value is <code>null</code>.
102 	 */
103 	public UnsignedInteger64(BigInteger pValue) throws NumberFormatException {
104 		if (pValue == null) throw new IllegalArgumentException("BigInteger value cannot be null!");
105 		setValue(pValue);
106 	}
107 
108 	/**
109 	 * Constructs an unsigned 64-bit integer object for the specified array of
110 	 * bytes. Only the lower 64 bits are considered.
111 	 *
112 	 * @param pValue
113 	 *            The byte array to be represented as an unsigned 64-bit
114 	 *            integer.
115 	 * @throws NumberFormatException
116 	 *             If the number is out of range.
117 	 * @throws IllegalArgumentException
118 	 *             If value is <code>null</code>.
119 	 */
120 	public UnsignedInteger64(byte[] pValue) throws NumberFormatException {
121 		if (pValue == null) throw new IllegalArgumentException("byte[] value cannot be null!");
122 		setValue(new BigInteger(pValue));
123 	}
124 
125 	/**
126 	 * Constructs an unsigned 64-bit integer object from the specified string.
127 	 * Only the lower 64 bits are considered.
128 	 *
129 	 * @param pValue
130 	 *            The string to be represented as an unsigned 64-bit integer.
131 	 * @throws NumberFormatException
132 	 *             If the number is out of range.
133 	 * @throws IllegalArgumentException
134 	 *             If value is <code>null</code>.
135 	 */
136 	public UnsignedInteger64(String pValue) throws NumberFormatException {
137 		if (pValue == null) throw new IllegalArgumentException("String value cannot be null!");
138 		setValue(new BigInteger(pValue));
139 	}
140 
141 	/**
142 	 * Get the value as a <code>BigInteger</code>.
143 	 *
144 	 * @return <code>BigInteger</code> representation of this object.
145 	 */
146 	public BigInteger bigIntegerValue() {
147 		return this.iValue;
148 	}
149 
150 	/**
151 	 * Compares this object with the specified object for order. Returns a
152 	 * negative integer, zero, or a positive integer as this object is less
153 	 * than, equal to, or greater than the specified object.
154 	 *
155 	 * @param pOther
156 	 *            The Object to be compared.
157 	 * @return A negative integer, zero, or a positive integer as this object is
158 	 *         less than, equal to, or greater than the specified object.
159 	 * @throws ClassCastException
160 	 *             If the specified object's type prevents it from being
161 	 *             compared to this Object.
162 	 * @throws IllegalArgumentException
163 	 *             If value is <code>null</code>.
164 	 */
165 	public int compareTo(UnsignedInteger64 pOther) {
166 		if (pOther == null) throw new IllegalArgumentException("Other UnsignedInteger64 cannot be null!");
167 		UnsignedInteger64 that = pOther;
168 		int d = this.iValue.compareTo(that.iValue);
169 		if (d == 0) return 0;
170 		return d < 0 ? -1 : 1;
171 	}
172 
173 	/**
174 	 * Compares this object against the specified object. The result is
175 	 * <code>true</code> if and only if the argument is not <code>null</code>
176 	 * and is an <code>UnsignedInteger64</code> object that represents the same
177 	 * value as this object.
178 	 *
179 	 * @param pOther
180 	 *            The object to compare.
181 	 * @return <code>true</code> if the objects are the same; <code>false</code>
182 	 *         otherwise.
183 	 */
184 	@Override
185 	public boolean equals(Object pOther) {
186 		if (!(pOther instanceof UnsignedInteger64)) return false;
187 		return this.iValue.equals(((UnsignedInteger64) pOther).iValue);
188 	}
189 
190 	/**
191 	 * Returns the value of this unsigned integer object as a <code>byte</code>.
192 	 *
193 	 * @return The <code>byte</code> value of this unsigned integer object.
194 	 */
195 	@Override
196 	public byte byteValue() {
197 		return this.iValue.byteValue();
198 	}
199 
200 	/**
201 	 * Returns the value of this unsigned integer object as a
202 	 * <code>double</code>.
203 	 *
204 	 * @return Value of this unsigned integer object as a <code>double</code>.
205 	 */
206 	@Override
207 	public double doubleValue() {
208 		return this.iValue.doubleValue();
209 	}
210 
211 	/**
212 	 * Returns the value of this unsigned integer object as a <code>float</code>
213 	 * .
214 	 *
215 	 * @return Value of this unsigned integer object as a <code>float</code>.
216 	 */
217 	@Override
218 	public float floatValue() {
219 		return this.iValue.floatValue();
220 	}
221 
222 	/**
223 	 * Computes the hash code for this unsigned integer object.
224 	 *
225 	 * @return The integer representing the hash code for this unsigned integer
226 	 *         object.
227 	 */
228 	@Override
229 	public int hashCode() {
230 		return this.iValue.hashCode();
231 	}
232 
233 	/**
234 	 * Returns the value of this unsigned integer object as an <code>int</code>.
235 	 *
236 	 * @return Value of this unsigned integer object as an <code>int</code>.
237 	 */
238 	@Override
239 	public int intValue() {
240 		return this.iValue.intValue();
241 	}
242 
243 	/**
244 	 * Returns the value of this unsigned integer object as a <code>long</code>.
245 	 *
246 	 * @return Value of this unsigned integer object as a <code>long</code>.
247 	 */
248 	@Override
249 	public long longValue() {
250 		return this.iValue.longValue();
251 	}
252 
253 	/**
254 	 * Returns the value of this unsigned integer object as a <code>short</code>
255 	 * .
256 	 *
257 	 * @return Value of this unsigned integer object as a <code>short</code>.
258 	 */
259 	@Override
260 	public short shortValue() {
261 		return this.iValue.shortValue();
262 	}
263 
264 	/**
265 	 * Returns the text representation of this unsigned integer object.
266 	 *
267 	 * @return Text representation of this unsigned integer.
268 	 */
269 	@Override
270 	public String toString() {
271 		return this.iValue.toString();
272 	}
273 }