1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * 26 * ident "%Z%%M% %I% %E% SMI" 27 */ 28 29 package com.sun.solaris.service.pools; 30 31 import java.math.BigInteger; 32 33 public class UnsignedInt64 extends BigInteger { 34 /** 35 * The minimum value is 0. 36 */ 37 public final static BigInteger MIN_VALUE = new BigInteger("0"); 38 39 /** 40 * The maximum value is 18446744073709551615. 41 */ 42 public final static BigInteger MAX_VALUE = new BigInteger( 43 "18446744073709551615"); 44 45 /** 46 * Constructs a UnsignedInt64 with the same value as the given 47 * string, interpreted in base 10. 48 * 49 * @throws NumberFormatException if the given value is outside 50 * the representable range. 51 */ UnsignedInt64(String string)52 public UnsignedInt64(String string) throws NumberFormatException 53 { 54 super(string); 55 validate(this); 56 } 57 58 /** 59 * Constructs a UnsignedInt64 with the same value as the given 60 * string, interpreted in the given base. 61 * 62 * @throws NumberFormatException if the given value is outside 63 * the representable range. 64 */ UnsignedInt64(String string, int radix)65 public UnsignedInt64(String string, int radix) 66 throws NumberFormatException 67 { 68 super(string, radix); 69 validate(this); 70 } 71 72 /** 73 * Constructs a UnsignedInt64 with the same value as the given 74 * byte array, interpreted as a two's-complement number in 75 * big-endian byte order (the most significant byte has the 76 * lowest index). 77 * 78 * @throws NumberFormatException if the given value is outside 79 * the representable range. 80 */ UnsignedInt64(byte[] bytes)81 public UnsignedInt64(byte[] bytes) throws NumberFormatException 82 { 83 super(bytes); 84 validate(this); 85 } 86 87 /** 88 * Constructs an UnsignedInt64 with the same value as the given 89 * BigInteger. 90 * 91 * @throws NumberFormatException if the given value is outside 92 * the representable range. 93 */ UnsignedInt64(BigInteger value)94 public UnsignedInt64(BigInteger value) throws NumberFormatException 95 { 96 super(value.toByteArray()); 97 validate(this); 98 } 99 100 /** 101 * Check that the supplied parameter is a valid value for an 102 * UnsignedInt64. 103 * 104 * @param v A BigInteger to be checked if it's value is legal 105 * as an UnsignedInt64. 106 * @throws NumberFormatException if the given value is outside 107 * the representable range. 108 */ validate(BigInteger v)109 private void validate(BigInteger v) 110 { 111 if (v.compareTo(MIN_VALUE) < 0 || v.compareTo(MAX_VALUE) > 0) 112 throw(new NumberFormatException()); 113 } 114 } 115