view java/src/java/lang/Integer.d @ 2:712ffca654f3

Moved java classes to their correct location
author Frank Benoit <benoit@tionex.de>
date Wed, 04 Mar 2009 21:41:18 +0100
parents 6dd524f61e62
children 9b96950f2c3c
line wrap: on
line source

module java.lang.Integer;

import java.lang.util;
import java.lang.exceptions;

class Integer : ValueWrapperT!(int) {

    public static const int MIN_VALUE = 0x80000000;
    public static const int MAX_VALUE = 0x7fffffff;
    public static const int SIZE = 32;

    public this ( int value ){
        super( value );
    }

    public this ( String s ){
        super(parseInt(s));
    }

    public static String toString( int i, int radix ){
        switch( radix ){
        case 2:
            return toBinaryString(i);
        case 8:
            return toOctalString(i);
        case 10:
            return toString(i);
        case 16:
            return toHexString(i);
        default:
            implMissing( __FILE__, __LINE__ );
            return null;
        }
    }

    public static String toHexString( int i ){
        return tango.text.convert.Integer.toString(i, "x" );
    }

    public static String toOctalString( int i ){
        return tango.text.convert.Integer.toString(i, "o" );
    }

    public static String toBinaryString( int i ){
        return tango.text.convert.Integer.toString(i, "b" );
    }

    public static String toString( int i ){
        return tango.text.convert.Integer.toString(i);
    }

    public static int parseInt( String s, int radix ){
        try{
            return tango.text.convert.Integer.toLong( s, radix );
        }
        catch( IllegalArgumentException e ){
            throw new NumberFormatException( e );
        }
    }

    public static int parseInt( String s ){
        try{
            return tango.text.convert.Integer.toLong( s );
        }
        catch( IllegalArgumentException e ){
            throw new NumberFormatException( e );
        }
    }

    public static Integer valueOf( String s, int radix ){
        implMissing( __FILE__, __LINE__ );
        return null;
    }

    public static Integer valueOf( String s ){
        return valueOf( parseInt(s));
    }

    public static Integer valueOf( int i ){
        return new Integer(i);
    }

    public byte byteValue(){
        return cast(byte)value;
    }

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

    public int intValue(){
        return value;
    }

    public long longValue(){
        return cast(long)value;
    }

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

    public double doubleValue(){
        return cast(double)value;
    }

    public override  hash_t toHash(){
        return intValue();
    }

    public override String toString(){
        return tango.text.convert.Integer.toString( value );
    }
}
alias Integer ValueWrapperInt;