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>UnsignedInteger16</code>. A 53 * <code>uint16</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 UnsignedInteger16 extends Number implements Comparable<UnsignedInteger16> { 59 private static final long serialVersionUID = -4992164525643467216L; 60 61 /** 62 * The maximum value for an <code>UnsignedInteger16</code>. 63 */ 64 public static final int MAX_VALUE = 65535; 65 66 /** 67 * The minimum value for an <code>UnsignedInteger16</code>. 68 */ 69 public static final int MIN_VALUE = 0; 70 71 private int 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(int pValue) throws NumberFormatException { 83 if (pValue > MAX_VALUE || pValue < MIN_VALUE) { 84 String msg = "uint16:" + pValue + " is out of range!"; 85 throw new NumberFormatException(msg); 86 } 87 this.iValue = pValue; 88 } 89 90 /** 91 * Constructs an unsigned 16-bit integer object for the specified int value. 92 * Only the lower 16 bits are considered. 93 * 94 * @param pValue 95 * The integer to be represented as an unsigned 16-bit integer. 96 * @throws NumberFormatException 97 * If the number is out of range. 98 */ 99 public UnsignedInteger16(int pValue) throws NumberFormatException { 100 setValue(pValue); 101 } 102 103 /** 104 * Constructs an unsigned 16-bit integer object for the specified string. 105 * Only the lower 16 bits are considered. 106 * 107 * @param pValue 108 * The string to be represented as an unsigned 16-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 UnsignedInteger16(String pValue) throws NumberFormatException { 115 if (pValue == null) throw new IllegalArgumentException("String value cannot be null!"); 116 setValue(Integer.parseInt(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(UnsignedInteger16 pOther) { 135 if (pOther == null) throw new IllegalArgumentException("Other UnsignedInteger16 cannot be null!"); 136 UnsignedInteger16 that = pOther; 137 int 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 * <code>UnsignedInteger16</code> object that represents the same value as 146 * this object. 147 * 148 * @param pObj 149 * The object to compare. 150 * @return <code>true</code> if the objects are the same; <code>false</code> 151 * otherwise. 152 */ 153 @Override 154 public boolean equals(Object pObj) { 155 if (!(pObj instanceof UnsignedInteger16)) return false; 156 return this.iValue == ((UnsignedInteger16) pObj).iValue; 157 } 158 159 /** 160 * Returns the value of this unsigned integer object as a <code>byte</code>. 161 * 162 * @return The <code>byte</code> value of this unsigned integer object. 163 */ 164 @Override 165 public byte byteValue() { 166 return (byte) this.iValue; 167 } 168 169 /** 170 * Returns the value of this unsigned integer object as a 171 * <code>double</code>. 172 * 173 * @return Value of this unsigned integer object as a <code>double</code>. 174 */ 175 @Override 176 public double doubleValue() { 177 return this.iValue; 178 } 179 180 /** 181 * Returns the value of this unsigned integer object as a <code>float</code> 182 * . 183 * 184 * @return Value of this unsigned integer object as a <code>float</code>. 185 */ 186 @Override 187 public float floatValue() { 188 return this.iValue; 189 } 190 191 /** 192 * Computes the hash code for this unsigned integer object. 193 * 194 * @return The integer representing the hash code for this unsigned integer 195 * object. 196 */ 197 @Override 198 public int hashCode() { 199 return Integer.valueOf(this.iValue).hashCode(); 200 } 201 202 /** 203 * Returns the value of this unsigned integer object as an <code>int</code>. 204 * 205 * @return Value of this unsigned integer object as an <code>int</code>. 206 */ 207 @Override 208 public int intValue() { 209 return this.iValue; 210 } 211 212 /** 213 * Returns the value of this unsigned integer object as a <code>long</code>. 214 * 215 * @return Value of this unsigned integer object as a <code>long</code>. 216 */ 217 @Override 218 public long longValue() { 219 return this.iValue; 220 } 221 222 /** 223 * Returns the value of this unsigned integer object as a <code>short</code> 224 * . 225 * 226 * @return Value of this unsigned integer object as a <code>short</code>. 227 */ 228 @Override 229 public short shortValue() { 230 return (short) this.iValue; 231 } 232 233 /** 234 * Returns the text representation of this unsigned integer object. 235 * 236 * @return Text representation of this unsigned integer. 237 */ 238 @Override 239 public String toString() { 240 return Integer.toString(this.iValue); 241 } 242 }