Example usage for java.lang Byte TYPE

List of usage examples for java.lang Byte TYPE

Introduction

In this page you can find the example usage for java.lang Byte TYPE.

Prototype

Class TYPE

To view the source code for java.lang Byte TYPE.

Click Source Link

Document

The Class instance representing the primitive type byte .

Usage

From source file:demo.config.PropertyConverter.java

/**
 * Converts the specified value to the target class. If the class is a
 * primitive type (Integer.TYPE, Boolean.TYPE, etc) the value returned will
 * use the wrapper type (Integer.class, Boolean.class, etc).
 * //from w w w. j a va 2s  .  c o m
 * @param cls
 *            the target class of the converted value
 * @param value
 *            the value to convert
 * @param params
 *            optional parameters used for the conversion
 * @return the converted value
 * @throws ConversionException
 *             if the value is not compatible with the requested type
 * 
 * @since 1.5
 */
static Object to(Class<?> cls, Object value, Object[] params) throws ConversionException {
    if (cls.isInstance(value)) {
        return value; // no conversion needed
    }

    if (Boolean.class.equals(cls) || Boolean.TYPE.equals(cls)) {
        return toBoolean(value);
    } else if (Character.class.equals(cls) || Character.TYPE.equals(cls)) {
        return toCharacter(value);
    } else if (Number.class.isAssignableFrom(cls) || cls.isPrimitive()) {
        if (Integer.class.equals(cls) || Integer.TYPE.equals(cls)) {
            return toInteger(value);
        } else if (Long.class.equals(cls) || Long.TYPE.equals(cls)) {
            return toLong(value);
        } else if (Byte.class.equals(cls) || Byte.TYPE.equals(cls)) {
            return toByte(value);
        } else if (Short.class.equals(cls) || Short.TYPE.equals(cls)) {
            return toShort(value);
        } else if (Float.class.equals(cls) || Float.TYPE.equals(cls)) {
            return toFloat(value);
        } else if (Double.class.equals(cls) || Double.TYPE.equals(cls)) {
            return toDouble(value);
        } else if (BigInteger.class.equals(cls)) {
            return toBigInteger(value);
        } else if (BigDecimal.class.equals(cls)) {
            return toBigDecimal(value);
        }
    } else if (Date.class.equals(cls)) {
        return toDate(value, (String) params[0]);
    } else if (Calendar.class.equals(cls)) {
        return toCalendar(value, (String) params[0]);
    } else if (URL.class.equals(cls)) {
        return toURL(value);
    } else if (Locale.class.equals(cls)) {
        return toLocale(value);
    } else if (isEnum(cls)) {
        return convertToEnum(cls, value);
    } else if (Color.class.equals(cls)) {
        return toColor(value);
    } else if (cls.getName().equals(INTERNET_ADDRESS_CLASSNAME)) {
        return toInternetAddress(value);
    } else if (InetAddress.class.isAssignableFrom(cls)) {
        return toInetAddress(value);
    }

    throw new ConversionException("The value '" + value + "' (" + value.getClass() + ")"
            + " can't be converted to a " + cls.getName() + " object");
}

From source file:org.openflexo.antar.binding.TypeUtils.java

public static Class toPrimitive(Class<?> aClass) {
    if (isDouble(aClass)) {
        return Double.TYPE;
    }/*w  ww .ja v a  2 s . c  o  m*/
    if (isFloat(aClass)) {
        return Float.TYPE;
    }
    if (isLong(aClass)) {
        return Long.TYPE;
    }
    if (isInteger(aClass)) {
        return Integer.TYPE;
    }
    if (isShort(aClass)) {
        return Short.TYPE;
    }
    if (isByte(aClass)) {
        return Byte.TYPE;
    }
    if (isBoolean(aClass)) {
        return Boolean.TYPE;
    }
    if (isChar(aClass)) {
        return Character.TYPE;
    }
    return aClass;
}

From source file:MethodHashing.java

static String getTypeString(Class cl) {
    if (cl == Byte.TYPE) {
        return "B";
    } else if (cl == Character.TYPE) {
        return "C";
    } else if (cl == Double.TYPE) {
        return "D";
    } else if (cl == Float.TYPE) {
        return "F";
    } else if (cl == Integer.TYPE) {
        return "I";
    } else if (cl == Long.TYPE) {
        return "J";
    } else if (cl == Short.TYPE) {
        return "S";
    } else if (cl == Boolean.TYPE) {
        return "Z";
    } else if (cl == Void.TYPE) {
        return "V";
    } else if (cl.isArray()) {
        return "[" + getTypeString(cl.getComponentType());
    } else {/* w  ww  . jav  a  2 s  .c om*/
        return "L" + cl.getName().replace('.', '/') + ";";
    }
}

