List of usage examples for java.lang Character TYPE
Class TYPE
To view the source code for java.lang Character TYPE.
Click Source Link
From source file:Main.java
/** * Creates a class identifier of form Labc/abc;, from a Class. *//*from w w w. j a v a 2s .c om*/ 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 . java 2 s . co 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:PrimitiveUtils.java
public static Object read(String value, Class type) { Object ret = value;/*from w w w . java 2 s. co 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:com.swtxml.util.types.SimpleTypes.java
public static void addSimpleTypes(PropertyRegistry inj) { inj.add(new PropertyMatcher(Boolean.class, Boolean.TYPE), BOOLEAN); inj.add(new PropertyMatcher(Integer.class, Integer.TYPE), INTEGER); inj.add(new PropertyMatcher(Float.class, Float.TYPE), FLOAT); inj.add(new PropertyMatcher(Character.class, Character.TYPE), CHARACTER); inj.add(new PropertyMatcher(String.class), STRING); inj.add(new PropertyMatcher(int[].class), INT_ARRAY); }
From source file:Main.java
/** * This method parses the given value into the specified primitive or wrapper class. * @param clazz - primitive or wrapper class used to parse * @param value - string to be parsed/*from www . j a v a2s. c o m*/ * @return object of type clazz parsed from the string * @author Trisan Bepler */ public static Object toObject(Class<?> clazz, String value) { if (Boolean.TYPE == clazz) return Boolean.parseBoolean(value); if (Byte.TYPE == clazz) return Byte.parseByte(value); if (Short.TYPE == clazz) return Short.parseShort(value); if (Integer.TYPE == clazz) return Integer.parseInt(value); if (Long.TYPE == clazz) return Long.parseLong(value); if (Float.TYPE == clazz) return Float.parseFloat(value); if (Double.TYPE == clazz) return Double.parseDouble(value); if (Boolean.class == clazz) return Boolean.parseBoolean(value); if (Byte.class == clazz) return Byte.parseByte(value); if (Short.class == clazz) return Short.parseShort(value); if (Integer.class == clazz) return Integer.parseInt(value); if (Long.class == clazz) return Long.parseLong(value); if (Float.class == clazz) return Float.parseFloat(value); if (Double.class == clazz) return Double.parseDouble(value); if (Character.class == clazz) return value.charAt(0); if (Character.TYPE == clazz) return value.charAt(0); return value; }
From source file:nl.strohalm.cyclos.utils.csv.CSVWriter.java
/** * Creates a new instance//from w w w.j a v a 2 s . c om */ public static <E> CSVWriter<E> instance(final Class<E> elementClass, final LocalSettings localSettings) { final CSVWriter<E> writer = new CSVWriter<E>(elementClass); writer.setValueSeparator( CoercionHelper.coerce(Character.TYPE, localSettings.getCsvValueSeparator().getValue())); writer.setStringQuote(CoercionHelper.coerce(Character.TYPE, localSettings.getCsvStringQuote().getValue())); writer.setRowSeparator(localSettings.getCsvRecordSeparator().getValue()); writer.setUseHeader(localSettings.isCsvUseHeader()); return writer; }
From source file:nl.strohalm.cyclos.utils.csv.CSVReader.java
/** * Creates a new instance//from ww w . ja v a 2s . co m */ public static <E> CSVReader<E> instance(final Class<E> elementClass, final LocalSettings localSettings) { final CSVReader<E> reader = new CSVReader<E>(elementClass); reader.setValueSeparator( CoercionHelper.coerce(Character.TYPE, localSettings.getCsvValueSeparator().getValue())); reader.setStringQuote(CoercionHelper.coerce(Character.TYPE, localSettings.getCsvStringQuote().getValue())); return reader; }
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/*from www . j a v a 2s. c om*/ return null; }
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); }//from w ww. j a va 2 s. c o m return false; }
From source file:Main.java
public static String getPrimitiveLetter(Class<?> paramClass) { if (Integer.TYPE.equals(paramClass)) { return "I"; }/*from w w w . ja va 2 s .co m*/ if (Void.TYPE.equals(paramClass)) { return "V"; } if (Boolean.TYPE.equals(paramClass)) { return "Z"; } if (Character.TYPE.equals(paramClass)) { return "C"; } if (Byte.TYPE.equals(paramClass)) { return "B"; } if (Short.TYPE.equals(paramClass)) { return "S"; } if (Float.TYPE.equals(paramClass)) { return "F"; } if (Long.TYPE.equals(paramClass)) { return "J"; } if (Double.TYPE.equals(paramClass)) { return "D"; } throw new IllegalStateException("Type: " + paramClass.getCanonicalName() + " is not a primitive type"); }