Example usage for java.lang Double TYPE

List of usage examples for java.lang Double TYPE

Introduction

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

Prototype

Class TYPE

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

Click Source Link

Document

The Class instance representing the primitive type double .

Usage

From source file:org.apache.struts.config.FormPropertyConfig.java

/**
 * Return a Class corresponds to the value specified for the
 * <code>type</code> property, taking into account the trailing "[]" for
 * arrays (as well as the ability to specify primitive Java types).
 *//*from w  w  w.ja v a2  s.c  o m*/
public Class getTypeClass() {
    // Identify the base class (in case an array was specified)
    String baseType = getType();
    boolean indexed = false;

    if (baseType.endsWith("[]")) {
        baseType = baseType.substring(0, baseType.length() - 2);
        indexed = true;
    }

    // Construct an appropriate Class instance for the base class
    Class baseClass = null;

    if ("boolean".equals(baseType)) {
        baseClass = Boolean.TYPE;
    } else if ("byte".equals(baseType)) {
        baseClass = Byte.TYPE;
    } else if ("char".equals(baseType)) {
        baseClass = Character.TYPE;
    } else if ("double".equals(baseType)) {
        baseClass = Double.TYPE;
    } else if ("float".equals(baseType)) {
        baseClass = Float.TYPE;
    } else if ("int".equals(baseType)) {
        baseClass = Integer.TYPE;
    } else if ("long".equals(baseType)) {
        baseClass = Long.TYPE;
    } else if ("short".equals(baseType)) {
        baseClass = Short.TYPE;
    } else {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

        if (classLoader == null) {
            classLoader = this.getClass().getClassLoader();
        }

        try {
            baseClass = classLoader.loadClass(baseType);
        } catch (ClassNotFoundException ex) {
            log.error("Class '" + baseType + "' not found for property '" + name + "'");
            baseClass = null;
        }
    }

    // Return the base class or an array appropriately
    if (indexed) {
        return (Array.newInstance(baseClass, 0).getClass());
    } else {
        return (baseClass);
    }
}

From source file:RealFunctionValidation.java

public static Object readAndWritePrimitiveValue(final DataInputStream in, final DataOutputStream out,
        final Class<?> type) throws IOException {

    if (!type.isPrimitive()) {
        throw new IllegalArgumentException("type must be primitive");
    }/*from  ww  w  .  j a  v a 2  s . c o m*/
    if (type.equals(Boolean.TYPE)) {
        final boolean x = in.readBoolean();
        out.writeBoolean(x);
        return Boolean.valueOf(x);
    } else if (type.equals(Byte.TYPE)) {
        final byte x = in.readByte();
        out.writeByte(x);
        return Byte.valueOf(x);
    } else if (type.equals(Character.TYPE)) {
        final char x = in.readChar();
        out.writeChar(x);
        return Character.valueOf(x);
    } else if (type.equals(Double.TYPE)) {
        final double x = in.readDouble();
        out.writeDouble(x);
        return Double.valueOf(x);
    } else if (type.equals(Float.TYPE)) {
        final float x = in.readFloat();
        out.writeFloat(x);
        return Float.valueOf(x);
    } else if (type.equals(Integer.TYPE)) {
        final int x = in.readInt();
        out.writeInt(x);
        return Integer.valueOf(x);
    } else if (type.equals(Long.TYPE)) {
        final long x = in.readLong();
        out.writeLong(x);
        return Long.valueOf(x);
    } else if (type.equals(Short.TYPE)) {
        final short x = in.readShort();
        out.writeShort(x);
        return Short.valueOf(x);
    } else {
        // This should never occur.
        throw new IllegalStateException();
    }
}

From source file:me.crime.loader.DataBaseLoader.java

