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:de.micromata.genome.util.strings.converter.StandardStringConverter.java

@Override
public char getTypeChar(Object value) {
    if (value == null) {
        return ConvertedStringTypes.NULL.getShortType();
    }/*from  ww  w.j a v  a2s.  c o  m*/
    Class<?> cls = value.getClass();

    if (value instanceof String) {
        return ConvertedStringTypes.STRING.getShortType();
    }

    Class<?> vclass = value.getClass();

    if (value instanceof Boolean || vclass == Boolean.TYPE) {
        return ConvertedStringTypes.BOOLEAN.getShortType();
    }
    if (value instanceof Byte || vclass == Byte.TYPE) {
        return ConvertedStringTypes.BYTE.getShortType();
    }
    if (value instanceof Short || vclass == Short.TYPE) {
        return ConvertedStringTypes.SHORT.getShortType();
    }
    if (value instanceof Integer || vclass == Integer.TYPE) {
        return ConvertedStringTypes.INTEGER.getShortType();
    }
    if (value instanceof Long || vclass == Long.TYPE) {
        return ConvertedStringTypes.LONG.getShortType();
    }
    if (value instanceof Float || vclass == Float.TYPE) {
        return ConvertedStringTypes.FLOAT.getShortType();
    }
    if (value instanceof Double || vclass == Double.TYPE) {
        return ConvertedStringTypes.DOUBLE.getShortType();
    }
    if (value instanceof Character || vclass == Character.TYPE) {
        return ConvertedStringTypes.CHAR.getShortType();
    }
    if (value instanceof Date) {
        return ConvertedStringTypes.DATE.getShortType();
    }
    if (value instanceof BigDecimal) {
        return ConvertedStringTypes.BIGDECIMAL.getShortType();
    }
    if (value instanceof Character) {
        return ConvertedStringTypes.CHAR.getShortType();
    }
    if (value instanceof byte[]) {
        return ConvertedStringTypes.BYTEARRAY.getShortType();
    }
    if (value instanceof String[]) {
        return ConvertedStringTypes.STRINGARRAY.getShortType();
    }
    if (value instanceof Long[]) {
        return ConvertedStringTypes.LONGARRAY.getShortType();
    }

    // if (value instanceof Serializable)
    // return ConvertedStringTypes.XMLOBJECT;
    return ConvertedStringTypes.CUSTOM.getShortType();
}

From source file:org.kuali.rice.krad.util.DataTypeUtil.java

/**
 * Determines if the given class is enough like a "long" to store values of it as a SearchableAttributeLongValue
 * @param type the class to determine the type of
 * @return true if it is like a "long", false otherwise
 *//*from  ww  w .ja va2 s.  com*/
public static boolean isIntsy(Class<?> type) {
    return java.lang.Integer.class.isAssignableFrom(type) || java.lang.Long.class.isAssignableFrom(type)
            || java.lang.Short.class.isAssignableFrom(type) || java.lang.Byte.class.isAssignableFrom(type)
            || java.math.BigInteger.class.isAssignableFrom(type) || type.equals(Integer.TYPE)
            || type.equals(Long.TYPE) || type.equals(Short.TYPE) || type.equals(Byte.TYPE);
}

From source file:org.kordamp.ezmorph.primitive.ByteMorpher.java

public Class<?> morphsTo() {
    return Byte.TYPE;
}

From source file:org.kordamp.ezmorph.object.NumberMorpher.java

/**
 * Creates a new morpher for the target type with a default value.<br>
 * The defaultValue should be of the same class as the target type.
 *
 * @param type         must be a primitive or wrapper type. BigDecimal and BigInteger
 *                     are also supported.
 * @param defaultValue return value if the value to be morphed is null
 *//*from   w  w w. j  ava2 s .  c om*/
public NumberMorpher(Class type, Number defaultValue) {
    super(true);

    if (type == null) {
        throw new MorphException("Must specify a type");
    }

    if (type != Byte.TYPE && type != Short.TYPE && type != Integer.TYPE && type != Long.TYPE
            && type != Float.TYPE && type != Double.TYPE && !Byte.class.isAssignableFrom(type)
            && !Short.class.isAssignableFrom(type) && !Integer.class.isAssignableFrom(type)
            && !Long.class.isAssignableFrom(type) && !Float.class.isAssignableFrom(type)
            && !Double.class.isAssignableFrom(type) && !BigInteger.class.isAssignableFrom(type)
            && !BigDecimal.class.isAssignableFrom(type)) {
        throw new MorphException("Must specify a Number subclass");
    }

    if (defaultValue != null && !type.isInstance(defaultValue)) {
        throw new MorphException("Default value must be of type " + type);
    }

    this.type = type;
    setDefaultValue(defaultValue);
}

