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.evosuite.testcase.fm.MethodDescriptor.java

public Object executeMatcher(int i) throws IllegalArgumentException {
    if (i < 0 || i >= getNumberOfInputParameters()) {
        throw new IllegalArgumentException("Invalid index: " + i);
    }//  w ww .jav  a  2s. c  om

    Type[] types = method.getParameterTypes();
    Type type = types[i];

    try {
        if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
            return Mockito.anyInt();
        } else if (type.equals(Long.TYPE) || type.equals(Long.class)) {
            return Mockito.anyLong();
        } else if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) {
            return Mockito.anyBoolean();
        } else if (type.equals(Double.TYPE) || type.equals(Double.class)) {
            return Mockito.anyDouble();
        } else if (type.equals(Float.TYPE) || type.equals(Float.class)) {
            return Mockito.anyFloat();
        } else if (type.equals(Short.TYPE) || type.equals(Short.class)) {
            return Mockito.anyShort();
        } else if (type.equals(Character.TYPE) || type.equals(Character.class)) {
            return Mockito.anyChar();
        } else if (type.equals(String.class)) {
            return Mockito.anyString();
        } else {
            return Mockito.any(type.getClass());
        }
    } catch (Exception e) {
        logger.error("Failed to executed Mockito matcher n{} of type {} in {}.{}: {}", i, type, className,
                methodName, e.getMessage());
        throw new EvosuiteError(e);
    }
}

From source file:org.eiichiro.bootleg.AbstractRequest.java

/**
 * Returns the default value of the specified primitive type.
 * //  w  w  w. j a  va  2s.  com
 * @param type The primitive type.
 * @return The default value of the specified primitive type.
 */
protected Object primitive(Type type) {
    Class<?> rawType = Types.getRawType(type);

    if (rawType.equals(Boolean.TYPE)) {
        return (boolean) false;
    } else if (rawType.equals(Character.TYPE)) {
        return (char) 0;
    } else if (rawType.equals(Byte.TYPE)) {
        return (byte) 0;
    } else if (rawType.equals(Double.TYPE)) {
        return (double) 0.0;
    } else if (rawType.equals(Float.TYPE)) {
        return (float) 0.0;
    } else if (rawType.equals(Integer.TYPE)) {
        return (int) 0;
    } else {
        // short.
        return (short) 0;
    }
}

From source file:org.hyperic.hq.product.jmx.MBeanUtil.java

private static void initConverters() {
    addConverter(Object.class, new Converter() {
        public Object convert(String param) {
            return param;
        }//from  w w  w.  j a  v  a  2  s.c om
    });

    addConverter(Short.class, new Converter() {
        public Object convert(String param) {
            return Short.valueOf(param);
        }
    });

    addConverter(Integer.class, new Converter() {
        public Object convert(String param) {
            return Integer.valueOf(param);
        }
    });

    addConverter(Long.class, new Converter() {
        public Object convert(String param) {
            return Long.valueOf(param);
        }
    });

    addConverter(Double.class, new Converter() {
        public Object convert(String param) {
            return Double.valueOf(param);
        }
    });

    addConverter(Boolean.class, new Converter() {
        public Object convert(String param) {
            return Boolean.valueOf(param);
        }
    });

    addConverter(File.class, new Converter() {
        public Object convert(String param) {
            return new File(param);
        }
    });

    addConverter(URL.class, new Converter() {
        public Object convert(String param) {
            try {
                return new URL(param);
            } catch (MalformedURLException e) {
                throw invalid(param, e);
            }
        }
    });

    addConverter(ObjectName.class, new Converter() {
        public Object convert(String param) {
            try {
                return new ObjectName(param);
            } catch (MalformedObjectNameException e) {
                throw invalid(param, e);
            }
        }
    });

    addConverter(List.class, new ListConverter() {
        public Object convert(String[] params) {
            return Arrays.asList(params);
        }
    });

    addConverter(String[].class, new ListConverter() {
        public Object convert(String[] params) {
            return params;
        }
    });

    addConverter(Long[].class, new ListConverter() {
        public Object convert(String[] params) {
            Long[] args = new Long[params.length];
            for (int i = 0; i < params.length; i++) {
                args[i] = Long.valueOf(params[i]);
            }
            return args;
        }
    });

    addConverter(Integer[].class, new ListConverter() {
        public Object convert(String[] params) {
            Integer[] args = new Integer[params.length];
            for (int i = 0; i < params.length; i++) {
                args[i] = Integer.valueOf(params[i]);
            }
            return args;
        }
    });

    addConverter(Double[].class, new ListConverter() {
        public Object convert(String[] params) {
            Double[] args = new Double[params.length];
            for (int i = 0; i < params.length; i++) {
                args[i] = Double.valueOf(params[i]);
            }
            return args;
        }
    });

    addConverter(Short[].class, new ListConverter() {
        public Object convert(String[] params) {
            Short[] args = new Short[params.length];
            for (int i = 0; i < params.length; i++) {
                args[i] = Short.valueOf(params[i]);
            }
            return args;
        }
    });

    addConverter(Boolean[].class, new ListConverter() {
        public Object convert(String[] params) {
            Boolean[] args = new Boolean[params.length];
            for (int i = 0; i < params.length; i++) {
                args[i] = Boolean.valueOf(params[i]);
            }
            return args;
        }
    });

    addConverter(long[].class, new ListConverter() {
        public Object convert(String[] params) {
            long[] args = new long[params.length];
            for (int i = 0; i < params.length; i++) {
                args[i] = Long.parseLong(params[i]);
            }
            return args;
        }
    });

    addConverter(int[].class, new ListConverter() {
        public Object convert(String[] params) {
            int[] args = new int[params.length];
            for (int i = 0; i < params.length; i++) {
                args[i] = Integer.parseInt(params[i]);
            }
            return args;
        }
    });

    addConverter(double[].class, new ListConverter() {
        public Object convert(String[] params) {
            double[] args = new double[params.length];
            for (int i = 0; i < params.length; i++) {
                args[i] = Double.parseDouble(params[i]);
            }
            return args;
        }
    });

    addConverter(short[].class, new ListConverter() {
        public Object convert(String[] params) {
            short[] args = new short[params.length];
            for (int i = 0; i < params.length; i++) {
                args[i] = Short.parseShort(params[i]);
            }
            return args;
        }
    });

    addConverter(boolean[].class, new ListConverter() {
        public Object convert(String[] params) {
            boolean[] args = new boolean[params.length];
            for (int i = 0; i < params.length; i++) {
                args[i] = params[i].equals("true") ? true : false;
            }
            return args;
        }
    });

    Class[][] aliases = { { String.class, Object.class }, { Short.TYPE, Short.class },
            { Integer.TYPE, Integer.class }, { Long.TYPE, Long.class }, { Double.TYPE, Double.class },
            { Boolean.TYPE, Boolean.class }, };

    for (int i = 0; i < aliases.length; i++) {
        addConverter(aliases[i][0], aliases[i][1]);
    }
}

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

