import java.util.Arrays;
import java.util.HashMap;
public class ArbitraryArrays {
private static class Entry implements Comparable<Entry> {
Object o;
Class<?> c;
public Entry(Object o, Class<?> c) {
this.o = o;
this.c = c;
}
private static final HashMap<Class<?>, Integer> map = new HashMap<>();
static {
map.put(Byte.class, 0);
map.put(Short.class, 1);
map.put(Integer.class, 2);
map.put(Long.class, 3);
map.put(Float.class, 4);
map.put(Double.class, 5);
map.put(String.class, 6);
}
@Override
public int compareTo(ArbitraryArrays.Entry o) {
return map.get(c) - map.get(o.c);
}
}
public static String[] getSortedArray(String[] textArray) {
Entry[] a = getArray(textArray);
Arrays.sort(a);
String[] b = new String[a.length];
for (int i = 0; i < a.length; i++) {
b[i] = String.valueOf(a[i].o);
}
return b;
}
private static Entry[] getArray(String[] textArray) {
Entry[] a = new Entry[textArray.length];
for (int i = 0; i < textArray.length; i++) {
String s = textArray[i];
Object x = null;
l: for (int j = 0; j < 1; j++) {
try {
x = Byte.parseByte(s);
break l;
} catch (Exception e) {
}
try {
x = Short.parseShort(s);
break l;
} catch (Exception e) {
}
try {
x = Integer.parseInt(s);
break l;
} catch (Exception e) {
}
try {
x = Long.parseLong(s);
break l;
} catch (Exception e) {
}
try {
x = Float.parseFloat(s);
break l;
} catch (Exception e) {
}
try {
x = Double.parseDouble(s);
break l;
} catch (Exception e) {
}
}
if (x == null) {
a[i] = new Entry(s, s.getClass());
} else {
a[i] = new Entry(x, x.getClass());
}
}
return a;
}
public static void main(String[] args) {
String[] textArray = { "1", "Tiger", "§a2", "255", "Elefant", "32", "64!" };
System.out.println(Arrays.toString(textArray));
textArray = getSortedArray(textArray);
System.out.println(Arrays.toString(textArray));
}
}