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.lunarray.model.descriptor.builder.annotation.util.RenderDefaultsUtil.java

/**
 * Fills the defaults.//from w  ww .  j a v a  2 s  .  co m
 */
private RenderDefaultsUtil() {
    this.renderDefaults = new HashMap<Class<?>, RenderType>();
    this.renderDefaults.put(Calendar.class, RenderType.DATE_PICKER);
    this.renderDefaults.put(Date.class, RenderType.DATE_PICKER);
    this.renderDefaults.put(java.sql.Date.class, RenderType.DATE_PICKER);
    this.renderDefaults.put(String.class, RenderType.TEXT);
    this.renderDefaults.put(Integer.class, RenderType.TEXT);
    this.renderDefaults.put(Double.class, RenderType.TEXT);
    this.renderDefaults.put(Float.class, RenderType.TEXT);
    this.renderDefaults.put(Long.class, RenderType.TEXT);
    this.renderDefaults.put(Byte.class, RenderType.TEXT);
    this.renderDefaults.put(Short.class, RenderType.TEXT);
    this.renderDefaults.put(Character.class, RenderType.TEXT);
    this.renderDefaults.put(Integer.TYPE, RenderType.TEXT);
    this.renderDefaults.put(Double.TYPE, RenderType.TEXT);
    this.renderDefaults.put(Float.TYPE, RenderType.TEXT);
    this.renderDefaults.put(Long.TYPE, RenderType.TEXT);
    this.renderDefaults.put(Byte.TYPE, RenderType.TEXT);
    this.renderDefaults.put(Short.TYPE, RenderType.TEXT);
    this.renderDefaults.put(Character.TYPE, RenderType.TEXT);
    this.renderDefaults.put(BigDecimal.class, RenderType.TEXT);
    this.renderDefaults.put(BigInteger.class, RenderType.TEXT);
    this.renderDefaults.put(Boolean.class, RenderType.CHECKBOX);
    this.renderDefaults.put(Boolean.TYPE, RenderType.CHECKBOX);
}

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

@Test
public void testTo_convertToDouble() throws Exception {
    assertEquals(10.0, Convert.to(Double.class, 10), 0);
    assertEquals(10.0, Convert.to(Double.class, 10.0), 0);
    assertEquals(10.0, Convert.to(Double.class, 10.0f), 0);
    assertEquals(10.0, Convert.to(Double.class, 10l), 0);
    assertEquals(10.0, Convert.to(Double.class, (short) 10), 0);
    assertEquals(10.0, Convert.to(Double.class, (byte) 10), 0);
    assertEquals(10.0, Convert.to(Double.class, Complex.valueOf(10)), 0);
    assertEquals(1.0, Convert.to(Double.class, Logical.TRUE), 0);
    assertEquals(1.0, Convert.to(Double.class, true), 0);

    assertEquals(10.0, Convert.to(Double.TYPE, 10), 0);
    assertEquals(10.0, Convert.to(Double.TYPE, 10.0), 0);
    assertEquals(10.0, Convert.to(Double.TYPE, 10.0f), 0);
    assertEquals(10.0, Convert.to(Double.TYPE, 10l), 0);
    assertEquals(10.0, Convert.to(Double.TYPE, (short) 10), 0);
    assertEquals(10.0, Convert.to(Double.TYPE, (byte) 10), 0);
    assertEquals(10.0, Convert.to(Double.TYPE, Complex.valueOf(10)), 0);
    assertEquals(1.0, Convert.to(Double.TYPE, Logical.TRUE), 0);
    assertEquals(1.0, Convert.to(Double.TYPE, true), 0);
}

From source file:io.github.benas.jpopulator.impl.DefaultRandomizer.java

/**
 * Generate a random value for the given type.
 *
 * @param type the type for which a random value will be generated
 * @return a random value for the given type or null if the type is not supported
 *///from w ww .j  a  va2 s  . c  o  m