/**
 * Tests if Class represents a primitive double or wrapper.<br>
 *///from  w  ww . ja va2 s. c o m
public static boolean isDouble(Class clazz) {
    return clazz != null && (Double.TYPE.isAssignableFrom(clazz) || Double.class.isAssignableFrom(clazz));
}

From source file:org.opoo.util.ClassUtils.java

public static boolean isCompatibleType(Object value, Class type) {
    // Do object check first, then primitives
    if (value == null || type.isInstance(value)) {
        return true;
    } else if (type.equals(Integer.TYPE) && Integer.class.isInstance(value)) {
        return true;
    } else if (type.equals(Long.TYPE) && Long.class.isInstance(value)) {
        return true;
    } else if (type.equals(Double.TYPE) && Double.class.isInstance(value)) {
        return true;
    } else if (type.equals(Float.TYPE) && Float.class.isInstance(value)) {
        return true;
    } else if (type.equals(Short.TYPE) && Short.class.isInstance(value)) {
        return true;
    } else if (type.equals(Byte.TYPE) && Byte.class.isInstance(value)) {
        return true;
    } else if (type.equals(Character.TYPE) && Character.class.isInstance(value)) {
        return true;
    } else if (type.equals(Boolean.TYPE) && Boolean.class.isInstance(value)) {
        return true;
    } else {/*w  w w.  j a v a  2 s.  c o  m*/
        return false;
    }
}

From source file:org.acmsl.commons.utils.ConversionUtils.java

/**
 * Converts given String to double, if given value is not null.
 * @param value the value to convert.//w w  w.  ja  va2  s  .  co  m
 * @return the converted value.
 */
@Nullable
public Double toDoubleIfNotNull(@Nullable final String value) {
    Double result = null;

    @Nullable
    final Converter t_Converter = ConvertUtils.lookup(Double.TYPE);

    if (t_Converter != null) {
        @Nullable
        final Object t_Result = t_Converter.convert(Double.TYPE, value);

        if (t_Result instanceof Double) {
            result = (Double) t_Result;
        }
    }

    return result;
}

From source file:pe.com.mmh.sisgap.utils.BasicDynaBean.java

/**
 * Return the value of a simple property with the specified name.
 *
 * @param name Name of the property whose value is to be retrieved
 *
 * @exception IllegalArgumentException if there is no property
 *  of the specified name//from  w w w.  j  a  v a2s.  co  m
 */
public Object get(String name) {

    // Return any non-null value for the specified property
    Object value = values.get(name);
    if (value != null) {
        return (value);
    }

    // Return a null value for a non-primitive property
    Class type = getDynaProperty(name).getType();
    if (!type.isPrimitive()) {
        return (value);
    }

    // Manufacture default values for primitive properties
    if (type == Boolean.TYPE) {
        return (Boolean.FALSE);
    } else if (type == Byte.TYPE) {
        return (new Byte((byte) 0));
    } else if (type == Character.TYPE) {
        return (new Character((char) 0));
    } else if (type == Double.TYPE) {
        return (new Double((double) 0.0));
    } else if (type == Float.TYPE) {
        return (new Float((float) 0.0));
    } else if (type == Integer.TYPE) {
        return (new Integer((int) 0));
    } else if (type == Long.TYPE) {
        return (new Long((int) 0));
    } else if (type == Short.TYPE) {
        return (new Short((short) 0));
    } else {
        return (null);
    }

}

