Example usage for java.lang Boolean TYPE

List of usage examples for java.lang Boolean TYPE

Introduction

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

Prototype

Class TYPE

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

Click Source Link

Document

The Class object representing the primitive type boolean.

Usage

From source file:com.examples.with.different.packagename.testcarver.AbstractConverter.java

/**
 * Change primitve Class types to the associated wrapper class.
 * @param type The class type to check.//w ww .  j a v a  2s.  c  o  m
 * @return The converted type.
 */
Class primitive(Class type) {
    if (type == null || !type.isPrimitive()) {
        return type;
    }

    if (type == Integer.TYPE) {
        return Integer.class;
    } else if (type == Double.TYPE) {
        return Double.class;
    } else if (type == Long.TYPE) {
        return Long.class;
    } else if (type == Boolean.TYPE) {
        return Boolean.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;
    } else if (type == Character.TYPE) {
        return Character.class;
    } else {
        return type;
    }
}

From source file:net.sf.qooxdoo.rpc.RemoteCallUtils.java

/**
 * Converts "normal" java types to JSON stuff.
 *
 * @param       obj                 the object to convert.
 *//*from  w  ww.  j  av  a2  s  . c o m*/

public Object fromJava(Object obj)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    if (obj == null) {
        return JSONObject.NULL;
    }
    if (obj instanceof String) {
        return obj;
    }
    if (obj instanceof Date) {
        return obj;
    }
    if (obj instanceof Integer || obj instanceof Double || obj instanceof Boolean) {
        return obj;
    }
    if (obj instanceof Float) {
        return new Double(((Float) obj).doubleValue());
    }
    // FIXME: find a better way to handle longs
    if (obj instanceof Long) {
        return new Double(((Long) obj).doubleValue());
    }
    if (obj instanceof Object[]) {
        Object[] objectArray = (Object[]) obj;
        JSONArray jsonArray = new JSONArray();
        for (int i = 0; i < objectArray.length; ++i) {
            jsonArray.put(fromJava(objectArray[i]));
        }
        return jsonArray;
    }
    Class componentType = obj.getClass().getComponentType();
    if (componentType == Integer.TYPE) {
        JSONArray jsonArray = new JSONArray();
        int[] intArray = (int[]) obj;
        for (int i = 0; i < intArray.length; ++i) {
            jsonArray.put(intArray[i]);
        }
        return jsonArray;
    }
    if (componentType == Float.TYPE) {
        JSONArray jsonArray = new JSONArray();
        float[] floatArray = (float[]) obj;
        for (int i = 0; i < floatArray.length; ++i) {
            jsonArray.put((double) (floatArray[i]));
        }
        return jsonArray;
    }
    // FIXME: find a better way to handle longs
    if (componentType == Long.TYPE) {
        JSONArray jsonArray = new JSONArray();
        long[] longArray = (long[]) obj;
        for (int i = 0; i < longArray.length; ++i) {
            jsonArray.put((double) (longArray[i]));
        }
        return jsonArray;
    }
    if (componentType == Double.TYPE) {
        JSONArray jsonArray = new JSONArray();
        double[] doubleArray = (double[]) obj;
        for (int i = 0; i < doubleArray.length; ++i) {
            jsonArray.put(doubleArray[i]);
        }
        return jsonArray;
    }
    if (componentType == Boolean.TYPE) {
        JSONArray jsonArray = new JSONArray();
        boolean[] booleanArray = (boolean[]) obj;
        for (int i = 0; i < booleanArray.length; ++i) {
            jsonArray.put(booleanArray[i]);
        }
        return jsonArray;
    }
    if (obj instanceof Map) {
        Map map = (Map) obj;
        Iterator keyIterator = map.keySet().iterator();
        JSONObject jsonObject = new JSONObject();
        Object key;
        while (keyIterator.hasNext()) {
            key = keyIterator.next();
            jsonObject.put((key == null ? null : key.toString()), fromJava(map.get(key)));
        }
        return jsonObject;
    }
    if (obj instanceof Set) {
        Set set = (Set) obj;
        Iterator iterator = set.iterator();
        JSONObject jsonObject = new JSONObject();
        Object key;
        while (iterator.hasNext()) {
            key = iterator.next();
            jsonObject.put((key == null ? null : key.toString()), true);
        }
        return jsonObject;
    }
    return fromJava(filter(obj, PropertyUtils.describe(obj)));
}

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