From source file:com.github.jknack.handlebars.helper.MethodHelper.java

/**
 * Wrap (if possible) a primitive type to their wrapper.
 *
 * @param type The candidate type.//from   www.  j  a va2 s.  c  o m
 * @return A wrapper for the primitive type or the original type.
 */
private static Class<?> wrap(final Class<?> type) {
    if (type.isPrimitive()) {
        if (type == Integer.TYPE) {
            return Integer.class;
        } else if (type == Boolean.TYPE) {
            return Boolean.class;
        } else if (type == Character.TYPE) {
            return Character.class;
        } else if (type == Double.TYPE) {
            return Double.class;
        } else if (type == Long.TYPE) {
            return Long.class;
        } else if (type == Float.TYPE) {
            return Float.class;
        } else if (type == Short.TYPE) {
            return Short.class;
        } else if (type == Byte.TYPE) {
            return Byte.class;
        }
    }
    return type;
}

From source file:org.spring4gwt.server.RpcHelper.java

private static String printTypeName(Class<?> type) {
    // Primitives
    ///*  w w  w  . ja v a  2 s  .co  m*/
    if (type.equals(Integer.TYPE)) {
        return "int";
    } else if (type.equals(Long.TYPE)) {
        return "long";
    } else if (type.equals(Short.TYPE)) {
        return "short";
    } else if (type.equals(Byte.TYPE)) {
        return "byte";
    } else if (type.equals(Character.TYPE)) {
        return "char";
    } else if (type.equals(Boolean.TYPE)) {
        return "boolean";
    } else if (type.equals(Float.TYPE)) {
        return "float";
    } else if (type.equals(Double.TYPE)) {
        return "double";
    }

    // Arrays
    //
    if (type.isArray()) {
        Class<?> componentType = type.getComponentType();
        return printTypeName(componentType) + "[]";
    }

    // Everything else
    //
    return type.getName().replace('$', '.');
}

From source file:com.alibaba.doris.admin.service.impl.ValueParseUtil.java

/**
 * ?String ?://from w ww  .  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:org.briljantframework.data.Na.java

/**
 * Returns the {@code NA} value for the class {@code T}. For reference types (excluding
 * {@link Complex} and {@link Logical}) {@code NA} is represented as {@code null}, but for
 * primitive types a special convention is used.
 *
 * <ul>//from  w ww .j a  v  a2  s  .  com
 * <li>{@code double}: {@link Na#DOUBLE}</li>
 * <li>{@code int}: {@link Na#INT}</li>
 * <li>{@code long}: {@link Long#MAX_VALUE}</li>
 * <li>{@link Logical}: {@link Logical#NA}</li>
 * <li>{@link Complex}: {@link Na#COMPLEX}</li>
 * </ul>
 *
 * @param cls the class
 * @param <T> the type of {@code cls}
 * @return a {@code NA} value of type {@code T}
 */
@SuppressWarnings("unchecked")
public static <T> T of(Class<T> cls) {
    if (cls == null) {
        return null;
    } else if (Double.class.equals(cls) || Double.TYPE.equals(cls)) {
        return (T) BOXED_DOUBLE;
    } else if (Float.class.equals(cls) || Float.TYPE.equals(cls)) {
        return (T) BOXED_FLOAT;
    } else if (Long.class.equals(cls) || Long.TYPE.equals(cls)) {
        return (T) BOXED_LONG;
    } else if (Integer.class.equals(cls) || Integer.TYPE.equals(cls)) {
        return (T) BOXED_INT;
    } else if (Short.class.equals(cls) || Short.TYPE.equals(cls)) {
        return (T) BOXED_SHORT;
    } else if (Byte.class.equals(cls) || Byte.TYPE.equals(cls)) {
        return (T) BOXED_BYTE;
    } else if (Character.class.equals(cls) || Character.TYPE.equals(cls)) {
        return (T) BOXED_CHAR;
    } else if (Logical.class.equals(cls)) {
        return (T) Logical.NA;
    } else if (Complex.class.equals(cls)) {
        return (T) COMPLEX;
    } else {
        return null;
    }
}

From source file:org.apache.click.util.RequestTypeConverter.java

/**
 * Return the converted value for the given value object and target type.
 *
 * @param value the value object to convert
 * @param toType the target class type to convert the value to
 * @return a converted value into the specified type
 *//*from  ww  w  .ja  va  2 s  . co m*/