From source file:be.fedict.eid.applet.service.impl.tlv.TlvParser.java

private static <T> T parseThrowing(byte[] file, Class<T> tlvClass) throws InstantiationException,
        IllegalAccessException, DataConvertorException, UnsupportedEncodingException {
    Field[] fields = tlvClass.getDeclaredFields();
    Map<Integer, Field> tlvFields = new HashMap<Integer, Field>();
    for (Field field : fields) {
        TlvField tlvFieldAnnotation = field.getAnnotation(TlvField.class);
        if (null == tlvFieldAnnotation) {
            continue;
        }/*from w  w  w.j  a  va 2s  . c om*/
        int tagId = tlvFieldAnnotation.value();
        if (tlvFields.containsKey(new Integer(tagId))) {
            throw new IllegalArgumentException("TLV field duplicate: " + tagId);
        }
        tlvFields.put(new Integer(tagId), field);
    }
    T tlvObject = tlvClass.newInstance();

    int idx = 0;
    while (idx < file.length - 1) {
        byte tag = file[idx];
        idx++;
        byte lengthByte = file[idx];
        int length = lengthByte & 0x7f;
        while ((lengthByte & 0x80) == 0x80) {
            idx++;
            lengthByte = file[idx];
            length = (length << 7) + (lengthByte & 0x7f);
        }
        idx++;
        if (0 == tag) {
            idx += length;
            continue;
        }
        if (tlvFields.containsKey(new Integer(tag))) {
            Field tlvField = tlvFields.get(new Integer(tag));
            Class<?> tlvType = tlvField.getType();
            ConvertData convertDataAnnotation = tlvField.getAnnotation(ConvertData.class);
            byte[] tlvValue = copy(file, idx, length);
            Object fieldValue;
            if (null != convertDataAnnotation) {
                Class<? extends DataConvertor<?>> dataConvertorClass = convertDataAnnotation.value();
                DataConvertor<?> dataConvertor = dataConvertorClass.newInstance();
                fieldValue = dataConvertor.convert(tlvValue);
            } else if (String.class == tlvType) {
                fieldValue = new String(tlvValue, "UTF-8");
            } else if (Boolean.TYPE == tlvType) {
                fieldValue = true;
            } else if (tlvType.isArray() && Byte.TYPE == tlvType.getComponentType()) {
                fieldValue = tlvValue;
            } else {
                throw new IllegalArgumentException("unsupported field type: " + tlvType.getName());
            }
            LOG.debug("setting field: " + tlvField.getName());
            if (null != tlvField.get(tlvObject) && false == tlvField.getType().isPrimitive()) {
                throw new RuntimeException("field was already set: " + tlvField.getName());
            }
            tlvField.setAccessible(true);
            tlvField.set(tlvObject, fieldValue);
        } else {
            LOG.debug("unknown tag: " + (tag & 0xff) + ", length: " + length);
        }
        idx += length;
    }
    return tlvObject;
}

From source file:org.openTwoFactor.clientExt.net.sf.ezmorph.primitive.ByteMorpher.java

public Class morphsTo() {
    return Byte.TYPE;
}

From source file:org.yccheok.jstock.gui.POIUtils.java

private static void handlePrimitive(Method method, Class<?> clazz) {
    if (clazz == Boolean.TYPE) {
        parameterTypeMap.put(Boolean.class, method);
    } else if (clazz == Character.TYPE) {
        parameterTypeMap.put(Character.class, method);
    } else if (clazz == Byte.TYPE) {
        parameterTypeMap.put(Byte.class, method);
    } else if (clazz == Short.TYPE) {
        parameterTypeMap.put(Short.class, method);
    } else if (clazz == Integer.TYPE) {
        parameterTypeMap.put(Integer.class, method);
    } else if (clazz == Long.TYPE) {
        parameterTypeMap.put(Long.class, method);
    } else if (clazz == Float.TYPE) {
        parameterTypeMap.put(Float.class, method);
    } else if (clazz == Double.TYPE) {
        parameterTypeMap.put(Double.class, method);
    } // ... and so on for the other six primitive types (void doesn't matter)
}

