Back to index

plt-scheme  4.2.1
Byte.java
Go to the documentation of this file.
00001 /* Byte.java -- object wrapper for byte
00002    Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc.
00003 
00004 This file is part of GNU Classpath.
00005 
00006 GNU Classpath is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU General Public License as published by
00008 the Free Software Foundation; either version 2, or (at your option)
00009 any later version.
00010 
00011 GNU Classpath is distributed in the hope that it will be useful, but
00012 WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with GNU Classpath; see the file COPYING.  If not, write to the
00018 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019 02111-1307 USA.
00020 
00021 Linking this library statically or dynamically with other modules is
00022 making a combined work based on this library.  Thus, the terms and
00023 conditions of the GNU General Public License cover the whole
00024 combination.
00025 
00026 As a special exception, the copyright holders of this library give you
00027 permission to link this library with independent modules to produce an
00028 executable, regardless of the license terms of these independent
00029 modules, and to copy and distribute the resulting executable under
00030 terms of your choice, provided that you also meet, for each linked
00031 independent module, the terms and conditions of the license of that
00032 module.  An independent module is a module which is not derived from
00033 or based on this library.  If you modify this library, you may extend
00034 this exception to your version of the library, but you are not
00035 obligated to do so.  If you do not wish to do so, delete this
00036 exception statement from your version. */
00037 
00038 
00039 package java.lang;
00040 
00055 public final class Byte extends Number implements Comparable
00056 {
00060   private static final long serialVersionUID = -7183698231559129828L;
00061 
00066   public static final byte MIN_VALUE = -128;
00067 
00072   public static final byte MAX_VALUE = 127;
00073 
00078   //public static final Class TYPE = VMClassLoader.getPrimitiveClass('B');
00079 
00085   private final byte value;
00086 
00093   public Byte(byte value)
00094   {
00095     this.value = value;
00096   }
00097 
00106   public Byte(String s)
00107   {
00108     value = parseByte(s, 10);
00109   }
00110 
00118   public static String toString(byte b)
00119   {
00120     return String.valueOf((int)b);
00121   }
00122 
00133   public static byte parseByte(String s)
00134   {
00135     return parseByte(s, 10);
00136   }
00137 
00154   public static byte parseByte(String s, int radix)
00155   {
00156     int i = Integer.parseInt(s, radix, false);
00157     if ((byte) i != i)
00158       throw new NumberFormatException();
00159     return (byte) i;
00160   }
00161 
00173   public static Byte valueOf(String s, int radix)
00174   {
00175     return new Byte(parseByte(s, radix));
00176   }
00177 
00189   public static Byte valueOf(String s)
00190   {
00191     return new Byte(parseByte(s, 10));
00192   }
00193 
00225   public static Byte decode(String s)
00226   {
00227     int i = Integer.parseInt(s, 10, true);
00228     if ((byte) i != i)
00229       throw new NumberFormatException();
00230     return new Byte((byte) i);
00231   }
00232 
00238   public byte byteValue()
00239   {
00240     return value;
00241   }
00242 
00248   public short shortValue()
00249   {
00250     return value;
00251   }
00252 
00258   public int intValue()
00259   {
00260     return value;
00261   }
00262 
00268   public long longValue()
00269   {
00270     return value;
00271   }
00272 
00278   public float floatValue()
00279   {
00280     return value;
00281   }
00282 
00288   public double doubleValue()
00289   {
00290     return value;
00291   }
00292 
00300   public String toString()
00301   {
00302     return String.valueOf((int)value);
00303   }
00304 
00311   public int hashCode()
00312   {
00313     return value;
00314   }
00315 
00323   public boolean equals(Object obj)
00324   {
00325     return obj instanceof Byte && value == ((Byte) obj).value;
00326   }
00327 
00337   public int compareTo(Byte b)
00338   {
00339     return value - b.value;
00340   }
00341 
00353   public int compareTo(Object o)
00354   {
00355     return compareTo((Byte) o);
00356   }
00357 }