protected Object convertValue(Object value, Class<?> toType) {
    Object result = null;

    if (value != null) {

        // If array -> array then convert components of array individually
        if (value.getClass().isArray() && toType.isArray()) {
            Class<?> componentType = toType.getComponentType();

            result = Array.newInstance(componentType, Array.getLength(value));

            for (int i = 0, icount = Array.getLength(value); i < icount; i++) {
                Array.set(result, i, convertValue(Array.get(value, i), componentType));
            }

        } else {
            if ((toType == Integer.class) || (toType == Integer.TYPE)) {
                result = Integer.valueOf((int) OgnlOps.longValue(value));

            } else if ((toType == Double.class) || (toType == Double.TYPE)) {
                result = new Double(OgnlOps.doubleValue(value));

            } else if ((toType == Boolean.class) || (toType == Boolean.TYPE)) {
                result = Boolean.valueOf(value.toString());

            } else if ((toType == Byte.class) || (toType == Byte.TYPE)) {
                result = Byte.valueOf((byte) OgnlOps.longValue(value));

            } else if ((toType == Character.class) || (toType == Character.TYPE)) {
                result = Character.valueOf((char) OgnlOps.longValue(value));

            } else if ((toType == Short.class) || (toType == Short.TYPE)) {
                result = Short.valueOf((short) OgnlOps.longValue(value));

            } else if ((toType == Long.class) || (toType == Long.TYPE)) {
                result = Long.valueOf(OgnlOps.longValue(value));

            } else if ((toType == Float.class) || (toType == Float.TYPE)) {
                result = new Float(OgnlOps.doubleValue(value));

            } else if (toType == BigInteger.class) {
                result = OgnlOps.bigIntValue(value);

            } else if (toType == BigDecimal.class) {
                result = bigDecValue(value);

            } else if (toType == String.class) {
                result = OgnlOps.stringValue(value);

            } else if (toType == java.util.Date.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.util.Date(time);
                }

            } else if (toType == java.sql.Date.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.sql.Date(time);
                }

            } else if (toType == java.sql.Time.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.sql.Time(time);
                }

            } else if (toType == java.sql.Timestamp.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.sql.Timestamp(time);
                }
            }
        }

    } else {
        if (toType.isPrimitive()) {
            result = OgnlRuntime.getPrimitiveDefaultValue(toType);
        }
    }
    return result;
}

From source file:com.l2jfree.config.L2Properties.java

@SuppressWarnings("unchecked")
public Object getProperty(Class<?> expectedType, ConfigProperty configProperty) {
    final String name = configProperty.name();
    final String defaultValue = configProperty.value();

    if (expectedType == Boolean.class || expectedType == Boolean.TYPE) {
        return getBool(name, defaultValue);
    } else if (expectedType == Long.class || expectedType == Long.TYPE) {
        return getLong(name, defaultValue);
    } else if (expectedType == Integer.class || expectedType == Integer.TYPE) {
        return getInteger(name, defaultValue);
    } else if (expectedType == Short.class || expectedType == Short.TYPE) {
        return getShort(name, defaultValue);
    } else if (expectedType == Byte.class || expectedType == Byte.TYPE) {
        return getByte(name, defaultValue);
    } else if (expectedType == Double.class || expectedType == Double.TYPE) {
        return getDouble(name, defaultValue);
    } else if (expectedType == Float.class || expectedType == Float.TYPE) {
        return getFloat(name, defaultValue);
    } else if (expectedType == String.class) {
        return getString(name, defaultValue);
    } else if (expectedType.isEnum()) {
        return getEnum(name, (Class<? extends Enum>) expectedType, defaultValue);
    } else {//from ww  w. ja  v  a 2s. c  o  m
        throw new IllegalStateException();
    }
}

From source file:cc.aileron.accessor.TypeConvertorImpl.java

/**
 * default constractor/*from w  w  w . j  av a 2s  .c o m*/
 */
@Inject
public TypeConvertorImpl() {
    map.put(Boolean.TYPE, new C() {
        @Override
        public Boolean convert(final java.lang.Number number) {
            return number.intValue() != 0;
        }
    });
    map.put(Byte.TYPE, new C() {

        @Override
        public Byte convert(final java.lang.Number number) {
            return number.byteValue();
        }
    });
    map.put(Short.TYPE, new C() {

        @Override
        public Short convert(final java.lang.Number number) {
            return number.shortValue();
        }
    });
    map.put(Integer.TYPE, new C() {
        @Override
        public Integer convert(final java.lang.Number number) {
            return number.intValue();
        }

    });
    map.put(Long.TYPE, new C() {

        @Override
        public Long convert(final java.lang.Number number) {
            return number.longValue();
        }
    });
    map.put(Float.TYPE, new C() {

        @Override
        public Float convert(final java.lang.Number number) {
            return number.floatValue();
        }
    });
    map.put(Double.TYPE, new C() {

        @Override
        public Double convert(final java.lang.Number number) {
            return number.doubleValue();
        }
    });
}