public static Object getRandomValue(final Class type) {

    /*
     * String and Character types
     */
    if (type.equals(String.class)) {
        return RandomStringUtils.randomAlphabetic(ConstantsUtil.DEFAULT_STRING_LENGTH);
    }
    if (type.equals(Character.TYPE) || type.equals(Character.class)) {
        return RandomStringUtils.randomAlphabetic(1).charAt(0);
    }

    /*
     * Boolean type
     */
    if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) {
        return ConstantsUtil.RANDOM.nextBoolean();
    }

    /*
     * Numeric types
     */
    if (type.equals(Byte.TYPE) || type.equals(Byte.class)) {
        return (byte) (ConstantsUtil.RANDOM.nextInt());
    }
    if (type.equals(Short.TYPE) || type.equals(Short.class)) {
        return (short) (ConstantsUtil.RANDOM.nextInt());
    }
    if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
        return ConstantsUtil.RANDOM.nextInt();
    }
    if (type.equals(Long.TYPE) || type.equals(Long.class)) {
        return ConstantsUtil.RANDOM.nextLong();
    }
    if (type.equals(Double.TYPE) || type.equals(Double.class)) {
        return ConstantsUtil.RANDOM.nextDouble();
    }
    if (type.equals(Float.TYPE) || type.equals(Float.class)) {
        return ConstantsUtil.RANDOM.nextFloat();
    }
    if (type.equals(BigInteger.class)) {
        return new BigInteger(
                Math.abs(ConstantsUtil.RANDOM.nextInt(ConstantsUtil.DEFAULT_BIG_INTEGER_NUM_BITS_LENGTH)),
                ConstantsUtil.RANDOM);
    }
    if (type.equals(BigDecimal.class)) {
        return new BigDecimal(ConstantsUtil.RANDOM.nextDouble());
    }
    if (type.equals(AtomicLong.class)) {
        return new AtomicLong(ConstantsUtil.RANDOM.nextLong());
    }
    if (type.equals(AtomicInteger.class)) {
        return new AtomicInteger(ConstantsUtil.RANDOM.nextInt());
    }

    /*
     * Date and time types
     */
    if (type.equals(java.util.Date.class)) {
        return ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue();
    }
    if (type.equals(java.sql.Date.class)) {
        return new java.sql.Date(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime());
    }
    if (type.equals(java.sql.Time.class)) {
        return new java.sql.Time(ConstantsUtil.RANDOM.nextLong());
    }
    if (type.equals(java.sql.Timestamp.class)) {
        return new java.sql.Timestamp(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime());
    }
    if (type.equals(Calendar.class)) {
        return Calendar.getInstance();
    }
    if (type.equals(org.joda.time.DateTime.class)) {
        return new org.joda.time.DateTime(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime());
    }
    if (type.equals(org.joda.time.LocalDate.class)) {
        return new org.joda.time.LocalDate(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime());
    }
    if (type.equals(org.joda.time.LocalTime.class)) {
        return new org.joda.time.LocalTime(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime());
    }
    if (type.equals(org.joda.time.LocalDateTime.class)) {
        return new org.joda.time.LocalDateTime(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime());
    }
    if (type.equals(org.joda.time.Duration.class)) {
        return new org.joda.time.Duration(Math.abs(ConstantsUtil.RANDOM.nextLong()));
    }
    if (type.equals(org.joda.time.Period.class)) {
        return new org.joda.time.Period(Math.abs(ConstantsUtil.RANDOM.nextInt()));
    }
    if (type.equals(org.joda.time.Interval.class)) {
        long startDate = Math.abs(ConstantsUtil.RANDOM.nextInt());
        long endDate = startDate + Math.abs(ConstantsUtil.RANDOM.nextInt());
        return new org.joda.time.Interval(startDate, endDate);
    }

    /*
     * Enum type
     */
    if (type.isEnum() && type.getEnumConstants().length > 0) {
        Object[] enumConstants = type.getEnumConstants();
        return enumConstants[ConstantsUtil.RANDOM.nextInt(enumConstants.length)];
    }

    /*
     * Return null for any unsupported type
     */
    return null;

}

From source file:org.openamf.util.OpenAMFUtils.java

public static boolean typesMatch(Class parameterType, Object parameter) {
    log.debug("expected class: " + parameterType.getName());
    if (parameter == null) {
        log.debug("parameter is null");
    } else {// w w  w. jav a  2 s  .  c  om
        log.debug("parameter class: " + parameter.getClass().getName());
    }
    boolean typesMatch = parameterType.isInstance(parameter);
    if (!typesMatch) {
        if (parameterType.equals(Boolean.TYPE) && parameter instanceof Boolean) {
            typesMatch = true;
        } else if (parameterType.equals(Character.TYPE) && parameter instanceof Character) {
            typesMatch = true;
        } else if (parameterType.equals(Byte.TYPE) && parameter instanceof Byte) {
            typesMatch = true;
        } else if (parameterType.equals(Short.TYPE) && parameter instanceof Short) {
            typesMatch = true;
        } else if (parameterType.equals(Integer.TYPE) && parameter instanceof Integer) {
            typesMatch = true;
        } else if (parameterType.equals(Long.TYPE) && parameter instanceof Long) {
            typesMatch = true;
        } else if (parameterType.equals(Float.TYPE) && parameter instanceof Float) {
            typesMatch = true;
        } else if (parameterType.equals(Double.TYPE) && parameter instanceof Double) {
            typesMatch = true;
        }
    }
    return typesMatch;
}

From source file:org.openTwoFactor.clientExt.net.sf.ezmorph.object.NumberMorpher.java

