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:Main.java

/**
 * <p>Copies the given array and adds the given element at the end of the new array.</p>
 *
 * <p>The new array contains the same elements of the input
 * array plus the given element in the last position. The component type of
 * the new array is the same as that of the input array.</p>
 *
 * <p>If the input array is {@code null}, a new one element array is returned
 *  whose component type is the same as the element.</p>
 *
 * <pre>//from   ww  w  .j  a  va2  s. com
 * ArrayUtils.add(null, 0)   = [0]
 * ArrayUtils.add([1], 0)    = [1, 0]
 * ArrayUtils.add([1, 0], 1) = [1, 0, 1]
 * </pre>
 *
 * @param array  the array to copy and add the element to, may be {@code null}
 * @param element  the object to add at the last index of the new array
 * @return A new array containing the existing elements plus the new element
 * @since 2.1
 */
public static byte[] add(final byte[] array, final byte element) {
    final byte[] newArray = (byte[]) copyArrayGrow1(array, Byte.TYPE);
    newArray[newArray.length - 1] = element;
    return newArray;
}

From source file:org.trianacode.taskgraph.tool.ClassLoaders.java

public static Class forName(String className) throws ClassNotFoundException {
    className = getTextClassName(className);
    boolean isArray = false;
    int dims = 0;
    if (className.endsWith("[]")) {
        isArray = true;/*  w w w. ja v  a 2  s  .  c o m*/
        dims = className.substring(className.indexOf("[]"), className.length()).length() / 2;
        className = className.substring(0, className.indexOf("[]"));

    }
    Class cls;
    if (className.equals("boolean")) {
        cls = Boolean.TYPE;
    } else if (className.equals("char")) {
        cls = Character.TYPE;
    } else if (className.equals("byte")) {
        cls = Byte.TYPE;
    } else if (className.equals("short")) {
        cls = Short.TYPE;
    } else if (className.equals("int")) {
        cls = Integer.TYPE;
    } else if (className.equals("long")) {
        cls = Long.TYPE;
    } else if (className.equals("float")) {
        cls = Float.TYPE;
    } else if (className.equals("double")) {
        cls = Double.TYPE;
    } else if (className.equals("void")) {
        cls = void.class;
    } else {
        cls = loadClass(className);
    }
    if (isArray) {
        Object arr = Array.newInstance(cls, new int[dims]);
        cls = arr.getClass();
    }
    return cls;
}

From source file:net.sf.jrf.domain.PersistentObjectDynaProperty.java

/** Constructs instance and property name and class.
* @param name property name./*from   w  w  w.ja  v a 2 s.  co  m*/
* @param cls value object <code>Class</code>.
* @param readMethodName name of the read <code>Method</code>
* @param writeMethodName name of the write <code>Method</code>
*/
public PersistentObjectDynaProperty(String name, Class cls, String readMethodName, String writeMethodName) {
    super(name, cls);
    this.readMethodName = readMethodName;
    this.writeMethodName = writeMethodName;
    if (cls.isPrimitive()) {
        if (cls.equals(Boolean.TYPE))
            primitiveWrapperClass = Boolean.class;
        else if (cls.equals(Byte.TYPE))
            primitiveWrapperClass = Byte.class;
        else if (cls.equals(Character.TYPE))
            primitiveWrapperClass = Character.class;
        else if (cls.equals(Double.TYPE))
            primitiveWrapperClass = Double.class;
        else if (cls.equals(Float.TYPE))
            primitiveWrapperClass = Float.class;
        else if (cls.equals(Integer.TYPE))
            primitiveWrapperClass = Integer.class;
        else if (cls.equals(Long.TYPE))
            primitiveWrapperClass = Long.class;
        else if (cls.equals(Short.TYPE))
            primitiveWrapperClass = Short.class;

    } else if (java.util.List.class.isAssignableFrom(cls) || cls.isArray()) {
        indexed = true;
    } else if (java.util.Map.class.isAssignableFrom(cls)) {
        mapped = true;
    }
}

From source file:org.skfiy.typhon.spi.GMConsoleProvider.java

/**
 *
 * @param uid/*from   w  ww  . jav  a  2 s  .  c  o m*/
 * @param propertyName
 * @param val
 * @throws javax.management.MBeanException
 */
