106 lines
3.1 KiB
Java
106 lines
3.1 KiB
Java
// onjava/ConvertTo.java
|
|
// (c)2016 MindView LLC: see Copyright.txt
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
// Visit http://OnJava8.com for more book information.
|
|
package onjava;
|
|
|
|
public interface ConvertTo {
|
|
public static boolean[] primitive(Boolean[] in) {
|
|
boolean[] result = new boolean[in.length];
|
|
for(int i = 0; i < in.length; i++)
|
|
result[i] = in[i]; // Autounboxing
|
|
return result;
|
|
}
|
|
public static char[] primitive(Character[] in) {
|
|
char[] result = new char[in.length];
|
|
for(int i = 0; i < in.length; i++)
|
|
result[i] = in[i];
|
|
return result;
|
|
}
|
|
public static byte[] primitive(Byte[] in) {
|
|
byte[] result = new byte[in.length];
|
|
for(int i = 0; i < in.length; i++)
|
|
result[i] = in[i];
|
|
return result;
|
|
}
|
|
public static short[] primitive(Short[] in) {
|
|
short[] result = new short[in.length];
|
|
for(int i = 0; i < in.length; i++)
|
|
result[i] = in[i];
|
|
return result;
|
|
}
|
|
public static int[] primitive(Integer[] in) {
|
|
int[] result = new int[in.length];
|
|
for(int i = 0; i < in.length; i++)
|
|
result[i] = in[i];
|
|
return result;
|
|
}
|
|
public static long[] primitive(Long[] in) {
|
|
long[] result = new long[in.length];
|
|
for(int i = 0; i < in.length; i++)
|
|
result[i] = in[i];
|
|
return result;
|
|
}
|
|
public static float[] primitive(Float[] in) {
|
|
float[] result = new float[in.length];
|
|
for(int i = 0; i < in.length; i++)
|
|
result[i] = in[i];
|
|
return result;
|
|
}
|
|
public static double[] primitive(Double[] in) {
|
|
double[] result = new double[in.length];
|
|
for(int i = 0; i < in.length; i++)
|
|
result[i] = in[i];
|
|
return result;
|
|
}
|
|
// Convert from primitive array to wrapped array:
|
|
public static Boolean[] boxed(boolean[] in) {
|
|
Boolean[] result = new Boolean[in.length];
|
|
for(int i = 0; i < in.length; i++)
|
|
result[i] = in[i]; // Autboxing
|
|
return result;
|
|
}
|
|
public static Character[] boxed(char[] in) {
|
|
Character[] result = new Character[in.length];
|
|
for(int i = 0; i < in.length; i++)
|
|
result[i] = in[i];
|
|
return result;
|
|
}
|
|
public static Byte[] boxed(byte[] in) {
|
|
Byte[] result = new Byte[in.length];
|
|
for(int i = 0; i < in.length; i++)
|
|
result[i] = in[i];
|
|
return result;
|
|
}
|
|
public static Short[] boxed(short[] in) {
|
|
Short[] result = new Short[in.length];
|
|
for(int i = 0; i < in.length; i++)
|
|
result[i] = in[i];
|
|
return result;
|
|
}
|
|
public static Integer[] boxed(int[] in) {
|
|
Integer[] result = new Integer[in.length];
|
|
for(int i = 0; i < in.length; i++)
|
|
result[i] = in[i];
|
|
return result;
|
|
}
|
|
public static Long[] boxed(long[] in) {
|
|
Long[] result = new Long[in.length];
|
|
for(int i = 0; i < in.length; i++)
|
|
result[i] = in[i];
|
|
return result;
|
|
}
|
|
public static Float[] boxed(float[] in) {
|
|
Float[] result = new Float[in.length];
|
|
for(int i = 0; i < in.length; i++)
|
|
result[i] = in[i];
|
|
return result;
|
|
}
|
|
public static Double[] boxed(double[] in) {
|
|
Double[] result = new Double[in.length];
|
|
for(int i = 0; i < in.length; i++)
|
|
result[i] = in[i];
|
|
return result;
|
|
}
|
|
}
|