private void saveData(String method, String data, Object obj) throws SAXException {
    Method getMethod = getMethod("get" + method, obj);
    Method setMethod = getMethod("set" + method, obj);

    try {/*from  w  ww . j  a  v a 2s. c  o m*/

        Object args[] = new Object[1];
        if (getMethod.getGenericReturnType() == Integer.TYPE) {
            args[0] = new Integer(data);
        } else if (getMethod.getGenericReturnType() == String.class) {
            args[0] = data;
        } else if (getMethod.getGenericReturnType() == Double.TYPE) {
            args[0] = new Double(data);
        } else if (getMethod.getGenericReturnType() == Long.TYPE) {
            args[0] = new Long(data);
        } else if (getMethod.getGenericReturnType() == Calendar.class) {
            String[] dt = data.split(":");
            Calendar cal = Calendar.getInstance();

            cal.set(Calendar.YEAR, Integer.parseInt(dt[0]));
            cal.set(Calendar.MONTH, Integer.parseInt(dt[1]));
            cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dt[2]));
            cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(dt[3]));
            cal.set(Calendar.MINUTE, Integer.parseInt(dt[4]));
            cal.set(Calendar.SECOND, Integer.parseInt(dt[5]));
            cal.set(Calendar.MILLISECOND, Integer.parseInt(dt[5]));

            if (cal.get(Calendar.YEAR) < 10) {
                cal.set(Calendar.YEAR, 2000 + cal.get(Calendar.YEAR));
            }

            args[0] = cal;

        }
        setMethod.invoke(obj, args);

    } catch (Exception e) {
        DataBaseLoader.log_.error("saveData: " + method, e);
        throw new SAXException("saveData:", e);
    }

}

From source file:org.wisdom.template.thymeleaf.OgnlOpsByReflectionTest.java

@Test
public void testNewReal() throws Exception {
    Class[] classes = new Class[] { Integer.TYPE, Double.TYPE };
    assertThat(invoke("newReal", classes, NumericTypes.FLOAT, 42.0)).isEqualTo(42f);
    assertThat(invoke("newReal", classes, NumericTypes.DOUBLE, 42.0)).isEqualTo(42d);
}

From source file:com.xwtec.xwserver.util.json.JSONArray.java

/**
 * Creates a JSONArray.<br>/*from   ww w  .  j  a  v  a 2s  .  c  om*/
 * Inspects the object type to call the correct JSONArray factory method.
 * Accepts JSON formatted strings, arrays, Collections and Enums.
 *
 * @param object
 * @throws JSONException if the object can not be converted to a proper
 *         JSONArray.
 */
public static JSONArray fromObject(Object object, JsonConfig jsonConfig) {
    if (object instanceof JSONString) {
        return _fromJSONString((JSONString) object, jsonConfig);
    } else if (object instanceof JSONArray) {
        return _fromJSONArray((JSONArray) object, jsonConfig);
    } else if (object instanceof Collection) {
        return _fromCollection((Collection) object, jsonConfig);
    } else if (object instanceof JSONTokener) {
        return _fromJSONTokener((JSONTokener) object, jsonConfig);
    } else if (object instanceof String) {
        return _fromString((String) object, jsonConfig);
    } else if (object != null && object.getClass().isArray()) {
        Class type = object.getClass().getComponentType();
        if (!type.isPrimitive()) {
            return _fromArray((Object[]) object, jsonConfig);
        } else {
            if (type == Boolean.TYPE) {
                return _fromArray((boolean[]) object, jsonConfig);
            } else if (type == Byte.TYPE) {
                return _fromArray((byte[]) object, jsonConfig);
            } else if (type == Short.TYPE) {
                return _fromArray((short[]) object, jsonConfig);
            } else if (type == Integer.TYPE) {
                return _fromArray((int[]) object, jsonConfig);
            } else if (type == Long.TYPE) {
                return _fromArray((long[]) object, jsonConfig);
            } else if (type == Float.TYPE) {
                return _fromArray((float[]) object, jsonConfig);
            } else if (type == Double.TYPE) {
                return _fromArray((double[]) object, jsonConfig);
            } else if (type == Character.TYPE) {
                return _fromArray((char[]) object, jsonConfig);
            } else {
                throw new JSONException("Unsupported type");
            }
        }
    } else if (JSONUtils.isBoolean(object) || JSONUtils.isFunction(object) || JSONUtils.isNumber(object)
            || JSONUtils.isNull(object) || JSONUtils.isString(object) || object instanceof JSON) {
        fireArrayStartEvent(jsonConfig);
        JSONArray jsonArray = new JSONArray().element(object, jsonConfig);
        fireElementAddedEvent(0, jsonArray.get(0), jsonConfig);
        fireArrayStartEvent(jsonConfig);
        return jsonArray;
    } else if (object instanceof Enum) {
        return _fromArray((Enum) object, jsonConfig);
    } else if (object instanceof Annotation || (object != null && object.getClass().isAnnotation())) {
        throw new JSONException("Unsupported type");
    } else if (JSONUtils.isObject(object)) {
        fireArrayStartEvent(jsonConfig);
        JSONArray jsonArray = new JSONArray().element(JSONObject.fromObject(object, jsonConfig));
        fireElementAddedEvent(0, jsonArray.get(0), jsonConfig);
        fireArrayStartEvent(jsonConfig);
        return jsonArray;
    } else {
        throw new JSONException("Unsupported type");
    }
}