public void changeProperty(final String uid, final String propertyName, final String val)
        throws MBeanException {
    try {
        invoke(transcoding(uid), new Handler() {

            @Override
            void execute() {
                Player player = SessionUtils.getPlayer();
                try {
                    Class<?> propertyType = PropertyUtils.getPropertyType(player, propertyName);
                    if (propertyType == null) { // Not found property
                        throw new IllegalArgumentException("Not found property[" + propertyName + "]");
                    }

                    if (propertyType == Byte.class || propertyType == Byte.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Byte.valueOf(val));
                    } else if (propertyType == Character.class || propertyType == Character.TYPE) {
                        BeanUtils.setProperty(player, propertyName, val.charAt(0));
                    } else if (propertyType == Boolean.class || propertyType == Boolean.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Boolean.valueOf(val));
                    } else if (propertyType == Integer.class || propertyType == Integer.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Integer.valueOf(val));
                    } else if (propertyType == Long.class || propertyType == Long.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Long.valueOf(val));
                    } else if (propertyType == Float.class || propertyType == Float.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Float.valueOf(val));
                    } else if (propertyType == Double.class || propertyType == Double.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Double.valueOf(val));
                    } else {
                        BeanUtils.setProperty(player, propertyName, val);
                    }

                } catch (Exception ex) {
                    throw new IllegalArgumentException(ex.getMessage());
                }
            }

        });
    } catch (Exception e) {
        throw new MBeanException(e, e.getMessage());
    }
}

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

@SuppressWarnings("unchecked")
private static <T> T convertLogical(Class<T> cls, Logical log) {
    if (cls.equals(Double.class) || cls.equals(Double.TYPE)) {
        return (T) (Double) (log == Logical.TRUE ? 1.0 : 0.0);
    } else if (cls.equals(Float.class) || cls.equals(Float.TYPE)) {
        return (T) (Float) (log == Logical.TRUE ? 1.0f : 0.0f);
    } else if (cls.equals(Long.class) || cls.equals(Long.TYPE)) {
        return (T) (Long) (log == Logical.TRUE ? 1l : 0l);
    } else if (cls.equals(Integer.class) || cls.equals(Integer.TYPE)) {
        return (T) (Integer) (log == Logical.TRUE ? 1 : 0);
    } else if (cls.equals(Short.class) || cls.equals(Short.TYPE)) {
        return (T) (Short) (log == Logical.TRUE ? (short) 1 : (short) 0);
    } else if (cls.equals(Byte.class) || cls.equals(Byte.TYPE)) {
        return (T) (Byte) (log == Logical.TRUE ? (byte) 1 : (byte) 0);
    } else if (Complex.class.equals(cls)) {
        return cls.cast(log == Logical.TRUE ? Complex.ONE : Complex.ZERO);
    } else if (Boolean.class.equals(cls)) {
        return cls.cast(log == Logical.TRUE);
    } else {/*  w ww  .ja  v a2s . c  om*/
        return Na.of(cls);
    }
}

From source file:com.github.michalbednarski.intentslab.Utils.java

public static Object getDefaultValueForPrimitveClass(Class<?> aClass) {
    if (aClass == Boolean.TYPE) {
        return false;
    } else if (aClass == Byte.TYPE) {
        return (byte) 0;
    } else if (aClass == Character.TYPE) {
        return 0;
    } else if (aClass == Short.TYPE) {
        return (short) 0;
    } else if (aClass == Integer.TYPE) {
        return 0;
    } else if (aClass == Long.TYPE) {
        return (long) 0;
    } else if (aClass == Float.TYPE) {
        return 0;
    } else if (aClass == Double.TYPE) {
        return 0;
    } else {/* w  w  w  .  jav  a  2 s .co m*/
        throw new RuntimeException("Not primitive type");
    }
}

From source file:com.adobe.acs.commons.data.Variant.java

@SuppressWarnings("squid:S3776")
public final <T> void setValue(T val) {
    if (val == null) {
        return;//w  w  w.j ava  2  s  .c om
    }
    Class type = val.getClass();
    if (type == Variant.class) {
        Variant v = (Variant) val;
        longVal = v.longVal;
        doubleVal = v.doubleVal;
        stringVal = v.stringVal;
        booleanVal = v.booleanVal;
        dateVal = v.dateVal;
    } else if (type == Byte.TYPE || type == Byte.class) {
        setLongVal(((Byte) val).longValue());
    } else if (type == Integer.TYPE || type == Integer.class) {
        setLongVal(((Integer) val).longValue());
    } else if (type == Long.TYPE || type == Long.class) {
        setLongVal((Long) val);
    } else if (type == Short.TYPE || type == Short.class) {
        setLongVal(((Short) val).longValue());
    } else if (type == Float.TYPE || type == Float.class) {
        setDoubleVal((Double) val);
    } else if (type == Double.TYPE || type == Double.class) {
        setDoubleVal((Double) val);
    } else if (type == Boolean.TYPE || type == Boolean.class) {
        setBooleanVal((Boolean) val);
    } else if (type == String.class) {
        setStringVal((String) val);
    } else if (type == Date.class) {
        setDateVal((Date) val);
    } else if (type == Instant.class) {
        setDateVal(new Date(((Instant) val).toEpochMilli()));
    } else if (type == Calendar.class) {
        setDateVal(((Calendar) val).getTime());
    } else {
        setStringVal(String.valueOf(val));
    }
}

