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:com.puppycrawl.tools.checkstyle.api.AutomaticBean.java
/** * Creates a BeanUtilsBean that is configured to use * type converters that throw a ConversionException * instead of using the default value when something * goes wrong.// w w w . j a v a2 s .c om * * @return a configured BeanUtilsBean */ private static BeanUtilsBean createBeanUtilsBean() { final ConvertUtilsBean cub = new ConvertUtilsBean(); cub.register(new BooleanConverter(), Boolean.TYPE); cub.register(new BooleanConverter(), Boolean.class); cub.register(new ArrayConverter(boolean[].class, new BooleanConverter()), boolean[].class); cub.register(new ByteConverter(), Byte.TYPE); cub.register(new ByteConverter(), Byte.class); cub.register(new ArrayConverter(byte[].class, new ByteConverter()), byte[].class); cub.register(new CharacterConverter(), Character.TYPE); cub.register(new CharacterConverter(), Character.class); cub.register(new ArrayConverter(char[].class, new CharacterConverter()), char[].class); cub.register(new DoubleConverter(), Double.TYPE); cub.register(new DoubleConverter(), Double.class); cub.register(new ArrayConverter(double[].class, new DoubleConverter()), double[].class); cub.register(new FloatConverter(), Float.TYPE); cub.register(new FloatConverter(), Float.class); cub.register(new ArrayConverter(float[].class, new FloatConverter()), float[].class); cub.register(new IntegerConverter(), Integer.TYPE); cub.register(new IntegerConverter(), Integer.class); cub.register(new ArrayConverter(int[].class, new IntegerConverter()), int[].class); cub.register(new LongConverter(), Long.TYPE); cub.register(new LongConverter(), Long.class); cub.register(new ArrayConverter(long[].class, new LongConverter()), long[].class); cub.register(new ShortConverter(), Short.TYPE); cub.register(new ShortConverter(), Short.class); cub.register(new ArrayConverter(short[].class, new ShortConverter()), short[].class); cub.register(new RelaxedStringArrayConverter(), String[].class); // BigDecimal, BigInteger, Class, Date, String, Time, TimeStamp // do not use defaults in the default configuration of ConvertUtilsBean return new BeanUtilsBean(cub, new PropertyUtilsBean()); }
From source file:org.lunarray.model.descriptor.builder.annotation.util.RenderDefaultsUtil.java
/** * Fills the defaults./*from ww w .ja va 2 s .co m*/ */ private RenderDefaultsUtil() { this.renderDefaults = new HashMap<Class<?>, RenderType>(); this.renderDefaults.put(Calendar.class, RenderType.DATE_PICKER); this.renderDefaults.put(Date.class, RenderType.DATE_PICKER); this.renderDefaults.put(java.sql.Date.class, RenderType.DATE_PICKER); this.renderDefaults.put(String.class, RenderType.TEXT); this.renderDefaults.put(Integer.class, RenderType.TEXT); this.renderDefaults.put(Double.class, RenderType.TEXT); this.renderDefaults.put(Float.class, RenderType.TEXT); this.renderDefaults.put(Long.class, RenderType.TEXT); this.renderDefaults.put(Byte.class, RenderType.TEXT); this.renderDefaults.put(Short.class, RenderType.TEXT); this.renderDefaults.put(Character.class, RenderType.TEXT); this.renderDefaults.put(Integer.TYPE, RenderType.TEXT); this.renderDefaults.put(Double.TYPE, RenderType.TEXT); this.renderDefaults.put(Float.TYPE, RenderType.TEXT); this.renderDefaults.put(Long.TYPE, RenderType.TEXT); this.renderDefaults.put(Byte.TYPE, RenderType.TEXT); this.renderDefaults.put(Short.TYPE, RenderType.TEXT); this.renderDefaults.put(Character.TYPE, RenderType.TEXT); this.renderDefaults.put(BigDecimal.class, RenderType.TEXT); this.renderDefaults.put(BigInteger.class, RenderType.TEXT); this.renderDefaults.put(Boolean.class, RenderType.CHECKBOX); this.renderDefaults.put(Boolean.TYPE, RenderType.CHECKBOX); }
From source file:com.link_intersystems.lang.Conversions.java
/** * <em>java language specification - 5.1.2 Widening Primitive Conversion</em> * .//from w w w . j a v a 2 s .co m * * <code> * <blockquote>The following 19 specific conversions on primitive types * are called the widening primitive conversions: * <ul> * <li>byte to short, int, long, float, or double</li> * <li>short to int, long, float, or double</li> * <li>char to int, long, float, or double</li> * <li>int to long, float, or double</li> * <li>long to float or double</li> * <li>float to double</li> * </blockquote> * </code> * * @param from * the base type * @param to * the widening type * @return true if from to to is a primitive widening. * @since 1.0.0.0 */ public static boolean isPrimitiveWidening(Class<?> from, Class<?> to) { Assert.isTrue(Primitives.isPrimitive(from), PARAMETER_MUST_BE_A_PRIMITIVE, "form"); Assert.isTrue(Primitives.isPrimitive(to), PARAMETER_MUST_BE_A_PRIMITIVE, "to"); boolean isPrimitiveWidening = false; if (isIdentity(from, Byte.TYPE)) { isPrimitiveWidening = isPrimitiveByteWidening(to); } else if (isIdentity(from, Short.TYPE)) { isPrimitiveWidening = isPrimitiveShortWidening(to); } else if (isIdentity(from, Character.TYPE)) { isPrimitiveWidening = isPrimitiveCharacterWidening(to); } else if (isIdentity(from, Integer.TYPE)) { isPrimitiveWidening = isPrimitiveIntegerWidening(to); } else if (isIdentity(from, Long.TYPE)) { isPrimitiveWidening = isPrimitiveLongWidening(to); } else if (isIdentity(from, Float.TYPE)) { isPrimitiveWidening = isPrimitiveFloatWidening(to); } /* * must be a double - no widening available */ return isPrimitiveWidening; }
From source file:org.seasar.mayaa.impl.util.ObjectUtil.java
protected static Class loadPrimitiveClass(String className) { if (StringUtil.isEmpty(className)) { throw new IllegalArgumentException(); }/*from w w w. j a v a 2 s.c om*/ if ("short".equals(className)) { return Short.TYPE; } else if ("int".equals(className)) { return Integer.TYPE; } else if ("long".equals(className)) { return Long.TYPE; } else if ("float".equals(className)) { return Float.TYPE; } else if ("double".equals(className)) { return Double.TYPE; } else if ("byte".equals(className)) { return Byte.TYPE; } else if ("char".equals(className)) { return Character.TYPE; } else if ("boolean".equals(className)) { return Boolean.TYPE; } else if ("void".equals(className)) { return Void.TYPE; } return null; }
From source file:com.alibaba.doris.admin.service.impl.ValueParseUtil.java
/** * ?String ?:// www .j a v a2s . c o m * * <pre> * short, int, long, float : 0 * char, byte: 0 * String: null * Map, List: null * Integer, Long, Float : null * Date: null * array: null * </pre> * * @param strValue * @param clazz * @return */ @SuppressWarnings("unchecked") public static <T> T parseStringValue(String strValue, Class<T> clazz, boolean autoDefault) { if (DEF_NULL.equals(strValue)) { if (!clazz.isPrimitive()) { return null; } if (autoDefault) { return (T) getInternalDefaultValue(clazz); } else { return null; } } if (DEF_EMPTY.equals(strValue)) { if (clazz.isArray()) { return (T) Array.newInstance(clazz.getComponentType(), 0); } if (Map.class.isAssignableFrom(clazz)) { return (T) Collections.EMPTY_MAP; } if (List.class.isAssignableFrom(clazz)) { return (T) new ArrayList<Object>(); } if (Set.class.isAssignableFrom(clazz)) { return (T) new HashSet<Object>(); } if (String.class.equals(clazz)) { return (T) StringUtils.EMPTY; } if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) { return (T) Character.valueOf(' '); } if (autoDefault) { return (T) getInternalDefaultValue(clazz); } else { return null; } } if (StringUtils.isBlank(strValue)) {// ? if (autoDefault) { return (T) getInternalDefaultValue(clazz); } else { return null; } } else { if (String.class.equals(clazz)) { return (T) strValue; } if (Short.TYPE.equals(clazz) || Short.class.equals(clazz)) { return (T) Short.valueOf(strValue); } if (Integer.TYPE.equals(clazz) || Integer.class.equals(clazz)) { return (T) Integer.valueOf(strValue); } if (Long.TYPE.equals(clazz) || Long.class.equals(clazz)) { return (T) Long.valueOf(strValue); } if (Boolean.TYPE.equals(clazz) || Boolean.class.equals(clazz)) { return (T) Boolean.valueOf(strValue); } if (Float.TYPE.equals(clazz) || Float.class.equals(clazz)) { return (T) Float.valueOf(strValue); } if (Double.TYPE.equals(clazz) || Double.class.equals(clazz)) { return (T) Double.valueOf(strValue); } if (Byte.TYPE.equals(clazz) || Byte.class.equals(clazz)) { return (T) Byte.valueOf(strValue); } if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) { return (T) Character.valueOf(strValue.charAt(0)); } if (clazz.isArray()) { final Class<?> componentType = clazz.getComponentType(); // String[] if (String.class.equals(componentType)) { return (T) StringUtils.split(strValue, ','); } // ?char[] if (Character.TYPE.equals(componentType)) { return (T) strValue.toCharArray(); } if (Character.class.equals(componentType)) { final char[] tmp = strValue.toCharArray(); final Character[] result = new Character[tmp.length]; for (int i = 0; i < result.length; i++) { result[i] = tmp[i]; } return (T) result; } if (Byte.TYPE.equals(componentType) || Byte.class.equals(componentType)) { return (T) (strValue == null ? null : strValue.getBytes()); } } } return null; }
From source file:de.micromata.genome.util.bean.SoftCastPropertyUtilsBean.java
public Class<?> getWrappedClass(Class<?> target) { if (target.isPrimitive() == false) { return target; }/*from ww w . j av a 2s .c om*/ if (target == Integer.TYPE) { return Integer.class; } if (target == Long.TYPE) { return Long.class; } if (target == Byte.TYPE) { return Byte.class; } if (target == Short.TYPE) { return Short.class; } if (target == Float.TYPE) { return Short.class; } if (target == Double.TYPE) { return Double.class; } if (target == Character.TYPE) { return Character.class; } if (target == Boolean.TYPE) { return Boolean.class; } throw new RuntimeException("Unmapped basic type: " + target); }
From source file:org.wings.template.DefaultPropertyValueConverter.java
/** * Describe <code>convertPropertyValue</code> method here. * * @param value an <code>Object</code> value * @param targetClass a <code>Class</code> value * @return <description>//from w w w.ja v a2 s.c om * @throws UnsupportedOperationException if an error occurs * @throws java.lang.UnsupportedOperationException * <description> */ public Object convertPropertyValue(String value, Class targetClass) throws UnsupportedOperationException { if (value == null || "null".equals(value)) { return null; } // end of if () if (targetClass == String.class) { return value; } // end of if () if (targetClass == Boolean.TYPE || targetClass == Boolean.class) { return Boolean.valueOf(value); } if (targetClass == Integer.TYPE || targetClass == Integer.class) { return Integer.valueOf(value); } if (targetClass == Long.TYPE || targetClass == Long.class) { return Long.valueOf(value); } if (targetClass == Short.TYPE || targetClass == Short.class) { return Short.valueOf(value); } if (targetClass == Byte.TYPE || targetClass == Byte.class) { return Byte.valueOf(value); } if (targetClass == Float.TYPE || targetClass == Float.class) { return Float.valueOf(value); } if (targetClass == Double.TYPE || targetClass == Double.class) { return Double.valueOf(value); } if (targetClass == Character.TYPE || targetClass == Character.class) { return new Character(value.charAt(0)); } if (targetClass == StringBuffer.class) { return new StringBuffer(value); } // end of if () if (SIcon.class.isAssignableFrom(targetClass)) { return ResourceFactory.makeIcon(value); } if (targetClass == Color.class) { return ResourceFactory.makeColor(value); } if (targetClass == SDimension.class) { return ResourceFactory.makeDimension(value); } if (targetClass == SFont.class) { return TemplateUtil.parseFont(value); } if (Resource.class.isAssignableFrom(targetClass)) { return new ClassPathResource(value); } if (CSSAttributeSet.class.isAssignableFrom(targetClass)) { return ResourceFactory.makeAttributeSet(value); } if (StyleSheet.class.isAssignableFrom(targetClass)) { StyleSheet result; try { CSSStyleSheet styleSheet = new CSSStyleSheet(); InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(value); styleSheet.read(in); in.close(); result = styleSheet; } catch (Exception e) { log.warn("Exception", e); result = null; } return result; } if (ComponentCG.class.isAssignableFrom(targetClass)) { return ResourceFactory.makeComponentCG(value); } throw new UnsupportedOperationException("cannot create object of type " + targetClass.getName()); }
From source file:org.kordamp.ezmorph.primitive.CharMorpher.java
public Class<?> morphsTo() { return Character.TYPE; }
From source file:foundation.stack.datamill.configuration.impl.Classes.java
public static boolean isAssignable(Class<?> clazz, final Class<?> toClass) { if (toClass == null) { return false; }/* w w w.j av a 2 s . c o m*/ if (clazz == null) { return !toClass.isPrimitive(); } if (clazz.isPrimitive() && !toClass.isPrimitive()) { clazz = primitiveToWrapper(clazz); if (clazz == null) { return false; } } if (toClass.isPrimitive() && !clazz.isPrimitive()) { clazz = wrapperToPrimitive(clazz); if (clazz == null) { return false; } } if (clazz.equals(toClass)) { return true; } if (clazz.isPrimitive()) { if (!toClass.isPrimitive()) { return false; } if (Integer.TYPE.equals(clazz)) { return Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Long.TYPE.equals(clazz)) { return Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Boolean.TYPE.equals(clazz)) { return false; } if (Double.TYPE.equals(clazz)) { return false; } if (Float.TYPE.equals(clazz)) { return Double.TYPE.equals(toClass); } if (Character.TYPE.equals(clazz)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Short.TYPE.equals(clazz)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Byte.TYPE.equals(clazz)) { return Short.TYPE.equals(toClass) || Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } // should never get here return false; } return toClass.isAssignableFrom(clazz); }
From source file:cc.aileron.accessor.TypeConvertorImpl.java
@Override public Object convert(final Object value, final Class<?> from, final Class<?> to) { /*/*from w w w . j a va 2 s. co m*/ * to boolean */ if (Boolean.class.isAssignableFrom(to) || to == Boolean.TYPE) { if (value == null) { return false; } if (Boolean.class.isAssignableFrom(from) || Boolean.TYPE == from) { return value; } if (Number.class.isAssignableFrom(from) || from.isPrimitive()) { return ((Number) value).intValue() != 0; } if (BooleanGetAccessor.class.isAssignableFrom(from)) { final BooleanGetAccessor accessor = (BooleanGetAccessor) value; return accessor.toBoolean(); } if (String.class == from) { return Boolean.parseBoolean(String.class.cast(value)); } return true; } /* * to primitive is null */ if (to.isPrimitive() && value == null) { return 0; } /* * value is null */ if (value == null) { return null; } /* * to primitive from string */ if (to.isPrimitive() && String.class == from) { if (StringUtils.isEmpty((String) value)) { return 0; } final Integer number = Integer.valueOf((String) value); return numberToPrimitive(number, to); } /* * to primitive from number */ if (to.isPrimitive() && Number.class.isAssignableFrom(from)) { final Number number = (Number) value; return numberToPrimitive(number, to); } /* * to number from string */ if (Number.class.isAssignableFrom(to) && String.class == from) { final String string = (String) value; if (Boolean.TYPE == to) { return Boolean.parseBoolean(string); } if (Character.TYPE == to) { throw new UnsupportedOperationException(); } final Number number = Integer.valueOf(string); return numberToPrimitive(number, to); } /* * to number from number-get-accessor */ if (Number.class.isAssignableFrom(to) && value instanceof NumberGetAccessor) { final NumberGetAccessor accessor = (NumberGetAccessor) value; return accessor.toNumber(); } /* * to string from not string */ if (to == String.class && !(value instanceof String)) { return value.toString(); } return value; }