From source file:uk.ac.imperial.presage2.core.cli.run.ExecutorModule.java

/**
 * <p>/*from   w  ww. j  a  v a  2s .  c  om*/
 * Load an {@link AbstractModule} which can inject an
 * {@link ExecutorManager} with the appropriate {@link SimulationExecutor}s
 * as per provided configuration.
 * </p>
 * 
 * <p>
 * The executor config can be provided in two ways (in order of precedence):
 * </p>
 * <ul>
 * <li><code>executors.properties</code> file on the classpath. This file
 * should contain a <code>module</code> key who's value is the fully
 * qualified name of a class which extends {@link AbstractModule} and has a
 * public constructor which takes a single {@link Properties} object as an
 * argument or public no-args constructor. An instance of this class will be
 * returned.</li>
 * <li><code>executors.json</code> file on the classpath. This file contains
 * a specification of the executors to load in JSON format. If this file is
 * valid we will instantiate each executor defined in the spec and add it to
 * an {@link ExecutorModule} which will provide the bindings for them.</li>
 * </ul>
 * 
 * <h3>executors.json format</h3>
 * 
 * <p>
 * The <code>executors.json</code> file should contain a JSON object with
 * the following:
 * <ul>
 * <li><code>executors</code> key whose value is an array. Each element of
 * the array is a JSON object with the following keys:
 * <ul>
 * <li><code>class</code>: the fully qualified name of the executor class.</li>
 * <li><code>args</code>: an array of arguments to pass to a public
 * constructor of the class.</li>
 * <li><code>enableLogs</code> (optional): boolean value whether this
 * executor should save logs to file. Defaults to global value.</li>
 * <li><code>logDir</code> (optional): string path to save logs to. Defaults
 * to global value</li>
 * </ul>
 * </li>
 * <li><code>enableLogs</code> (optional): Global value for enableLogs for
 * each executor. Defaults to false.</li>
 * <li><code>logDir</code> (optional): Global value for logDir for each
 * executor. Default values depend on the executor.</li>
 * </ul>
 * </p>
 * <p>
 * e.g.:
 * </p>
 * 
 * <pre class="prettyprint">
 * {
 *    "executors": [{
 *       "class": "my.fully.qualified.Executor",
 *       "args": [1, "some string", true]
 *    },{
 *       ...
 *    }],
 * "enableLogs": true
 * }
 * </pre>
 * 
 * @return
 */
