Back to index

plt-scheme  4.2.1
Short.java
Go to the documentation of this file.
00001 /* Short.java -- object wrapper for short
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 
00054 public final class Short extends Number implements Comparable
00055 {
00059   private static final long serialVersionUID = 7515723908773894738L;
00060 
00065   public static final short MIN_VALUE = (short) -32768;
00066 
00071   public static final short MAX_VALUE = (short) 32767;
00072 
00077   //public static final Class TYPE = VMClassLoader.getPrimitiveClass('S');
00078 
00084   private final short value;
00085 
00092   public Short(short value)
00093   {
00094     this.value = value;
00095   }
00096 
00104   public Short(String s)
00105   {
00106     value = parseShort(s, 10);
00107   }
00108 
00116   public static String toString(short s)
00117   {
00118     return String.valueOf((int) s);
00119   }
00120 
00130   public static short parseShort(String s)
00131   {
00132     return parseShort(s, 10);
00133   }
00134 
00151   public static short parseShort(String s, int radix)
00152   {
00153     int i = Integer.parseInt(s, radix, false);
00154     if ((short) i != i)
00155       throw new NumberFormatException();
00156     return (short) i;
00157   }
00158 
00170   public static Short valueOf(String s, int radix)
00171   {
00172     return new Short(parseShort(s, radix));
00173   }
00174 
00186   public static Short valueOf(String s)
00187   {
00188     return new Short(parseShort(s, 10));
00189   }
00190 
00222   public static Short decode(String s)
00223   {
00224     int i = Integer.parseInt(s, 10, true);
00225     if ((short) i != i)
00226       throw new NumberFormatException();
00227     return new Short((short) i);
00228   }
00229 
00235   public byte byteValue()
00236   {
00237     return (byte) value;
00238   }
00239 
00245   public short shortValue()
00246   {
00247     return value;
00248   }
00249 
00255   public int intValue()
00256   {
00257     return value;
00258   }
00259 
00265   public long longValue()
00266   {
00267     return value;
00268   }
00269 
00275   public float floatValue()
00276   {
00277     return value;
00278   }
00279 
00285   public double doubleValue()
00286   {
00287     return value;
00288   }
00289 
00296   public String toString()
00297   {
00298     return String.valueOf((int) value);
00299   }
00300 
00307   public int hashCode()
00308   {
00309     return value;
00310   }
00311 
00319   public boolean equals(Object obj)
00320   {
00321     return obj instanceof Short && value == ((Short) obj).value;
00322   }
00323 
00333   public int compareTo(Short s)
00334   {
00335     return value - s.value;
00336   }
00337 
00349   public int compareTo(Object o)
00350   {
00351     return compareTo((Short)o);
00352   }
00353 }