From 8f523f3a1047919d3563daf1ef47ba87336ebe89 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 15 Nov 2005 23:20:01 +0000 Subject: Imported GNU Classpath 0.19 + gcj-import-20051115. * sources.am: Regenerated. * Makefile.in: Likewise. * scripts/makemake.tcl: Use glob -nocomplain. From-SVN: r107049 --- libjava/classpath/java/lang/Short.java | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'libjava/classpath/java/lang/Short.java') diff --git a/libjava/classpath/java/lang/Short.java b/libjava/classpath/java/lang/Short.java index fbeea915bd3..eb40cd9e0e6 100644 --- a/libjava/classpath/java/lang/Short.java +++ b/libjava/classpath/java/lang/Short.java @@ -76,6 +76,19 @@ public final class Short extends Number implements Comparable */ public static final Class TYPE = VMClassLoader.getPrimitiveClass('S'); + /** + * The number of bits needed to represent a short. + * @since 1.5 + */ + public static final int SIZE = 16; + + // This caches some Short values, and is used by boxing conversions + // via valueOf(). We must cache at least -128..127; these constants + // control how much we actually cache. + private static final int MIN_CACHE = -128; + private static final int MAX_CACHE = 127; + private static Short[] shortCache = new Short[MAX_CACHE - MIN_CACHE + 1]; + /** * The immutable value of this Short. * @@ -188,6 +201,28 @@ public final class Short extends Number implements Comparable return new Short(parseShort(s, 10)); } + /** + * Returns a Short object wrapping the value. + * In contrast to the Short constructor, this method + * will cache some values. It is used by boxing conversion. + * + * @param val the value to wrap + * @return the Short + * + * @since 1.5 + */ + public static Short valueOf(short val) + { + if (val < MIN_CACHE || val > MAX_CACHE) + return new Short(val); + synchronized (shortCache) + { + if (shortCache[val - MIN_CACHE] == null) + shortCache[val - MIN_CACHE] = new Short(val); + return shortCache[val - MIN_CACHE]; + } + } + /** * Convert the specified String into a Short. * The String may represent decimal, hexadecimal, or @@ -350,4 +385,13 @@ public final class Short extends Number implements Comparable { return compareTo((Short)o); } + + /** + * Reverse the bytes in val. + * @since 1.5 + */ + public static short reverseBytes(short val) + { + return (short) (((val >> 8) & 0xff) | ((val << 8) & 0xff00)); + } } -- cgit v1.2.3