Created
August 6, 2015 18:00
-
-
Save money4honey/523e20afa86bd5aa6d16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ru.moneyhoney.tester.util; | |
public class Convert { | |
// Convert primitive types to String | |
public static String toString(byte i){ | |
return Integer.toString(i); | |
} | |
public static String toString(short i){ | |
return Integer.toString(i); | |
} | |
public static String toString(int i){ | |
return Integer.toString(i); | |
} | |
public static String toString(long i){ | |
return Long.toString(i); | |
} | |
public static String toString(float i){ | |
return String.valueOf(i); | |
} | |
public static String toString(double i){ | |
return String.valueOf(i); | |
} | |
public static String toString(boolean i){ | |
return String.valueOf(i); | |
} | |
public static String toString(char i){ | |
return String.valueOf(i); | |
} | |
// Convert primitive types to int | |
public static int toInt(byte i){ | |
return (int) i; | |
} | |
public static int toInt(short i){ | |
return (int) i; | |
} | |
public static int toInt(long i){ | |
return (int) i; | |
} | |
public static int toInt(float i){ | |
return (int) i; | |
} | |
public static int toInt(double i){ | |
return (int) i; | |
} | |
public static int toInt(boolean i){ | |
if (i) return 1; | |
else return 0; | |
} | |
public static int toInt(char i){ | |
return (int) i; | |
} | |
// Convert primitive types to double | |
public static double toDouble(byte i){ | |
return (double) i; | |
} | |
public static double toDouble(short i){ | |
return (double) i; | |
} | |
public static double toDouble(int i){ | |
return (double) i; | |
} | |
public static double toDouble(long i){ | |
return (double) i; | |
} | |
public static double toDouble(float i){ | |
return (double) i; | |
} | |
public static double toDouble(boolean i){ | |
if (i) return 1.0; | |
else return 0.0; | |
} | |
public static double toDouble(char i){ | |
return (double) i; | |
} | |
public static double toDouble(String i){ | |
return Double.parseDouble(i); | |
} | |
// Convert primitive types to byte | |
public static byte toByte(short i){ | |
return (byte) i; | |
} | |
public static byte toByte(int i){ | |
return (byte) i; | |
} | |
public static byte toByte(long i){ | |
return (byte) i; | |
} | |
public static byte toByte(float i){ | |
return (byte) i; | |
} | |
public static byte toByte(double i){ | |
return (byte) i; | |
} | |
public static byte toByte(boolean i){ | |
if (i) return 1; | |
else return 0; | |
} | |
public static byte toByte(char i){ | |
return (byte) i; | |
} | |
public static byte[] toByte(String i){ | |
return i.getBytes(); | |
} | |
// Show object type | |
public static String showType(Object i){ | |
return i.getClass().toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment