package silk; /** Coersion between primitive types. **/ public class Coerce { public static char toChar(int x) { return (char) x; } public static int toByte(char x) { return (byte) x; } public static byte toByte(byte x) { return (byte) x; } public static byte toByte(short x) { return (byte) x; } public static byte toByte(int x) { return (byte) x; } public static byte toByte(long x) { return (byte) x; } public static byte toByte(float x) { return (byte) x; } public static byte toByte(double x) { return (byte) x; } public static byte toByte(String x) { return Byte.parseByte(x); } public static int toShort(char x) { return (short) x; } public static short toShort(byte x) { return (short) x; } public static short toShort(short x) { return (short) x; } public static short toShort(int x) { return (short) x; } public static short toShort(long x) { return (short) x; } public static short toShort(float x) { return (short) x; } public static short toShort(double x) { return (short) x; } public static short toShort(String x) { return Short.parseShort(x); } public static int toInt(char x) { return (int) x; } public static int toInt(byte x) { return (int) x; } public static int toInt(short x) { return (int) x; } public static int toInt(int x) { return (int) x; } public static int toInt(long x) { return (int) x; } public static int toInt(float x) { return (int) x; } public static int toInt(double x) { return (int) x; } public static int toInt(String x) { return Integer.parseInt(x); } public static long toLong(char x) { return (long) x; } public static long toLong(byte x) { return (long) x; } public static long toLong(short x) { return (long) x; } public static long toLong(int x) { return (long) x; } public static long toLong(long x) { return (long) x; } public static long toLong(float x) { return (long) x; } public static long toLong(double x) { return (long) x; } public static long toLong(String x) { return Long.parseLong(x); } public static float toFloat(char x) { return (float) x; } public static float toFloat(byte x) { return (float) x; } public static float toFloat(short x) { return (float) x; } public static float toFloat(int x) { return (float) x; } public static float toFloat(long x) { return (float) x; } public static float toFloat(float x) { return (float) x; } public static float toFloat(double x) { return (float) x; } // JDK 1.2 // public static float toFloat(String x) { return Float.parseFloat(x); } public static float toFloat(String x) { return (new Float(x)).floatValue(); } public static double toDouble(char x) { return (double) x; } public static double toDouble(byte x) { return (double) x; } public static double toDouble(short x) { return (double) x; } public static double toDouble(int x) { return (double) x; } public static double toDouble(long x) { return (double) x; } public static double toDouble(float x) { return (double) x; } public static double toDouble(double x) { return (double) x; } // JDK 1.2 // public static double toDouble(String x) { return Double.parseDouble(x); } public static double toDouble(String x) { return (new Double(x)).doubleValue(); } }