public static AbstractModule load() {
    Logger logger = Logger.getLogger(ExecutorModule.class);
    // look for executors.properties
    // This defines an AbstractModule to use instead of this one.
    // We try and load the module class given and return it.
    try {
        Properties execProps = new Properties();
        execProps.load(ExecutorModule.class.getClassLoader().getResourceAsStream("executors.properties"));
        String moduleName = execProps.getProperty("module", "");

        Class<? extends AbstractModule> module = Class.forName(moduleName).asSubclass(AbstractModule.class);
        // look for suitable ctor, either Properties parameter or default
        Constructor<? extends AbstractModule> ctor;
        try {
            ctor = module.getConstructor(Properties.class);
            return ctor.newInstance(execProps);
        } catch (NoSuchMethodException e) {
            ctor = module.getConstructor();
            return ctor.newInstance();
        }
    } catch (Exception e) {
        logger.debug("Could not create module from executors.properties");
    }
    // executors.properties fail, look for executors.json
    // This file defines a set of classes to load with parameters for the
    // constructor.
    // We try to create each defined executor and add it to this
    // ExecutorModule.
    try {
        // get executors.json file and parse to JSON.
        // throws NullPointerException if file doesn't exist, or
        // JSONException if we can't parse the JSON.
        InputStream is = ExecutorModule.class.getClassLoader().getResourceAsStream("executors.json");
        logger.debug("Processing executors from executors.json");
        JSONObject execConf = new JSONObject(new JSONTokener(new InputStreamReader(is)));
        // Create our module and look for executor specs under the executors
        // array in the JSON.
        ExecutorModule module = new ExecutorModule();
        JSONArray executors = execConf.getJSONArray("executors");

        // optional global settings
        boolean enableLogs = execConf.optBoolean("enableLogs", false);
        String logDir = execConf.optString("logDir");

        logger.info("Building Executors from executors.json");

        // Try and instantiate an instance of each executor in the spec.
        for (int i = 0; i < executors.length(); i++) {
            try {
                JSONObject executorSpec = executors.getJSONObject(i);
                String executorClass = executorSpec.getString("class");
                JSONArray args = executorSpec.getJSONArray("args");
                Class<? extends SimulationExecutor> clazz = Class.forName(executorClass)
                        .asSubclass(SimulationExecutor.class);
                // build constructor args.
                // We assume all types are in primitive form where
                // applicable.
                // The only available types are boolean, int, double and
                // String.
                Class<?>[] argTypes = new Class<?>[args.length()];
                Object[] argValues = new Object[args.length()];
                for (int j = 0; j < args.length(); j++) {
                    argValues[j] = args.get(j);
                    Class<?> type = argValues[j].getClass();
                    if (type == Boolean.class)
                        type = Boolean.TYPE;
                    else if (type == Integer.class)
                        type = Integer.TYPE;
                    else if (type == Double.class)
                        type = Double.TYPE;

                    argTypes[j] = type;
                }
                SimulationExecutor exe = clazz.getConstructor(argTypes).newInstance(argValues);
                logger.debug("Adding executor to pool: " + exe.toString());
                module.addExecutorInstance(exe);
                // logging config
                boolean exeEnableLog = executorSpec.optBoolean("enableLogs", enableLogs);
                String exeLogDir = executorSpec.optString("logDir", logDir);
                exe.enableLogs(exeEnableLog);
                if (exeLogDir.length() > 0) {
                    exe.setLogsDirectory(exeLogDir);
                }
            } catch (JSONException e) {
                logger.warn("Error parsing executor config", e);
            } catch (ClassNotFoundException e) {
                logger.warn("Unknown executor class in config", e);
            } catch (IllegalArgumentException e) {
                logger.warn("Illegal arguments for executor ctor", e);
            } catch (NoSuchMethodException e) {
                logger.warn("No matching public ctor for args in executor config", e);
            } catch (Exception e) {
                logger.warn("Could not create executor from specification", e);
            }
        }
        return module;
    } catch (JSONException e) {
        logger.debug("Could not create module from executors.json");
    } catch (NullPointerException e) {
        logger.debug("Could not open executors.json");
    }

    // no executor config, use a default config: 1 local sub process
    // executor.
    logger.info("Using default ExecutorModule.");
    return new ExecutorModule(1);
}

From source file:org.seasar.struts.lessconfig.factory.AbstractValidatorAnnotationHandler.java

protected String getAutoTypeValidatorName(PropertyDesc propDesc) {
    Class paramType = propDesc.getPropertyType();
    if (paramType.isArray()) {
        paramType = paramType.getComponentType();
    }/*from  w w  w.j  a v  a2  s. co m*/

    if (paramType.equals(Byte.class) || paramType.equals(Byte.TYPE)) {
        return "byte";
    } else if (Date.class.isAssignableFrom(paramType)) {
        return "date";
    } else if (paramType.equals(Double.class) || paramType.equals(Double.TYPE)) {
        return "double";
    } else if (paramType.equals(Float.class) || paramType.equals(Float.TYPE)) {
        return "float";
    } else if (paramType.equals(Integer.class) || paramType.equals(Integer.TYPE)) {
        return "integer";
    } else if (paramType.equals(Long.class) || paramType.equals(Long.TYPE)) {
        return "long";
    } else if (paramType.equals(Short.class) || paramType.equals(Short.TYPE)) {
        return "short";
    }

    return null;
}