/**
 * Creates a new morpher for the target type.
 *
 * @param type must be a primitive or wrapper type. BigDecimal and BigInteger
 *        are also supported.//from   ww  w .  ja v a2  s  .c om
 */
public NumberMorpher(Class type) {
    super(false);

    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");
    }

    this.type = type;
}

From source file:it.greenvulcano.gvesb.http.ProtocolFactory.java

/**
 *
 * @param objectClass/*from   ww  w. j a  v  a 2s. c o m*/
 *        Object class to instantiate
 * @param node
 *        The configuration of constructor parameters.
 * @return
 */
private static Object createObjectUsingConstructor(Class<?> objectClass, Node node) throws Exception {
    NodeList paramList = XMLConfig.getNodeList(node, "constructor-param");
    Class<?>[] types = new Class[paramList.getLength()];
    Object[] params = new Object[types.length];

    for (int i = 0; i < types.length; ++i) {
        Node paramNode = paramList.item(i);
        String type = XMLConfig.get(paramNode, "@type");
        String value = XMLConfig.getDecrypted(paramNode, "@value");
        Class<?> cls = null;
        if (type.equals("byte")) {
            cls = Byte.TYPE;
        } else if (type.equals("boolean")) {
            cls = Boolean.TYPE;
        } else if (type.equals("char")) {
            cls = Character.TYPE;
        } else if (type.equals("double")) {
            cls = Double.TYPE;
        } else if (type.equals("float")) {
            cls = Float.TYPE;
        } else if (type.equals("int")) {
            cls = Integer.TYPE;
        } else if (type.equals("long")) {
            cls = Long.TYPE;
        } else if (type.equals("short")) {
            cls = Short.TYPE;
        } else if (type.equals("String")) {
            cls = String.class;
        }
        types[i] = cls;
        params[i] = cast(value, cls);
    }

    Constructor<?> constr = objectClass.getConstructor(types);
    return constr.newInstance(params);
}

From source file:com.textuality.lifesaver2.Columns.java

public Columns(Context context, String[] names, Class<?>[] classes, String key1, String key2) {
    this.mNames = names;
    mTypes = new Type[names.length];
    mKey1 = key1;/* ww w. j av a  2 s .c  o  m*/
    mKey2 = key2;
    mNameFinder = new NameFinder(context);
    for (int i = 0; i < names.length; i++) {

        if (classes[i] == String.class)
            mTypes[i] = Type.STRING;
        else if (classes[i] == Integer.TYPE || classes[i] == Integer.class)
            mTypes[i] = Type.INT;
        else if (classes[i] == Long.TYPE || classes[i] == Long.class)
            mTypes[i] = Type.LONG;
        else if (classes[i] == Float.TYPE || classes[i] == Float.class)
            mTypes[i] = Type.FLOAT;
        else if (classes[i] == Double.TYPE || classes[i] == Double.class)
            mTypes[i] = Type.DOUBLE;
    }
}

From source file:Main.java

/** Evaluates an XPath returning null if not found. <br>
 *  <br>/*from   ww w . ja va2  s  .co m*/
 *  This is intended for use with pre-defined XPaths stored as constants,
 *  where runtime exceptions should not be possible.
 *  @param expression The XPath expression to evaluate.
 *  @param item       The {@link Node} or other item to evaluate the XPath on.
 *  @param type       The type to return, this must be one of the following:
 *                    {@link String}, {@link CharSequence}, {@link Boolean},
 *                    {@link Node}, {@link NodeList}, {@link Double}, or
 *                    {@link Number}.
 *  @throws AssertionError If the nested call to <tt>XPath.newInstance(path)</tt>
 *                         throws an {@link XPathExpressionException}.
 */
public static <T> T evalXPath(String expression, Object item, Class<T> type) {
    Object val;

    if (type == String.class)
        val = evalXPath(expression, item, XPathConstants.STRING);
    else if (type == CharSequence.class)
        val = evalXPath(expression, item, XPathConstants.STRING);
    else if (type == Boolean.class)
        val = evalXPath(expression, item, XPathConstants.BOOLEAN);
    else if (type == Boolean.TYPE)
        val = evalXPath(expression, item, XPathConstants.BOOLEAN);
    else if (type == Node.class)
        val = evalXPath(expression, item, XPathConstants.NODE);
    else if (type == NodeList.class)
        val = evalXPath(expression, item, XPathConstants.NODESET);
    else if (type == Double.class)
        val = evalXPath(expression, item, XPathConstants.NUMBER);
    else if (type == Double.TYPE)
        val = evalXPath(expression, item, XPathConstants.NUMBER);
    else if (type == Number.class)
        val = evalXPath(expression, item, XPathConstants.NUMBER);
    else
        throw new IllegalArgumentException("Invalid type given " + type);

    return type.cast(val);
}

