List of usage examples for java.lang Byte TYPE
Class TYPE
To view the source code for java.lang Byte TYPE.
Click Source Link
From source file:PrimitiveUtils.java
public static Object read(String value, Class type) { Object ret = value;// ww w. j a va 2 s . c o m if (Integer.TYPE.equals(type)) { ret = Integer.valueOf(value); } if (Byte.TYPE.equals(type)) { ret = Byte.valueOf(value); } if (Short.TYPE.equals(type)) { ret = Short.valueOf(value); } if (Long.TYPE.equals(type)) { ret = Long.valueOf(value); } if (Float.TYPE.equals(type)) { ret = Float.valueOf(value); } if (Double.TYPE.equals(type)) { ret = Double.valueOf(value); } if (Boolean.TYPE.equals(type)) { ret = Boolean.valueOf(value); } if (Character.TYPE.equals(type)) { ret = value.charAt(0); } // TODO others. return ret; }
From source file:Main.java
/** * Creates a class identifier of form Labc/abc;, from a Class. *//* w w w.j a v a 2 s . c o m*/ public static String ci(Class n) { if (n.isArray()) { n = n.getComponentType(); if (n.isPrimitive()) { if (n == Byte.TYPE) { return "[B"; } else if (n == Boolean.TYPE) { return "[Z"; } else if (n == Short.TYPE) { return "[S"; } else if (n == Character.TYPE) { return "[C"; } else if (n == Integer.TYPE) { return "[I"; } else if (n == Float.TYPE) { return "[F"; } else if (n == Double.TYPE) { return "[D"; } else if (n == Long.TYPE) { return "[J"; } else { throw new RuntimeException("Unrecognized type in compiler: " + n.getName()); } } else { return "[" + ci(n); } } else { if (n.isPrimitive()) { if (n == Byte.TYPE) { return "B"; } else if (n == Boolean.TYPE) { return "Z"; } else if (n == Short.TYPE) { return "S"; } else if (n == Character.TYPE) { return "C"; } else if (n == Integer.TYPE) { return "I"; } else if (n == Float.TYPE) { return "F"; } else if (n == Double.TYPE) { return "D"; } else if (n == Long.TYPE) { return "J"; } else if (n == Void.TYPE) { return "V"; } else { throw new RuntimeException("Unrecognized type in compiler: " + n.getName()); } } else { return "L" + p(n) + ";"; } } }
From source file:org.mule.util.ArrayUtils.java
/** * Like {@link #toString(Object)} but considers at most <code>maxElements</code> * values; overflow is indicated by an appended "[..]" ellipsis. *//*from www . j a va 2s .c o m*/ public static String toString(Object array, int maxElements) { String result; Class componentType = array.getClass().getComponentType(); if (Object.class.isAssignableFrom(componentType)) { result = ArrayUtils.toString((ArrayUtils.subarray((Object[]) array, 0, maxElements))); } else if (componentType.equals(Boolean.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((boolean[]) array, 0, maxElements))); } else if (componentType.equals(Byte.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((byte[]) array, 0, maxElements))); } else if (componentType.equals(Character.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((char[]) array, 0, maxElements))); } else if (componentType.equals(Short.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((short[]) array, 0, maxElements))); } else if (componentType.equals(Integer.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((int[]) array, 0, maxElements))); } else if (componentType.equals(Long.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((long[]) array, 0, maxElements))); } else if (componentType.equals(Float.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((float[]) array, 0, maxElements))); } else if (componentType.equals(Double.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((double[]) array, 0, maxElements))); } else { throw new IllegalArgumentException("Unknown array service type: " + componentType.getName()); } if (Array.getLength(array) > maxElements) { StringBuffer buf = new StringBuffer(result); buf.insert(buf.length() - 1, " [..]"); result = buf.toString(); } return result; }
From source file:Main.java
/** * Finds a set of constant static byte field declarations in the class that have the given value * and whose name match the given pattern * @param cl class to search in//from w w w .j a va 2s. c o m * @param value value of constant static byte field declarations to match * @param regexPattern pattern to match against the name of the field * @return a set of the names of fields, expressed as a string */ private static String findConstByteInClass(Class<?> cl, byte value, String regexPattern) { Field[] fields = cl.getDeclaredFields(); Set<String> fieldSet = new HashSet<String>(); for (Field f : fields) { try { if (f.getType() == Byte.TYPE && (f.getModifiers() & Modifier.STATIC) != 0 && f.getName().matches(regexPattern) && f.getByte(null) == value) { fieldSet.add(f.getName()); } } catch (IllegalArgumentException e) { // ignore } catch (IllegalAccessException e) { // ignore } } return fieldSet.toString(); }
From source file:Main.java
public static boolean isConvertible(Class<?> srcPrimitive, Class<?> tgtPrimitive) { if (Boolean.TYPE.equals(srcPrimitive)) { return Boolean.TYPE.equals(tgtPrimitive); } else if (Byte.TYPE.equals(tgtPrimitive)) { return Byte.TYPE.equals(tgtPrimitive) || Short.TYPE.equals(tgtPrimitive) || Integer.TYPE.equals(tgtPrimitive) || Long.TYPE.equals(tgtPrimitive) || Float.TYPE.equals(tgtPrimitive) || Double.TYPE.equals(tgtPrimitive); } else if (Character.TYPE.equals(srcPrimitive)) { return Character.TYPE.equals(tgtPrimitive) || Integer.TYPE.equals(tgtPrimitive) || Long.TYPE.equals(tgtPrimitive) || Float.TYPE.equals(tgtPrimitive) || Double.TYPE.equals(tgtPrimitive); } else if (Double.TYPE.equals(srcPrimitive)) { return Double.TYPE.equals(tgtPrimitive); } else if (Float.TYPE.equals(srcPrimitive)) { return Float.TYPE.equals(tgtPrimitive) || Double.TYPE.equals(tgtPrimitive); } else if (Integer.TYPE.equals(srcPrimitive)) { return Integer.TYPE.equals(tgtPrimitive) || Long.TYPE.equals(tgtPrimitive) || Float.TYPE.equals(tgtPrimitive) || Double.TYPE.equals(tgtPrimitive); } else if (Long.TYPE.equals(srcPrimitive)) { return Long.TYPE.equals(tgtPrimitive) || Float.TYPE.equals(tgtPrimitive) || Double.TYPE.equals(tgtPrimitive); } else if (Short.TYPE.equals(srcPrimitive)) { return Short.TYPE.equals(tgtPrimitive) || Integer.TYPE.equals(tgtPrimitive) || Long.TYPE.equals(tgtPrimitive) || Float.TYPE.equals(tgtPrimitive) || Double.TYPE.equals(tgtPrimitive); }//ww w .ja va 2s . c om return false; }
From source file:sim.portrayal.inspector.TimeSeriesChartingPropertyInspector.java
public static Class[] types() { return new Class[] { Number.class, Boolean.TYPE, Byte.TYPE, Short.TYPE, Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE, Valuable.class }; }
From source file:Main.java
private static Class<?> getPrimitive(Class<?> argClass) { if (argClass == Boolean.class) return Boolean.TYPE; else if (argClass == Character.class) return Character.TYPE; else if (argClass == Byte.class) return Byte.TYPE; else if (argClass == Short.class) return Short.TYPE; else if (argClass == Integer.class) return Integer.TYPE; else if (argClass == Long.class) return Long.TYPE; else if (argClass == Float.class) return Float.TYPE; else if (argClass == Double.class) return Double.TYPE; else// w ww. java2 s .co m return null; }
From source file:org.jtwig.util.ArrayUtil.java
public static Object[] toArray(Object obj) { if (!obj.getClass().isArray()) { throw new IllegalArgumentException("Argument is not an array"); }//from w w w.j ava2 s . c o m Class<?> type = obj.getClass().getComponentType(); if (!type.isPrimitive()) { return (Object[]) obj; } if (Byte.TYPE.isAssignableFrom(type)) { return toArray((byte[]) obj); } if (Short.TYPE.isAssignableFrom(type)) { return toArray((short[]) obj); } if (Integer.TYPE.isAssignableFrom(obj.getClass().getComponentType())) { return toArray((int[]) obj); } if (Long.TYPE.isAssignableFrom(obj.getClass().getComponentType())) { return toArray((long[]) obj); } if (Boolean.TYPE.isAssignableFrom(obj.getClass().getComponentType())) { return toArray((boolean[]) obj); } if (Character.TYPE.isAssignableFrom(obj.getClass().getComponentType())) { return toArray((char[]) obj); } if (Float.TYPE.isAssignableFrom(obj.getClass().getComponentType())) { return toArray((float[]) obj); } if (Double.TYPE.isAssignableFrom(obj.getClass().getComponentType())) { return toArray((double[]) obj); } throw new IllegalArgumentException("Unsupported argument type: " + type.getName()); }
From source file:com.autonomy.aci.client.annotations.ConversionServiceImpl.java
public ConversionServiceImpl() { registerConverter(new StringToDoubleConverter(), String.class, Double.class); registerConverter(new StringToDoubleConverter(), String.class, Double.TYPE); registerConverter(new StringToByteConverter(), String.class, Byte.class); registerConverter(new StringToByteConverter(), String.class, Byte.TYPE); registerConverter(new StringToIntegerConverter(), String.class, Integer.class); registerConverter(new StringToIntegerConverter(), String.class, Integer.TYPE); registerConverter(new StringToFloatConverter(), String.class, Float.class); registerConverter(new StringToFloatConverter(), String.class, Float.TYPE); registerConverter(new StringToShortConverter(), String.class, Short.class); registerConverter(new StringToShortConverter(), String.class, Short.TYPE); registerConverter(new StringToCharacterConverter(), String.class, Character.class); registerConverter(new StringToCharacterConverter(), String.class, Character.TYPE); registerConverter(new StringToBooleanConverter(), String.class, Boolean.class); registerConverter(new StringToBooleanConverter(), String.class, Boolean.TYPE); registerConverter(new StringToLongConverter(), String.class, Long.class); registerConverter(new StringToLongConverter(), String.class, Long.TYPE); }
From source file:com.alibaba.doris.admin.service.impl.ValueParseUtil.java
/** * ?,?,//from w w w. j a v a2 s .c o m * * @param clazz * @return */ @SuppressWarnings("unchecked") private static <T> T getInternalDefaultValue(Class<T> clazz) { if (!clazz.isPrimitive()) { return null; } if (Short.TYPE.equals(clazz)) { return (T) Short.valueOf((short) 0); } if (Integer.TYPE.equals(clazz)) { return (T) Integer.valueOf(0); } if (Long.TYPE.equals(clazz)) { return (T) Long.valueOf(0); } if (Boolean.TYPE.equals(clazz)) { return (T) Boolean.valueOf(false); } if (Float.TYPE.equals(clazz)) { return (T) Float.valueOf(0); } if (Double.TYPE.equals(clazz)) { return (T) Double.valueOf(0); } if (Byte.TYPE.equals(clazz)) { return (T) Byte.valueOf((byte) 0); } if (Character.TYPE.equals(clazz)) { return (T) Character.valueOf('\0'); } return null; }