From source file:org.primeframework.mvc.parameter.convert.converters.NumberConverterTest.java

/**
 * Test the conversion from Strings.//from   w ww .  jav a  2 s .  co  m
 */
@Test
public void toStrings() {
    GlobalConverter converter = new NumberConverter(new MockConfiguration());
    String str = converter.convertToString(Integer.class, null, "testExpr", null);
    assertNull(str);

    str = converter.convertToString(Byte.class, null, "testExpr", (byte) 42);
    assertEquals(str, "42");

    str = converter.convertToString(Byte.TYPE, null, "testExpr", (byte) 42);
    assertEquals(str, "42");

    str = converter.convertToString(Short.class, null, "testExpr", (short) 42);
    assertEquals(str, "42");

    str = converter.convertToString(Short.TYPE, null, "testExpr", (short) 42);
    assertEquals(str, "42");

    str = converter.convertToString(Integer.class, null, "testExpr", 42);
    assertEquals(str, "42");

    str = converter.convertToString(Integer.class, null, "testExpr", 42);
    assertEquals(str, "42");

    str = converter.convertToString(Long.class, null, "testExpr", 42l);
    assertEquals(str, "42");

    str = converter.convertToString(Long.TYPE, null, "testExpr", 42l);
    assertEquals(str, "42");

    str = converter.convertToString(Float.class, null, "testExpr", 42f);
    assertEquals(str, "42.0");

    str = converter.convertToString(Float.TYPE, null, "testExpr", 42f);
    assertEquals(str, "42.0");

    str = converter.convertToString(Double.class, null, "testExpr", 42.0);
    assertEquals(str, "42.0");

    str = converter.convertToString(Double.TYPE, null, "testExpr", 42.0);
    assertEquals(str, "42.0");
}

From source file:com.collaborne.jsonschema.generator.pojo.PojoGenerator.java

@Inject
@VisibleForTesting/* w  w  w . j a va2s . c o  m*/
protected PojoGenerator(PojoClassGenerator classGenerator, PojoArrayGenerator arrayGenerator,
        PojoStringGenerator stringGenerator) {
    this.typeGenerators.put("object", classGenerator);
    this.typeGenerators.put("array", arrayGenerator);
    if (getFeature(FEATURE_USE_SIMPLE_PLAIN_TYPES)) {
        // TODO: if additional restrictions are given on these types we can either implement specific
        //       types (for example we provide a base library for each of the plain types, and configure them
        //       to check the restrictions), or we could simply ignore those.
        this.typeGenerators.put("string", new SimplePojoTypeGenerator(ClassName.create(String.class)));
    } else {
        this.typeGenerators.put("string", stringGenerator);
    }
    this.typeGenerators.put("integer", new SimplePojoTypeGenerator(ClassName.create(Integer.TYPE)));
    this.typeGenerators.put("number", new SimplePojoTypeGenerator(ClassName.create(Double.TYPE)));
    this.typeGenerators.put("boolean", new SimplePojoTypeGenerator(ClassName.create(Boolean.TYPE)));
}

From source file:org.wrml.runtime.syntax.DefaultSyntaxLoader.java

private final void loadSystemSyntaxes() {

    for (final SystemSyntax systemSyntax : SystemSyntax.values()) {
        final SyntaxHandler<?> syntaxHandler = systemSyntax.getSyntaxHandler();

        switch (systemSyntax) {

        case Boolean:
            _SyntaxHandlers.put(Boolean.TYPE, syntaxHandler);
            break;

        case Double:
            _SyntaxHandlers.put(Double.TYPE, syntaxHandler);
            break;

        case Integer:
            _SyntaxHandlers.put(Integer.TYPE, syntaxHandler);
            break;

        case Long:
            _SyntaxHandlers.put(Long.TYPE, syntaxHandler);
            break;

        default:/*from   w w  w . jav a2  s .  c  o  m*/
            break;

        }

        final URI syntaxUri = systemSyntax.getSyntaxUri();
        loadSyntaxInternal(syntaxUri, syntaxHandler);
    }

    final Context context = getContext();

    // Loop again to build the system Syntax models now that the
    for (final SystemSyntax systemSyntax : SystemSyntax.values()) {
        final Syntax syntax = context.newModel(Syntax.class);

        final URI syntaxUri = systemSyntax.getSyntaxUri();
        syntax.setUniqueName(systemSyntax.getUniqueName());
        syntax.setUri(syntaxUri);

        _SystemSyntaxes.put(syntaxUri, syntax);
    }

}