From source file:net.sf.ij_plugins.util.DialogUtil.java

/**
 * Utility to automatically create ImageJ's GenericDialog for editing bean properties. It uses BeanInfo to extract
 * display names for each field. If a fields type is not supported irs name will be displayed with a tag
 * "[Unsupported type: class_name]"./*from w  w  w . ja v a2s  .  c  o  m*/
 *
 * @param bean
 * @return <code>true</code> if user closed bean dialog using OK button, <code>false</code> otherwise.
 */
static public boolean showGenericDialog(final Object bean, final String title) {
    final BeanInfo beanInfo;
    try {
        beanInfo = Introspector.getBeanInfo(bean.getClass());
    } catch (IntrospectionException e) {
        throw new IJPluginsRuntimeException("Error extracting bean info.", e);
    }

    final GenericDialog genericDialog = new GenericDialog(title);

    // Create generic dialog fields for each bean's property
    final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
    try {
        for (int i = 0; i < propertyDescriptors.length; i++) {
            final PropertyDescriptor pd = propertyDescriptors[i];
            final Class type = pd.getPropertyType();
            if (type.equals(Class.class) && "class".equals(pd.getName())) {
                continue;
            }

            final Object o = PropertyUtils.getSimpleProperty(bean, pd.getName());
            if (type.equals(Boolean.TYPE)) {
                boolean value = ((Boolean) o).booleanValue();
                genericDialog.addCheckbox(pd.getDisplayName(), value);
            } else if (type.equals(Integer.TYPE)) {
                int value = ((Integer) o).intValue();
                genericDialog.addNumericField(pd.getDisplayName(), value, 0);
            } else if (type.equals(Float.TYPE)) {
                double value = ((Float) o).doubleValue();
                genericDialog.addNumericField(pd.getDisplayName(), value, 6, 10, "");
            } else if (type.equals(Double.TYPE)) {
                double value = ((Double) o).doubleValue();
                genericDialog.addNumericField(pd.getDisplayName(), value, 6, 10, "");
            } else {
                genericDialog.addMessage(pd.getDisplayName() + "[Unsupported type: " + type + "]");
            }

        }
    } catch (IllegalAccessException e) {
        throw new IJPluginsRuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new IJPluginsRuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new IJPluginsRuntimeException(e);
    }

    //        final Panel helpPanel = new Panel();
    //        helpPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0));
    //        final Button helpButton = new Button("Help");
    ////                helpButton.addActionListener(this);
    //        helpPanel.add(helpButton);
    //        genericDialog.addPanel(helpPanel, GridBagConstraints.EAST, new Insets(15,0,0,0));

    // Show modal dialog
    genericDialog.showDialog();
    if (genericDialog.wasCanceled()) {
        return false;
    }

    // Read fields from generic dialog into bean's properties.
    try {
        for (int i = 0; i < propertyDescriptors.length; i++) {
            final PropertyDescriptor pd = propertyDescriptors[i];
            final Class type = pd.getPropertyType();
            final Object propertyValue;
            if (type.equals(Boolean.TYPE)) {
                boolean value = genericDialog.getNextBoolean();
                propertyValue = Boolean.valueOf(value);
            } else if (type.equals(Integer.TYPE)) {
                int value = (int) Math.round(genericDialog.getNextNumber());
                propertyValue = new Integer(value);
            } else if (type.equals(Float.TYPE)) {
                double value = genericDialog.getNextNumber();
                propertyValue = new Float(value);
            } else if (type.equals(Double.TYPE)) {
                double value = genericDialog.getNextNumber();
                propertyValue = new Double(value);
            } else {
                continue;
            }
            PropertyUtils.setProperty(bean, pd.getName(), propertyValue);
        }
    } catch (IllegalAccessException e) {
        throw new IJPluginsRuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new IJPluginsRuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new IJPluginsRuntimeException(e);
    }

    return true;
}

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

@Test
public void testInferType() throws Exception {
    assertEquals(VectorType.DOUBLE, VectorType.of(Double.class));
    assertEquals(VectorType.INT, VectorType.of(Integer.class));
    assertEquals(VectorType.LOGICAL, VectorType.of(Boolean.class));
    assertEquals(VectorType.LOGICAL, VectorType.of(Logical.class));
    assertEquals(VectorType.COMPLEX, VectorType.of(Complex.class));
    assertEquals(VectorType.STRING, VectorType.of(String.class));
    assertEquals(VectorType.DOUBLE, VectorType.of(Double.TYPE));
    assertEquals(VectorType.INT, VectorType.of(Integer.TYPE));
    assertEquals(VectorType.OBJECT, VectorType.of(null));
}