001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.j2ssh.io;
027:
028: import java.io.*;
029:
030: /**
031: *
032: *
033: * @author $author$
034: * @version $Revision: 1.14 $
035: */
036: public class UnsignedInteger32 extends Number implements Serializable {
037: final static long serialVersionUID = 200;
038:
039: /** */
040: public final static long MAX_VALUE = 0xffffffffL;
041:
042: /** */
043: public final static long MIN_VALUE = 0;
044: private Long value;
045:
046: /**
047: * Creates a new UnsignedInteger32 object.
048: *
049: * @param a
050: *
051: * @throws NumberFormatException
052: */
053: public UnsignedInteger32(long a) {
054: if ((a < MIN_VALUE) || (a > MAX_VALUE)) {
055: throw new NumberFormatException();
056: }
057:
058: value = new Long(a);
059: }
060:
061: /**
062: * Creates a new UnsignedInteger32 object.
063: *
064: * @param a
065: *
066: * @throws NumberFormatException
067: */
068: public UnsignedInteger32(String a) throws NumberFormatException {
069: Long temp = new Long(a);
070: long longValue = temp.longValue();
071:
072: if ((longValue < MIN_VALUE) || (longValue > MAX_VALUE)) {
073: throw new NumberFormatException();
074: }
075:
076: value = new Long(longValue);
077: }
078:
079: /**
080: *
081: *
082: * @return
083: */
084: public byte byteValue() {
085: return value.byteValue();
086: }
087:
088: /**
089: *
090: *
091: * @return
092: */
093: public short shortValue() {
094: return value.shortValue();
095: }
096:
097: /**
098: *
099: *
100: * @return
101: */
102: public int intValue() {
103: return value.intValue();
104: }
105:
106: /**
107: *
108: *
109: * @return
110: */
111: public long longValue() {
112: return value.longValue();
113: }
114:
115: /**
116: *
117: *
118: * @return
119: */
120: public float floatValue() {
121: return value.floatValue();
122: }
123:
124: /**
125: *
126: *
127: * @return
128: */
129: public double doubleValue() {
130: return value.doubleValue();
131: }
132:
133: /**
134: *
135: *
136: * @return
137: */
138: public String toString() {
139: return value.toString();
140: }
141:
142: /**
143: *
144: *
145: * @return
146: */
147: public int hashCode() {
148: return value.hashCode();
149: }
150:
151: /**
152: *
153: *
154: * @param o
155: *
156: * @return
157: */
158: public boolean equals(Object o) {
159: if (!(o instanceof UnsignedInteger32)) {
160: return false;
161: }
162:
163: return (((UnsignedInteger32) o).value.equals(this .value));
164: }
165:
166: /**
167: *
168: *
169: * @param x
170: * @param y
171: *
172: * @return
173: */
174: public static UnsignedInteger32 add(UnsignedInteger32 x,
175: UnsignedInteger32 y) {
176: return new UnsignedInteger32(x.longValue() + y.longValue());
177: }
178:
179: /**
180: *
181: *
182: * @param x
183: * @param y
184: *
185: * @return
186: */
187: public static UnsignedInteger32 add(UnsignedInteger32 x, int y) {
188: return new UnsignedInteger32(x.longValue() + y);
189: }
190: }
|