view base/src/java/lang/Long.d @ 125:c43718956f21 default tip

Updated the snippets status.
author Jacob Carlborg <doob@me.com>
date Thu, 11 Aug 2011 19:55:14 +0200
parents 536e43f63c81
children
line wrap: on
line source

module java.lang.Long;

import java.lang.util;
import java.lang.exceptions;
import java.lang.Number;
import java.lang.Character;
import java.lang.Class;
import java.lang.String;

version(Tango){
    static import tango.text.convert.Integer;
} else { // Phobos
    static import std.conv;
    static import std.string;
}

class Long : Number {
    public static const long MIN_VALUE = long.min;
    public static const long MAX_VALUE = long.max;
    private long value;
    this( long value ){
        super();
        this.value = value;
    }
    this( String str ){
        super();
        this.value = parseLong(str);
    }
    public byte byteValue(){
        return cast(byte)value;
    }

    public short shortValue(){
        return cast(short)value;
    }

    public int intValue(){
        return cast(int)value;
    }

    public long longValue(){
        return value;
    }

    public float floatValue(){
        return cast(float)value;
    }

    public double doubleValue(){
        return cast(double)value;
    }
    public static long parseLong(String s){
        return parseLong( s, 10 );
    }
    public static long parseLong(String s, int radix){
        if(radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
            throw new NumberFormatException("The radix is out of range");
        version(Tango){
            try{
                return tango.text.convert.Integer.toLong( s, radix );
            }
            catch( IllegalArgumentException e ){
                throw new NumberFormatException( e );
            }
        } else { // Phobos
            try{
                immutable res = std.conv.parse!(long)( s, radix );
                if(s.length)
                    throw new NumberFormatException("String has invalid characters: " ~ s);
                return res;
            }
            catch( std.conv.ConvException e ){
                throw new NumberFormatException( e );
            }
        }
    }
    public static String toString( long i ){
        return String_valueOf(i);
    }
    private static Class TYPE_;
    public static Class TYPE(){
        if( TYPE_ is null ){
            TYPE_ = Class.fromType!(long);
        }
        return TYPE_;
    }

}
alias Long ValueWrapperLong;