package runEnv; public class RunValue { Object value; public RunValue( int i ) { value = new Integer( i ); } public RunValue( char c ) { value = new Character( c ); } public RunValue( double d ) { value = new Double( d ); } public RunValue( boolean b ) { value = new Boolean( b ); } public RunValue( String s ) { value = s; } public RunValue( Multiple m ) { value = m; } public RunValue( RunValue v ) { value = v.getValue(); } public RunValue() { value = null; } public Object getValue() { return value; } public int intValue() { if ( value == null ) throw new Error( "uninitialised value" ); else if ( ! ( value instanceof Integer ) ) throw new Error( "Invalid type for value" ); else { Integer i = ( Integer ) value; return i.intValue(); } } public char charValue() { if ( value == null ) throw new Error( "uninitialised value" ); else if ( ! ( value instanceof Character ) ) throw new Error( "Invalid type for value" ); else { Character c = ( Character ) value; return c.charValue(); } } public double realValue() { if ( value == null ) throw new Error( "uninitialised value" ); else if ( ! ( value instanceof Double ) ) throw new Error( "Invalid type for value" ); else { Double d = ( Double ) value; return d.doubleValue(); } } public boolean boolValue() { if ( value == null ) throw new Error( "uninitialised value" ); else if ( ! ( value instanceof Boolean ) ) throw new Error( "Invalid type for value" ); else { Boolean b = ( Boolean ) value; return b.booleanValue(); } } public String stringValue() { if ( value == null ) return "null"; else { return value.toString(); } } public String toString() { if ( value == null ) return "null"; else { return value.toString(); } } public Multiple multipleValue() { if ( value == null ) return null; else if ( ! ( value instanceof Multiple ) ) throw new Error( "Invalid type for value" ); else { return ( Multiple ) value; } } }