From source file:org.cloudata.core.common.io.CObjectWritable.java

/** Write a {@link CWritable}, {@link String}, primitive type, or an array of
 * the preceding. *///from   www.  ja  v  a2  s.co  m
public static void writeObject(DataOutput out, Object instance, Class declaredClass, CloudataConf conf,
        boolean arrayComponent) throws IOException {

    if (instance == null) { // null
        instance = new NullInstance(declaredClass, conf);
        declaredClass = CWritable.class;
        arrayComponent = false;
    }

    if (!arrayComponent) {
        CUTF8.writeString(out, declaredClass.getName()); // always write declared
        //System.out.println("Write:declaredClass.getName():" + declaredClass.getName());
    }

    if (declaredClass.isArray()) { // array
        int length = Array.getLength(instance);
        out.writeInt(length);
        //System.out.println("Write:length:" + length);

        if (declaredClass.getComponentType() == Byte.TYPE) {
            out.write((byte[]) instance);
        } else if (declaredClass.getComponentType() == ColumnValue.class) {
            //ColumnValue?  Deserialize? ?? ?   ?? ?  .
            writeColumnValue(out, instance, declaredClass, conf, length);
        } else {
            for (int i = 0; i < length; i++) {
                writeObject(out, Array.get(instance, i), declaredClass.getComponentType(), conf,
                        !declaredClass.getComponentType().isArray());
            }
        }
    } else if (declaredClass == String.class) { // String
        CUTF8.writeString(out, (String) instance);

    } else if (declaredClass.isPrimitive()) { // primitive type

        if (declaredClass == Boolean.TYPE) { // boolean
            out.writeBoolean(((Boolean) instance).booleanValue());
        } else if (declaredClass == Character.TYPE) { // char
            out.writeChar(((Character) instance).charValue());
        } else if (declaredClass == Byte.TYPE) { // byte
            out.writeByte(((Byte) instance).byteValue());
        } else if (declaredClass == Short.TYPE) { // short
            out.writeShort(((Short) instance).shortValue());
        } else if (declaredClass == Integer.TYPE) { // int
            out.writeInt(((Integer) instance).intValue());
        } else if (declaredClass == Long.TYPE) { // long
            out.writeLong(((Long) instance).longValue());
        } else if (declaredClass == Float.TYPE) { // float
            out.writeFloat(((Float) instance).floatValue());
        } else if (declaredClass == Double.TYPE) { // double
            out.writeDouble(((Double) instance).doubleValue());
        } else if (declaredClass == Void.TYPE) { // void
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declaredClass);
        }
    } else if (declaredClass.isEnum()) { // enum
        CUTF8.writeString(out, ((Enum) instance).name());
    } else if (CWritable.class.isAssignableFrom(declaredClass)) { // Writable
        if (instance.getClass() == declaredClass) {
            out.writeShort(TYPE_SAME); // ? ?? ? ?? 
            //System.out.println("Write:TYPE_SAME:" + TYPE_SAME);

        } else {
            out.writeShort(TYPE_DIFF);
            //System.out.println("Write:TYPE_DIFF:" + TYPE_DIFF);
            CUTF8.writeString(out, instance.getClass().getName());
            //System.out.println("Write:instance.getClass().getName():" + instance.getClass().getName());
        }
        ((CWritable) instance).write(out);
        //System.out.println("Write:instance value");

    } else {
        throw new IOException("Can't write: " + instance + " as " + declaredClass);
    }
}

From source file:com.manydesigns.elements.util.Util.java

public static boolean isNumericType(Class type) {
    return Number.class.isAssignableFrom(type) || type == Integer.TYPE || type == Byte.TYPE
            || type == Short.TYPE || type == Long.TYPE || type == Float.TYPE || type == Double.TYPE;
}

From source file:org.soybeanMilk.SbmUtils.java

/**
 * ?<code>type</code>?// w ww .ja  v a  2  s  .com
 * @param type
 * @return
 * @date 2010-12-31
 */
public static Type wrapType(Type type) {
    if (!isClassType(type))
        return type;
    else if (!narrowToClass(type).isPrimitive())
        return type;
    else if (Byte.TYPE.equals(type))
        return Byte.class;
    else if (Short.TYPE.equals(type))
        return Short.class;
    else if (Integer.TYPE.equals(type))
        return Integer.class;
    else if (Long.TYPE.equals(type))
        return Long.class;
    else if (Float.TYPE.equals(type))
        return Float.class;
    else if (Double.TYPE.equals(type))
        return Double.class;
    else if (Boolean.TYPE.equals(type))
        return Boolean.class;
    else if (Character.TYPE.equals(type))
        return Character.class;
    else
        return type;
}