/** Read a {@link CWritable}, {@link String}, primitive type, or an array of
 * the preceding. *//*from  w  ww  .j av  a2s. co m*/
@SuppressWarnings("unchecked")
public static Object readObject(DataInput in, CObjectWritable objectWritable, CloudataConf conf,
        boolean arrayComponent, Class componentClass) throws IOException {
    String className;
    if (arrayComponent) {
        className = componentClass.getName();
    } else {
        className = CUTF8.readString(in);
        //SANGCHUL
        //   System.out.println("SANGCHUL] className:" + className);
    }

    Class<?> declaredClass = PRIMITIVE_NAMES.get(className);
    if (declaredClass == null) {
        try {
            declaredClass = conf.getClassByName(className);
        } catch (ClassNotFoundException e) {
            //SANGCHUL
            e.printStackTrace();
            throw new RuntimeException("readObject can't find class[className=" + className + "]", e);
        }
    }

    Object instance;

    if (declaredClass.isPrimitive()) { // primitive types

        if (declaredClass == Boolean.TYPE) { // boolean
            instance = Boolean.valueOf(in.readBoolean());
        } else if (declaredClass == Character.TYPE) { // char
            instance = Character.valueOf(in.readChar());
        } else if (declaredClass == Byte.TYPE) { // byte
            instance = Byte.valueOf(in.readByte());
        } else if (declaredClass == Short.TYPE) { // short
            instance = Short.valueOf(in.readShort());
        } else if (declaredClass == Integer.TYPE) { // int
            instance = Integer.valueOf(in.readInt());
        } else if (declaredClass == Long.TYPE) { // long
            instance = Long.valueOf(in.readLong());
        } else if (declaredClass == Float.TYPE) { // float
            instance = Float.valueOf(in.readFloat());
        } else if (declaredClass == Double.TYPE) { // double
            instance = Double.valueOf(in.readDouble());
        } else if (declaredClass == Void.TYPE) { // void
            instance = null;
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declaredClass);
        }

    } else if (declaredClass.isArray()) { // array
        //System.out.println("SANGCHUL] is array");
        int length = in.readInt();
        //System.out.println("SANGCHUL] array length : " + length);
        //System.out.println("Read:in.readInt():" + length);
        if (declaredClass.getComponentType() == Byte.TYPE) {
            byte[] bytes = new byte[length];
            in.readFully(bytes);
            instance = bytes;
        } else if (declaredClass.getComponentType() == ColumnValue.class) {
            instance = readColumnValue(in, conf, declaredClass, length);
        } else {
            Class componentType = declaredClass.getComponentType();

            // SANGCHUL
            //System.out.println("SANGCHUL] componentType : " + componentType.getName());

            instance = Array.newInstance(componentType, length);
            for (int i = 0; i < length; i++) {
                Object arrayComponentInstance = readObject(in, null, conf, !componentType.isArray(),
                        componentType);
                Array.set(instance, i, arrayComponentInstance);
                //Array.set(instance, i, readObject(in, conf));
            }
        }
    } else if (declaredClass == String.class) { // String
        instance = CUTF8.readString(in);
    } else if (declaredClass.isEnum()) { // enum
        instance = Enum.valueOf((Class<? extends Enum>) declaredClass, CUTF8.readString(in));
    } else if (declaredClass == ColumnValue.class) {
        //ColumnValue?  ?? ?? ?  ? ?.
        //? ?   ? ? ? ? . 
        Class instanceClass = null;
        try {
            short typeDiff = in.readShort();
            if (typeDiff == TYPE_DIFF) {
                instanceClass = conf.getClassByName(CUTF8.readString(in));
            } else {
                instanceClass = declaredClass;
            }
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("readObject can't find class", e);
        }
        ColumnValue columnValue = new ColumnValue();
        columnValue.readFields(in);
        instance = columnValue;
    } else { // Writable

        Class instanceClass = null;
        try {
            short typeDiff = in.readShort();
            // SANGCHUL
            //System.out.println("SANGCHUL] typeDiff : " + typeDiff);
            //System.out.println("Read:in.readShort():" + typeDiff);
            if (typeDiff == TYPE_DIFF) {
                // SANGCHUL
                String classNameTemp = CUTF8.readString(in);
                //System.out.println("SANGCHUL] typeDiff : " + classNameTemp);
                instanceClass = conf.getClassByName(classNameTemp);
                //System.out.println("Read:UTF8.readString(in):" + instanceClass.getClass());
            } else {
                instanceClass = declaredClass;
            }
        } catch (ClassNotFoundException e) {

            // SANGCHUL
            e.printStackTrace();
            throw new RuntimeException("readObject can't find class", e);
        }

        CWritable writable = CWritableFactories.newInstance(instanceClass, conf);
        writable.readFields(in);
        //System.out.println("Read:writable.readFields(in)");
        instance = writable;

        if (instanceClass == NullInstance.class) { // null
            declaredClass = ((NullInstance) instance).declaredClass;
            instance = null;
        }
    }

    if (objectWritable != null) { // store values
        objectWritable.declaredClass = declaredClass;
        objectWritable.instance = instance;
    }

    return instance;
}

