1 11 12 13 package com.sun.jmx.snmp; 14 15 16 17 import com.sun.jmx.snmp.Enumerated; 18 19 27 28 public class SnmpInt extends SnmpValue { 29 30 38 public SnmpInt(int v) throws IllegalArgumentException { 39 if ( isInitValueValid(v) == false ) { 40 throw new IllegalArgumentException () ; 41 } 42 value = (long)v ; 43 } 44 45 51 public SnmpInt(Integer v) throws IllegalArgumentException { 52 this(v.intValue()) ; 53 } 54 55 61 public SnmpInt(long v) throws IllegalArgumentException { 62 if ( isInitValueValid(v) == false ) { 63 throw new IllegalArgumentException () ; 64 } 65 value = v ; 66 } 67 68 74 public SnmpInt(Long v) throws IllegalArgumentException { 75 this(v.longValue()) ; 76 } 77 78 85 public SnmpInt(Enumerated v) throws IllegalArgumentException { 86 this(v.intValue()) ; 87 } 88 89 101 public SnmpInt(boolean v) { 102 value = v ? 1 : 2 ; 103 } 104 105 111 public long longValue() { 112 return value ; 113 } 114 115 119 public Long toLong() { 120 return new Long (value) ; 121 } 122 123 127 public int intValue() { 128 return (int) value ; 129 } 130 131 135 public Integer toInteger() { 136 return new Integer ((int)value) ; 137 } 138 139 143 public String toString() { 144 return String.valueOf(value) ; 145 } 146 147 151 public SnmpOid toOid() { 152 return new SnmpOid(value) ; 153 } 154 155 164 public static SnmpOid toOid(long[] index, int start) throws SnmpStatusException { 165 try { 166 return new SnmpOid(index[start]) ; 167 } 168 catch(IndexOutOfBoundsException e) { 169 throw new SnmpStatusException(SnmpStatusException.noSuchName) ; 170 } 171 } 172 173 182 public static int nextOid(long[] index, int start) throws SnmpStatusException { 183 if (start >= index.length) { 184 throw new SnmpStatusException(SnmpStatusException.noSuchName) ; 185 } 186 else { 187 return start + 1 ; 188 } 189 } 190 191 196 public static void appendToOid(SnmpOid source, SnmpOid dest) { 197 if (source.getLength() != 1) { 198 throw new IllegalArgumentException () ; 199 } 200 dest.append(source) ; 201 } 202 203 208 final synchronized public SnmpValue duplicate() { 209 return (SnmpValue) clone() ; 210 } 211 212 216 final synchronized public Object clone() { 217 SnmpInt newclone = null ; 218 try { 219 newclone = (SnmpInt) super.clone() ; 220 newclone.value = value ; 221 } catch (CloneNotSupportedException e) { 222 throw new InternalError () ; } 224 return newclone ; 225 } 226 227 231 public String getTypeName() { 232 return name ; 233 } 234 235 239 boolean isInitValueValid(int v) { 240 if ((v < Integer.MIN_VALUE) || (v > Integer.MAX_VALUE)) { 241 return false; 242 } 243 return true; 244 } 245 246 250 boolean isInitValueValid(long v) { 251 if ((v < Integer.MIN_VALUE) || (v > Integer.MAX_VALUE)) { 252 return false; 253 } 254 return true; 255 } 256 257 262 final static String name = "Integer32" ; 263 264 268 protected long value = 0 ; 269 } 270 | Popular Tags |