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