From source file:Classes.java

/**
 * This method acts equivalently to invoking classLoader.loadClass(className)
 * but it also supports primitive types and array classes of object types or
 * primitive types./*from  w  ww.jav a  2s.  com*/
 * 
 * @param className
 *          the qualified name of the class or the name of primitive type or
 *          array in the same format as returned by the
 *          java.lang.Class.getName() method.
 * @param classLoader
 *          the ClassLoader used to load classes
 * @return the Class object for the requested className
 * 
 * @throws ClassNotFoundException
 *           when the <code>classLoader</code> can not find the requested
 *           class
 */
public static Class loadClass(String className, ClassLoader classLoader) throws ClassNotFoundException {
    // ClassLoader.loadClass() does not handle primitive types:
    //
    // B byte
    // C char
    // D double
    // F float
    // I int
    // J long
    // S short
    // Z boolean
    // V void
    //
    if (className.length() == 1) {
        char type = className.charAt(0);
        if (type == 'B')
            return Byte.TYPE;
        if (type == 'C')
            return Character.TYPE;
        if (type == 'D')
            return Double.TYPE;
        if (type == 'F')
            return Float.TYPE;
        if (type == 'I')
            return Integer.TYPE;
        if (type == 'J')
            return Long.TYPE;
        if (type == 'S')
            return Short.TYPE;
        if (type == 'Z')
            return Boolean.TYPE;
        if (type == 'V')
            return Void.TYPE;
        // else throw...
        throw new ClassNotFoundException(className);
    }

    // Check for a primative type
    if (isPrimitive(className) == true)
        return (Class) Classes.PRIMITIVE_NAME_TYPE_MAP.get(className);

    // Check for the internal vm format: Lclassname;
    if (className.charAt(0) == 'L' && className.charAt(className.length() - 1) == ';')
        return classLoader.loadClass(className.substring(1, className.length() - 1));

    // first try - be optimistic
    // this will succeed for all non-array classes and array classes that have
    // already been resolved
    //
    try {
        return classLoader.loadClass(className);
    } catch (ClassNotFoundException e) {
        // if it was non-array class then throw it
        if (className.charAt(0) != '[')
            throw e;
    }

    // we are now resolving array class for the first time

    // count opening braces
    int arrayDimension = 0;
    while (className.charAt(arrayDimension) == '[')
        arrayDimension++;

    // resolve component type - use recursion so that we can resolve primitive
    // types also
    Class componentType = loadClass(className.substring(arrayDimension), classLoader);

    // construct array class
    return Array.newInstance(componentType, new int[arrayDimension]).getClass();
}

From source file:org.gradle.model.internal.manage.schema.extract.ManagedProxyClassGenerator.java

private void declareCanCallSettersField(ClassVisitor visitor) {
    declareField(visitor, CAN_CALL_SETTERS_FIELD_NAME, Boolean.TYPE);
}

From source file:com.exadel.flamingo.flex.messaging.amf.io.AMF0Serializer.java