From source file:com.medallia.spider.api.DynamicInputImpl.java

private static Object parseSingleValue(Class<?> rt, String v, AnnotatedElement anno,
        Map<Class<?>, InputArgParser<?>> inputArgParsers) {
    if (rt.isEnum()) {
        String vlow = v.toLowerCase();
        for (Enum e : rt.asSubclass(Enum.class).getEnumConstants()) {
            if (e.name().toLowerCase().equals(vlow))
                return e;
        }/* w  w  w .ja v a 2s.c  om*/
        throw new AssertionError("Enum constant not found: " + v);
    } else if (rt == Integer.class) {
        // map blank strings to null
        return Strings.hasContent(v) ? Integer.valueOf(v) : null;
    } else if (rt == Integer.TYPE) {
        // primitive int must have a value
        return Integer.valueOf(v);
    } else if (rt == Long.class) {
        // map blank strings to null
        return Strings.hasContent(v) ? Long.valueOf(v) : null;
    } else if (rt == Long.TYPE) {
        // primitive long must have a value
        return Long.valueOf(v);
    } else if (rt == Double.class) {
        // map blank strings to null
        return Strings.hasContent(v) ? Double.valueOf(v) : null;
    } else if (rt == Double.TYPE) {
        // primitive double must have a value
        return Double.valueOf(v);
    } else if (rt == String.class) {
        return v;
    } else if (rt.isArray()) {
        Input.List ann = anno.getAnnotation(Input.List.class);
        if (ann == null)
            throw new AssertionError("Array type but no annotation (see " + Input.class + "): " + anno);
        String separator = ann.separator();
        String[] strVals = v.split(separator, -1);
        Class<?> arrayType = rt.getComponentType();
        Object a = Array.newInstance(arrayType, strVals.length);
        for (int i = 0; i < strVals.length; i++) {
            Array.set(a, i, parseSingleValue(arrayType, strVals[i], anno, inputArgParsers));
        }
        return a;
    } else if (inputArgParsers != null) {
        InputArgParser<?> argParser = inputArgParsers.get(rt);
        if (argParser != null) {
            return argParser.parse(v);
        }
    }
    throw new AssertionError("Unknown return type " + rt + " (val: " + v + ")");
}

From source file:org.broadinstitute.gatk.queue.extensions.gatk.ArgumentField.java

/**
 * @param argType The class to check for options.
 * @return true if option should be used.
 *//* w  ww  . j  a v  a2s  . com*/
protected static boolean useFormatter(Class<?> argType) {
    return (argType.equals(Double.class) || argType.equals(Double.TYPE) || argType.equals(Float.class)
            || argType.equals(Float.TYPE));
}

From source file:com.projity.util.ClassUtils.java

/**
 * Get the corresponding object class from a primitive class
 * @param clazz primitive class//  w  w w .j a v  a 2 s  .  c om
 * @return Object class.
 * @throws ClassCastException if class is unknown primitive
 */
public static Class primitiveToObjectClass(Class clazz) {
    //      return MethodUtils.toNonPrimitiveClass(clazz);
    if (clazz == Boolean.TYPE)
        return Boolean.class;
    else if (clazz == Character.TYPE)
        return Character.class;
    else if (clazz == Byte.TYPE)
        return Byte.class;
    else if (clazz == Short.TYPE)
        return Short.class;
    else if (clazz == Integer.TYPE)
        return Integer.class;
    else if (clazz == Long.TYPE)
        return Long.class;
    else if (clazz == Float.TYPE)
        return Float.class;
    else if (clazz == Double.TYPE)
        return Double.class;
    throw new ClassCastException("Cannot convert class" + clazz + " to an object class");
}