From source file:com.flipkart.polyguice.config.ApacheCommonsConfigProvider.java

@Override
public Object getValue(String path, Class<?> type) {
    if (!rootConfig.containsKey(path)) {
        return null;
    }//from  w w w .  ja v  a  2s.  c o m
    if (type.equals(Byte.TYPE) || type.equals(Byte.class)) {
        return rootConfig.getByte(path, null);
    } else if (type.equals(Short.TYPE) || type.equals(Short.class)) {
        return rootConfig.getShort(path, null);
    } else if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
        return rootConfig.getInteger(path, null);
    } else if (type.equals(Long.TYPE) || type.equals(Long.class)) {
        return rootConfig.getLong(path, null);
    } else if (type.equals(Float.TYPE) || type.equals(Float.class)) {
        return rootConfig.getFloat(path, null);
    } else if (type.equals(Double.TYPE) || type.equals(Double.class)) {
        return rootConfig.getDouble(path, null);
    } else if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) {
        return rootConfig.getBoolean(path, null);
    } else if (type.equals(String.class)) {
        return rootConfig.getString(path);
    } else if (type.equals(BigInteger.class)) {
        return rootConfig.getBigInteger(path);
    } else if (type.equals(BigDecimal.class)) {
        return rootConfig.getBigDecimal(path);
    } else if (type.equals(Properties.class)) {
        return rootConfig.getProperties(path);
    } else if (type.equals(String[].class)) {
        return rootConfig.getStringArray(path);
    } else if (type.equals(TimeInterval.class)) {
        String interval = rootConfig.getString(path);
        if (interval == null) {
            return null;
        }
        return new TimeInterval(interval);
    }
    return null;
}

From source file:org.briljantframework.data.vector.Convert.java

@SuppressWarnings("unchecked")
private static <T> T convertNumber(Class<T> cls, Number num) {
    if (cls.equals(Double.class) || cls.equals(Double.TYPE)) {
        return (T) (Double) num.doubleValue();
    } else if (cls.equals(Float.class) || cls.equals(Float.TYPE)) {
        return (T) (Float) num.floatValue();
    } else if (cls.equals(Long.class) || cls.equals(Long.TYPE)) {
        return (T) (Long) num.longValue();
    } else if (cls.equals(Integer.class) || cls.equals(Integer.TYPE)) {
        return (T) (Integer) num.intValue();
    } else if (cls.equals(Short.class) || cls.equals(Short.TYPE)) {
        return (T) (Short) num.shortValue();
    } else if (cls.equals(Byte.class) || cls.equals(Byte.TYPE)) {
        return (T) (Byte) num.byteValue();
    } else if (Complex.class.equals(cls)) {
        return cls.cast(Complex.valueOf(num.doubleValue()));
    } else if (Logical.class.equals(cls)) {
        return cls.cast(num.intValue() == 1 ? Logical.TRUE : Logical.FALSE);
    } else if (Boolean.class.equals(cls)) {
        return cls.cast(num.intValue() == 1);
    } else {/*from ww w .  ja  v a2  s  .  c  o m*/
        return Na.of(cls);
    }
}

From source file:ClassUtils.java

/**
 * Helper for invoking an instance method that takes a single parameter.
 * This method also handles parameters of primitive type.
 * //from w w  w . ja va  2  s.  c  o  m
 * @param cl
 *            The class that the instance belongs to
 * @param instance
 *            The object on which we will invoke the method
 * @param methodName
 *            The method name
 * @param param
 *            The parameter
 * @throws Throwable
 */
public static Object invokeMethod(Class cl, Object instance, String methodName, Object param) throws Throwable {
    Class paramClass;
    if (param instanceof Integer)
        paramClass = Integer.TYPE;
    else if (param instanceof Long)
        paramClass = Long.TYPE;
    else if (param instanceof Short)
        paramClass = Short.TYPE;
    else if (param instanceof Boolean)
        paramClass = Boolean.TYPE;
    else if (param instanceof Double)
        paramClass = Double.TYPE;
    else if (param instanceof Float)
        paramClass = Float.TYPE;
    else if (param instanceof Character)
        paramClass = Character.TYPE;
    else if (param instanceof Byte)
        paramClass = Byte.TYPE;
    else
        paramClass = param.getClass();
    Method method = cl.getMethod(methodName, new Class[] { paramClass });
    try {
        return method.invoke(instance, new Object[] { param });
    } catch (InvocationTargetException e) {
        throw e.getCause();
    }
}