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:com.flexive.faces.renderer.FxSelectRenderer.java

/**
 * Convert select many values to given array class
 *
 * @param context      faces context/*from w  w w .  j a v a2 s.co  m*/
 * @param uiSelectMany select many component
 * @param arrayClass   the array class
 * @param newValues    new values to convert
 * @return converted values
 * @throws ConverterException on errors
 */
protected Object convertSelectManyValues(FacesContext context, UISelectMany uiSelectMany, Class arrayClass,
        String[] newValues) throws ConverterException {

    Object result;
    Converter converter;
    int len = (null != newValues ? newValues.length : 0);

    Class elementType = arrayClass.getComponentType();

    // Optimization: If the elementType is String, we don't need
    // conversion.  Just return newValues.
    if (elementType.equals(String.class))
        return newValues;

    try {
        result = Array.newInstance(elementType, len);
    } catch (Exception e) {
        throw new ConverterException(e);
    }

    // bail out now if we have no new values, returning our
    // oh-so-useful zero-length array.
    if (null == newValues)
        return result;

    // obtain a converter.

    // attached converter takes priority
    if (null == (converter = uiSelectMany.getConverter())) {
        // Otherwise, look for a by-type converter
        if (null == (converter = FxJsfComponentUtils.getConverterForClass(elementType, context))) {
            // if that fails, and the attached values are of Object type,
            // we don't need conversion.
            if (elementType.equals(Object.class))
                return newValues;
            StringBuffer valueStr = new StringBuffer();
            for (int i = 0; i < len; i++) {
                if (i == 0)
                    valueStr.append(newValues[i]);
                else
                    valueStr.append(' ').append(newValues[i]);
            }
            throw new ConverterException("Could not get a converter for " + String.valueOf(valueStr));
        }
    }

    if (elementType.isPrimitive()) {
        for (int i = 0; i < len; i++) {
            if (elementType.equals(Boolean.TYPE)) {
                Array.setBoolean(result, i,
                        ((Boolean) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Byte.TYPE)) {
                Array.setByte(result, i, ((Byte) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Double.TYPE)) {
                Array.setDouble(result, i,
                        ((Double) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Float.TYPE)) {
                Array.setFloat(result, i, ((Float) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Integer.TYPE)) {
                Array.setInt(result, i, ((Integer) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Character.TYPE)) {
                Array.setChar(result, i,
                        ((Character) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Short.TYPE)) {
                Array.setShort(result, i, ((Short) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Long.TYPE)) {
                Array.setLong(result, i, ((Long) converter.getAsObject(context, uiSelectMany, newValues[i])));
            }
        }
    } else {
        for (int i = 0; i < len; i++)
            Array.set(result, i, converter.getAsObject(context, uiSelectMany, newValues[i]));
    }
    return result;
}

From source file:com.netflix.governator.lifecycle.LifecycleManager.java

private void assignConfiguration(Object obj, Field field) throws Exception {
    Configuration configuration = field.getAnnotation(Configuration.class);
    String configurationName = configuration.value();
    ConfigurationKey key = new ConfigurationKey(configurationName, KeyParser.parse(configurationName));

    Object value = null;//ww w  .  j  ava  2s.co m

    boolean has = configurationProvider.has(key);
    if (has) {
        try {
            if (String.class.isAssignableFrom(field.getType())) {
                value = configurationProvider.getString(key);
            } else if (Boolean.class.isAssignableFrom(field.getType())
                    || Boolean.TYPE.isAssignableFrom(field.getType())) {
                value = configurationProvider.getBoolean(key);
            } else if (Integer.class.isAssignableFrom(field.getType())
                    || Integer.TYPE.isAssignableFrom(field.getType())) {
                value = configurationProvider.getInteger(key);
            } else if (Long.class.isAssignableFrom(field.getType())
                    || Long.TYPE.isAssignableFrom(field.getType())) {
                value = configurationProvider.getLong(key);
            } else if (Double.class.isAssignableFrom(field.getType())
                    || Double.TYPE.isAssignableFrom(field.getType())) {
                value = configurationProvider.getDouble(key);
            } else if (Date.class.isAssignableFrom(field.getType())) {
                value = parseDate(configurationName, configurationProvider.getString(key), configuration);
                if (null == value) {
                    field = null;
                }
            } else {
                log.error("Field type not supported: " + field.getType());
                field = null;
            }
        } catch (IllegalArgumentException e) {
            if (!Date.class.isAssignableFrom(field.getType())) {
                ignoreTypeMismtachIfConfigured(configuration, configurationName, e);
                field = null;
            }
        } catch (ConversionException e) {
            if (!Date.class.isAssignableFrom(field.getType())) {
                ignoreTypeMismtachIfConfigured(configuration, configurationName, e);
                field = null;
            }
        }
    }

    if (field != null) {
        String defaultValue = String.valueOf(field.get(obj));
        String documentationValue;
        if (has) {
            field.set(obj, value);
            documentationValue = String.valueOf(value);
        } else {
            documentationValue = "";
        }
        configurationDocumentation.registerConfiguration(field, configurationName, has, defaultValue,
                documentationValue, configuration.documentation());
    }
}

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

/**
 * /*from   ww w.j av a  2  s  .c  o m*/
 * @param json
 * @param key
 * @param toField
 * @return
 * @throws JSONException
 */
public static Object getFromJsonByField2(JSONObject json, String key, Field toField) throws JSONException {
    final Object o = json.get(key);
    final Class<?> fieldType = toField.getType();
    if (o != JSONObject.NULL) {
        if (fieldType.equals(Integer.class) || fieldType.equals(Integer.TYPE)) {
            return json.getInt(key);
        } else if (fieldType.equals(String.class)) {
            return o;
        } else if (fieldType.equals(Long.class) || fieldType.equals(Long.TYPE)) {
            return json.getLong(key);
        } else if (fieldType.equals(Boolean.class) || fieldType.equals(Boolean.TYPE)) {
            return json.getBoolean(key);
        } else if (fieldType.equals(Float.class) || fieldType.equals(Float.TYPE)) {
            return (float) json.getDouble(key);
        } else if (fieldType.equals(Double.class) || fieldType.equals(Double.TYPE)) {
            return json.getDouble(key);
        } else {
            return o;
        }
    }

    return JSONObject.NULL;
}

From source file:org.ocelotds.dashboard.services.ServiceToolsTest.java

/**
 * Test of getInstanceOfClass method, of class ServiceTools.
 *
 * @throws com.fasterxml.jackson.core.JsonProcessingException
 *///  w  ww.  ja v a  2s  . co  m
@Test
public void testGetInstanceOfClass() throws JsonProcessingException {
    System.out.println("getTemplateOfClass");
    ObjectMapper om = new ObjectMapper();
    Result r = new Result();
    String expResult = om.writeValueAsString(r);
    Class cls = Boolean.class;
    Object result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(false);

    cls = Boolean.TYPE;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(false);

    cls = Integer.class;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(0);

    cls = Integer.TYPE;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(0);

    cls = Long.class;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(0L);

    cls = Long.TYPE;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(0l);

    cls = Float.class;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(0.1f);

    cls = Float.TYPE;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(0.1f);

    cls = Double.class;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(0.1d);

    cls = Double.TYPE;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(0.1d);

    cls = Float[].class;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(new Float[] { 0.1f, 0.1f });

    cls = Result.class;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualToComparingFieldByField(r);

    cls = Result[].class;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualToComparingFieldByField(new Result[] { r, r });

    cls = Locale.class;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isInstanceOf(Locale.class);

    cls = Serializable.class;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isNull();
}

From source file:org.crank.javax.faces.component.MenuRenderer.java

protected Object convertSelectManyValues(FacesContext context, UISelectMany uiSelectMany, Class<?> arrayClass,
        String[] newValues) throws ConverterException {

    Object result = null;/* w  w  w  .j  a  v a2s .c  om*/
    Converter converter = null;
    int len = (null != newValues ? newValues.length : 0);

    Class<?> elementType = arrayClass.getComponentType();

    // Optimization: If the elementType is String, we don't need
    // conversion.  Just return newValues.
    if (elementType.equals(String.class)) {
        return newValues;
    }

    try {
        result = Array.newInstance(elementType, len);
    } catch (Exception e) {
        throw new ConverterException(e);
    }

    // bail out now if we have no new values, returning our
    // oh-so-useful zero-length array.
    if (null == newValues) {
        return result;
    }

    // obtain a converter.

    // attached converter takes priority
    if (null == (converter = uiSelectMany.getConverter())) {
        // Otherwise, look for a by-type converter
        if (null == (converter = Util.getConverterForClass(elementType, context))) {
            // if that fails, and the attached values are of Object type,
            // we don't need conversion.
            if (elementType.equals(Object.class)) {
                return newValues;
            }
            StringBuffer valueStr = new StringBuffer();
            for (int i = 0; i < len; i++) {
                if (i == 0) {
                    valueStr.append(newValues[i]);
                } else {
                    valueStr.append(' ').append(newValues[i]);
                }
            }
            Object[] params = { valueStr.toString(), "null Converter" };

            throw new ConverterException(
                    MessageUtils.getExceptionMessage(MessageUtils.CONVERSION_ERROR_MESSAGE_ID, params));
        }
    }

    assert (null != result);
    if (elementType.isPrimitive()) {
        for (int i = 0; i < len; i++) {
            if (elementType.equals(Boolean.TYPE)) {
                Array.setBoolean(result, i,
                        ((Boolean) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Byte.TYPE)) {
                Array.setByte(result, i, ((Byte) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Double.TYPE)) {
                Array.setDouble(result, i,
                        ((Double) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Float.TYPE)) {
                Array.setFloat(result, i, ((Float) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Integer.TYPE)) {
                Array.setInt(result, i, ((Integer) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Character.TYPE)) {
                Array.setChar(result, i,
                        ((Character) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Short.TYPE)) {
                Array.setShort(result, i, ((Short) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Long.TYPE)) {
                Array.setLong(result, i, ((Long) converter.getAsObject(context, uiSelectMany, newValues[i])));
            }
        }
    } else {
        for (int i = 0; i < len; i++) {
            if (logger.isLoggable(Level.FINE)) {
                Object converted = converter.getAsObject(context, uiSelectMany, newValues[i]);
                logger.fine("String value: " + newValues[i] + " converts to : " + converted.toString());
            }
            Array.set(result, i, converter.getAsObject(context, uiSelectMany, newValues[i]));
        }
    }
    return result;

}

From source file:iing.uabc.edu.mx.persistencia.util.JSON.java

public static void stringifyArray(JsonGenerator generator, CollectionManager manager) {

    //Get size of the array to start stringifying elements
    //Note that the elements of this array has to be of the same class
    Collection collection = manager.getCollection();
    Class elementType = manager.getElementClass();

    System.out.println("Coleccion de tamanio " + collection.size());

    int i = 0;/*w  w  w.  ja  v a 2s .c  o m*/
    //Read every element and transform  it to a json array element string
    for (Iterator it = collection.iterator(); it.hasNext();) {
        Object element = it.next();

        System.out.println("Elemento: [" + i + "], Valor: " + element);

        if (element == null) {
            //Set to null the property
            generator.writeNull();
            continue;
        }

        //Is a String
        if (elementType == String.class) {
            generator.write(String.valueOf(element));
        } //Is a Date
        else if (elementType == Date.class) {
            String date = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(element);

            generator.write(date);

        } //Is a integer
        else if (elementType == Integer.class || elementType == Integer.TYPE) {
            generator.write((int) element);
        } //Is a double
        else if (elementType == Double.class || elementType == Double.TYPE) {
            generator.write((double) element);
        } //Is boolean
        else if (elementType == Boolean.class || elementType == Boolean.TYPE) {
            generator.write((boolean) element);

        } //Is a collection (Not implemented)
        else if (element instanceof Collection) {
            //                Class elementClass = manager.getCollectionElementType(keyName);
            //
            //                System.out.println("Nueva Colleccion [] de clase: "
            //                        + elementClass.getSimpleName());
            //
            //                generator.writeStartArray(keyName);
            //
            //                //Create new collection manager with the given class
            //                CollectionManager collectionManager
            //                        = new CollectionManager((Collection) value, elementClass);
            //
            //                generator.writeEnd();
        } else {
            //Is a object... probably
            BeanManager objectManager = new BeanManager(element);

            System.out.println("Nuevo Objecto {}: " + element.getClass().getSimpleName());
            generator.writeStartObject();

            stringifyObject(generator, objectManager);

            generator.writeEnd();
        }
    }
}

From source file:org.evosuite.testcarver.testcase.EvoTestCaseCodeGenerator.java

private final Class<?> getClassFromType(final org.objectweb.asm.Type type) {

    if (type.equals(org.objectweb.asm.Type.BOOLEAN_TYPE)) {
        return Boolean.TYPE;
    } else if (type.equals(org.objectweb.asm.Type.BYTE_TYPE)) {
        return Byte.TYPE;
    } else if (type.equals(org.objectweb.asm.Type.CHAR_TYPE)) {
        return Character.TYPE;
    } else if (type.equals(org.objectweb.asm.Type.DOUBLE_TYPE)) {
        return Double.TYPE;
    } else if (type.equals(org.objectweb.asm.Type.FLOAT_TYPE)) {
        return Float.TYPE;
    } else if (type.equals(org.objectweb.asm.Type.INT_TYPE)) {
        return Integer.TYPE;
    } else if (type.equals(org.objectweb.asm.Type.LONG_TYPE)) {
        return Long.TYPE;
    } else if (type.equals(org.objectweb.asm.Type.SHORT_TYPE)) {
        return Short.TYPE;
    } else if (type.getSort() == org.objectweb.asm.Type.ARRAY) {
        final org.objectweb.asm.Type elementType = type.getElementType();
        int[] dimensions = new int[type.getDimensions()];

        if (elementType.equals(org.objectweb.asm.Type.BOOLEAN_TYPE)) {
            return Array.newInstance(boolean.class, dimensions).getClass();
        } else if (elementType.equals(org.objectweb.asm.Type.BYTE_TYPE)) {
            return Array.newInstance(byte.class, dimensions).getClass();
        } else if (elementType.equals(org.objectweb.asm.Type.CHAR_TYPE)) {
            return Array.newInstance(char.class, dimensions).getClass();
        } else if (elementType.equals(org.objectweb.asm.Type.DOUBLE_TYPE)) {
            return Array.newInstance(double.class, dimensions).getClass();
        } else if (elementType.equals(org.objectweb.asm.Type.FLOAT_TYPE)) {
            return Array.newInstance(float.class, dimensions).getClass();
        } else if (elementType.equals(org.objectweb.asm.Type.INT_TYPE)) {
            return Array.newInstance(int.class, dimensions).getClass();
        } else if (elementType.equals(org.objectweb.asm.Type.LONG_TYPE)) {
            return Array.newInstance(long.class, dimensions).getClass();
        } else if (elementType.equals(org.objectweb.asm.Type.SHORT_TYPE)) {
            return Array.newInstance(short.class, dimensions).getClass();
        }//from www.  j av a2 s  . c o  m
    }

    //      try 
    //      {
    return getClassForName(type.getClassName());
    //         return Class.forName(type.getClassName(), true, StaticTestCluster.classLoader);
    //      } 
    //      catch (final ClassNotFoundException e) 
    //      {
    //         throw new RuntimeException(e);
    //      }
}

From source file:org.pentaho.reporting.engine.classic.core.util.beans.BeanUtility.java

public static boolean isSameType(final Class declared, final Class object) {
    if (declared.equals(object)) {
        return true;
    }/*from  w  w  w .  ja v a  2s .  c om*/

    if (Float.TYPE.equals(declared) && Float.class.equals(object)) {
        return true;
    }
    if (Double.TYPE.equals(declared) && Double.class.equals(object)) {
        return true;
    }
    if (Byte.TYPE.equals(declared) && Byte.class.equals(object)) {
        return true;
    }
    if (Character.TYPE.equals(declared) && Character.class.equals(object)) {
        return true;
    }
    if (Short.TYPE.equals(declared) && Short.class.equals(object)) {
        return true;
    }
    if (Integer.TYPE.equals(declared) && Integer.class.equals(object)) {
        return true;
    }
    if (Long.TYPE.equals(declared) && Long.class.equals(object)) {
        return true;
    }
    return false;
}

From source file:org.kuali.rice.krad.uif.util.ObjectPropertyUtils.java

/**
 * Convert to a primitive type if available.
 * /* w  w  w.  j av  a  2  s . c  o  m*/
 * @param type The type to convert.
 * @return A primitive type, if available, that corresponds to the type.
 */
public static Class<?> getPrimitiveType(Class<?> type) {
    if (Byte.class.equals(type)) {
        return Byte.TYPE;

    } else if (Short.class.equals(type)) {
        return Short.TYPE;

    } else if (Integer.class.equals(type)) {
        return Integer.TYPE;

    } else if (Long.class.equals(type)) {
        return Long.TYPE;

    } else if (Boolean.class.equals(type)) {
        return Boolean.TYPE;

    } else if (Float.class.equals(type)) {
        return Float.TYPE;

    } else if (Double.class.equals(type)) {
        return Double.TYPE;
    }

    return type;
}

From source file:org.jfree.chart.demo.SymbolicXYPlotDemo.java

/**
 * Transform an primitive array to an object array.
 * // w  ww .  j  av a  2  s . c o  m
 * @param arr
 *           the array.
 * @return an array.
 */
private static Object toArray(final Object arr) {

    if (arr == null) {
        return arr;
    }

    final Class cls = arr.getClass();
    if (!cls.isArray()) {
        return arr;
    }

    Class compType = cls.getComponentType();
    int dim = 1;
    while (!compType.isPrimitive()) {
        if (!compType.isArray()) {
            return arr;
        } else {
            dim++;
            compType = compType.getComponentType();
        }
    }

    final int[] length = new int[dim];
    length[0] = Array.getLength(arr);
    Object[] newarr = null;

    try {
        if (compType.equals(Integer.TYPE)) {
            newarr = (Object[]) Array.newInstance(Class.forName("java.lang.Integer"), length);
        } else if (compType.equals(Double.TYPE)) {
            newarr = (Object[]) Array.newInstance(Class.forName("java.lang.Double"), length);
        } else if (compType.equals(Long.TYPE)) {
            newarr = (Object[]) Array.newInstance(Class.forName("java.lang.Long"), length);
        } else if (compType.equals(Float.TYPE)) {
            newarr = (Object[]) Array.newInstance(Class.forName("java.lang.Float"), length);
        } else if (compType.equals(Short.TYPE)) {
            newarr = (Object[]) Array.newInstance(Class.forName("java.lang.Short"), length);
        } else if (compType.equals(Byte.TYPE)) {
            newarr = (Object[]) Array.newInstance(Class.forName("java.lang.Byte"), length);
        } else if (compType.equals(Character.TYPE)) {
            newarr = (Object[]) Array.newInstance(Class.forName("java.lang.Character"), length);
        } else if (compType.equals(Boolean.TYPE)) {
            newarr = (Object[]) Array.newInstance(Class.forName("java.lang.Boolean"), length);
        }
    } catch (ClassNotFoundException ex) {
        System.out.println(ex);
    }

    for (int i = 0; i < length[0]; i++) {
        if (dim != 1) {
            newarr[i] = toArray(Array.get(arr, i));
        } else {
            newarr[i] = Array.get(arr, i);
        }
    }
    return newarr;
}