1 module java.lang.Short; 2 3 import java.lang.util; 4 import java.lang.exceptions; 5 import java.lang.Number; 6 import java.lang.Class; 7 import java.lang.String; 8 9 version(Tango){ 10 static import tango.text.convert.Integer; 11 } else { // Phobos 12 static import std.conv; 13 } 14 class Short : Number { 15 public static const short MIN_VALUE = short.min; 16 public static const short MAX_VALUE = short.max; 17 private short value; 18 public static short parseShort( String s ){ 19 version(Tango){ 20 try{ 21 int res = tango.text.convert.Integer.parse( s ); 22 if( res < short.min || res > short.max ){ 23 throw new NumberFormatException( "out of range" ); 24 } 25 return res; 26 } 27 catch( IllegalArgumentException e ){ 28 throw new NumberFormatException( e ); 29 } 30 } else { // Phobos 31 try{ 32 return std.conv.to!(short)(s); 33 } 34 catch( std.conv.ConvException e ){ 35 throw new NumberFormatException( e ); 36 } 37 } 38 } 39 this( short value ){ 40 super(); 41 this.value = value; 42 } 43 44 public static String toString( short i ){ 45 return String_valueOf(i); 46 } 47 48 private static Class TYPE_; 49 public static Class TYPE(){ 50 if( TYPE_ is null ){ 51 TYPE_ = Class.fromType!(short); 52 } 53 return TYPE_; 54 } 55 56 override 57 byte byteValue(){ return cast(byte)value; } 58 override 59 double doubleValue(){ return value; } 60 override 61 float floatValue(){ return value; } 62 override 63 int intValue(){ return value; } 64 override 65 long longValue(){ return value; } 66 override 67 short shortValue(){ return value; } 68 } 69 alias Short ValueWrapperShort; 70