protected Object[] convertPrimitiveArrayToObjectArray(Object array) {
    Class<?> componentType = array.getClass().getComponentType();

    Object[] result = null;//from  w ww  . ja  va2s  .  c  o m

    if (componentType == null) {
        throw new NullPointerException("componentType is null");
    } else if (componentType == Character.TYPE) {
        char[] carray = (char[]) array;
        result = new Object[carray.length];
        for (int i = 0; i < carray.length; i++) {
            result[i] = new Character(carray[i]);
        }
    } else if (componentType == Byte.TYPE) {
        byte[] barray = (byte[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Byte(barray[i]);
        }
    } else if (componentType == Short.TYPE) {
        short[] sarray = (short[]) array;
        result = new Object[sarray.length];
        for (int i = 0; i < sarray.length; i++) {
            result[i] = new Short(sarray[i]);
        }
    } else if (componentType == Integer.TYPE) {
        int[] iarray = (int[]) array;
        result = new Object[iarray.length];
        for (int i = 0; i < iarray.length; i++) {
            result[i] = Integer.valueOf(iarray[i]);
        }
    } else if (componentType == Long.TYPE) {
        long[] larray = (long[]) array;
        result = new Object[larray.length];
        for (int i = 0; i < larray.length; i++) {
            result[i] = new Long(larray[i]);
        }
    } else if (componentType == Double.TYPE) {
        double[] darray = (double[]) array;
        result = new Object[darray.length];
        for (int i = 0; i < darray.length; i++) {
            result[i] = new Double(darray[i]);
        }
    } else if (componentType == Float.TYPE) {
        float[] farray = (float[]) array;
        result = new Object[farray.length];
        for (int i = 0; i < farray.length; i++) {
            result[i] = new Float(farray[i]);
        }
    } else if (componentType == Boolean.TYPE) {
        boolean[] barray = (boolean[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Boolean(barray[i]);
        }
    } else {
        throw new IllegalArgumentException("unexpected component type: " + componentType.getClass().getName());
    }

    return result;
}

From source file:com.phoenixnap.oss.ramlapisync.naming.SchemaHelper.java

/**
 * Maps primitives and other simple Java types into simple types supported by RAML
 * //from  ww w .java  2  s .  c o  m
 * @param clazz The Class to map
 * @return The Simple RAML ParamType which maps to this class or null if one is not found
 */
public static ParamType mapSimpleType(Class<?> clazz) {
    Class<?> targetClazz = clazz;
    if (targetClazz.isArray() && clazz.getComponentType() != null) {
        targetClazz = clazz.getComponentType();
    }
    if (targetClazz.equals(Long.TYPE) || targetClazz.equals(Long.class) || targetClazz.equals(Integer.TYPE)
            || targetClazz.equals(Integer.class) || targetClazz.equals(Short.TYPE)
            || targetClazz.equals(Short.class) || targetClazz.equals(Byte.TYPE)
            || targetClazz.equals(Byte.class)) {
        return ParamType.INTEGER;
    } else if (targetClazz.equals(Float.TYPE) || targetClazz.equals(Float.class)
            || targetClazz.equals(Double.TYPE) || targetClazz.equals(Double.class)
            || targetClazz.equals(BigDecimal.class)) {
        return ParamType.NUMBER;
    } else if (targetClazz.equals(Boolean.class) || targetClazz.equals(Boolean.TYPE)) {
        return ParamType.BOOLEAN;
    } else if (targetClazz.equals(String.class)) {
        return ParamType.STRING;
    }
    return null; // default to string
}

From source file:at.alladin.rmbt.shared.hstoreparser.HstoreParser.java

/**
 * //from  www  . j av  a  2s.c o m
 * @param f
 * @param o
 * @return
 */
public static Object parseFieldValue(Field f, Object o) {
    if (o != JSONObject.NULL) {
        if (f.getType().equals(Integer.class) || f.getType().equals(Integer.TYPE)) {
            return Integer.parseInt(String.valueOf(o));
        } else if (f.getType().equals(String.class)) {
            return String.valueOf(o);
        } else if (f.getType().equals(Long.class) || f.getType().equals(Long.TYPE)) {
            return Long.parseLong(String.valueOf(o));
        } else if (f.getType().equals(Boolean.class) || f.getType().equals(Boolean.TYPE)) {
            return Boolean.parseBoolean(String.valueOf(o));
        } else if (f.getType().equals(Float.class) || f.getType().equals(Float.TYPE)) {
            return Float.parseFloat(String.valueOf(o));
        } else if (f.getType().equals(Double.class) || f.getType().equals(Double.TYPE)) {
            return Double.parseDouble(String.valueOf(o));
        } else if (f.getType().equals(Short.class) || f.getType().equals(Short.TYPE)) {
            return Short.parseShort(String.valueOf(o));
        } else {
            return o;
        }
    }

    return null;
}

From source file:org.xmlsh.util.JavaUtils.java

public static boolean isWrappedOrPrimativeNumber(Class<?> c) {
    if (c == null)
        return false;
    if (c.isPrimitive() && !(c == Void.TYPE || c == Boolean.TYPE))
        return true;
    for (Class<?> w : mNumberWrappers)
        if (c.isAssignableFrom(w))
            return true;

    return false;
}

From source file:org.eclim.installer.eclipse.Application.java

private void performProvisioningActions()
        // EV: throw a regular Exception to account for reflection exceptions
        //throws CoreException
        throws Exception {
    // EV: pull private vars in.
    List<IVersionedId> rootsToInstall = (List<IVersionedId>) this.getPrivateField("rootsToInstall");
    List<IVersionedId> rootsToUninstall = (List<IVersionedId>) this.getPrivateField("rootsToUninstall");

    // EV: invoke private methods
    //IProfile profile = initializeProfile();
    //Collection<IInstallableUnit> installs = collectRoots(profile, rootsToInstall, true);
    //Collection<IInstallableUnit> uninstalls = collectRoots(profile, rootsToUninstall, false);
    IProfile profile = (IProfile) invokePrivate("initializeProfile", new Class[0], new Object[0]);
    Collection<IInstallableUnit> installs = (Collection<IInstallableUnit>) invokePrivate("collectRoots",
            new Class[] { IProfile.class, List.class, Boolean.TYPE },
            new Object[] { profile, rootsToInstall, true });
    Collection<IInstallableUnit> uninstalls = (Collection<IInstallableUnit>) invokePrivate("collectRoots",
            new Class[] { IProfile.class, List.class, Boolean.TYPE },
            new Object[] { profile, rootsToUninstall, false });

    // keep this result status in case there is a problem so we can report it to the user
    boolean wasRoaming = Boolean.valueOf(profile.getProperty(IProfile.PROP_ROAMING)).booleanValue();
    try {//w  w  w. j  a v  a  2  s . co  m
        // EV: invoke private methods
        //updateRoamingProperties(profile);
        invokePrivate("updateRoamingProperties", new Class[] { IProfile.class }, new Object[] { profile });

        // EV: pull in private fields
        IProvisioningAgent targetAgent = (IProvisioningAgent) this.getPrivateField("targetAgent");
        List<URI> metadataRepositoryLocations = (List<URI>) this.getPrivateField("metadataRepositoryLocations");
        List<URI> artifactRepositoryLocations = (List<URI>) this.getPrivateField("artifactRepositoryLocations");
        boolean followReferences = ((Boolean) this.getPrivateField("followReferences")).booleanValue();
        String FOLLOW_ARTIFACT_REPOSITORY_REFERENCES = (String) this
                .getPrivateField("FOLLOW_ARTIFACT_REPOSITORY_REFERENCES");

        ProvisioningContext context = new ProvisioningContext(targetAgent);
        context.setMetadataRepositories(
                metadataRepositoryLocations.toArray(new URI[metadataRepositoryLocations.size()]));
        context.setArtifactRepositories(
                artifactRepositoryLocations.toArray(new URI[artifactRepositoryLocations.size()]));
        context.setProperty(ProvisioningContext.FOLLOW_REPOSITORY_REFERENCES, String.valueOf(followReferences));
        context.setProperty(FOLLOW_ARTIFACT_REPOSITORY_REFERENCES, String.valueOf(followReferences));

        // EV: invoke private methods
        //ProfileChangeRequest request = buildProvisioningRequest(profile, installs, uninstalls);
        //printRequest(request);
        ProfileChangeRequest request = (ProfileChangeRequest) invokePrivate("buildProvisioningRequest",
                new Class[] { IProfile.class, Collection.class, Collection.class },
                new Object[] { profile, installs, uninstalls });
        invokePrivate("printRequest", new Class[] { ProfileChangeRequest.class }, new Object[] { request });

        planAndExecute(profile, context, request);
    } finally {
        // if we were originally were set to be roaming and we changed it, change it back before we return
        if (wasRoaming && !Boolean.valueOf(profile.getProperty(IProfile.PROP_ROAMING)).booleanValue())
            // EV: invoke private method
            //setRoaming(profile);
            invokePrivate("setRoaming", new Class[] { IProfile.class }, new Object[] { profile });
    }
}