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.quartz.jobs.ee.jmx.JMXInvokerJob.java

public void execute(JobExecutionContext context) throws JobExecutionException {
    try {/*from  w w w  .j  av a2s . c o  m*/
        Object[] params = null;
        String[] types = null;
        String objName = null;
        String objMethod = null;

        JobDataMap jobDataMap = context.getMergedJobDataMap();

        String[] keys = jobDataMap.getKeys();
        for (int i = 0; i < keys.length; i++) {
            String value = jobDataMap.getString(keys[i]);
            if ("JMX_OBJECTNAME".equalsIgnoreCase(keys[i])) {
                objName = value;
            } else if ("JMX_METHOD".equalsIgnoreCase(keys[i])) {
                objMethod = value;
            } else if ("JMX_PARAMDEFS".equalsIgnoreCase(keys[i])) {
                String[] paramdefs = split(value, ",");
                params = new Object[paramdefs.length];
                types = new String[paramdefs.length];
                for (int k = 0; k < paramdefs.length; k++) {
                    String parts[] = split(paramdefs[k], ":");
                    if (parts.length < 2) {
                        throw new Exception(
                                "Invalid parameter definition: required parts missing " + paramdefs[k]);
                    }
                    switch (parts[0].charAt(0)) {
                    case 'i':
                        params[k] = new Integer(jobDataMap.getString(parts[1]));
                        types[k] = Integer.TYPE.getName();
                        break;
                    case 'I':
                        params[k] = new Integer(jobDataMap.getString(parts[1]));
                        types[k] = Integer.class.getName();
                        break;
                    case 'l':
                        params[k] = new Long(jobDataMap.getString(parts[1]));
                        types[k] = Long.TYPE.getName();
                        break;
                    case 'L':
                        params[k] = new Long(jobDataMap.getString(parts[1]));
                        types[k] = Long.class.getName();
                        break;
                    case 'f':
                        params[k] = new Float(jobDataMap.getString(parts[1]));
                        types[k] = Float.TYPE.getName();
                        break;
                    case 'F':
                        params[k] = new Float(jobDataMap.getString(parts[1]));
                        types[k] = Float.class.getName();
                        break;
                    case 'd':
                        params[k] = new Double(jobDataMap.getString(parts[1]));
                        types[k] = Double.TYPE.getName();
                        break;
                    case 'D':
                        params[k] = new Double(jobDataMap.getString(parts[1]));
                        types[k] = Double.class.getName();
                        break;
                    case 's':
                        params[k] = jobDataMap.getString(parts[1]);
                        types[k] = String.class.getName();
                        break;
                    case 'b':
                        params[k] = new Boolean(jobDataMap.getString(parts[1]));
                        types[k] = Boolean.TYPE.getName();
                        break;
                    case 'B':
                        params[k] = new Boolean(jobDataMap.getString(parts[1]));
                        types[k] = Boolean.class.getName();
                        break;
                    }
                }
            }
        }

        if (objName == null || objMethod == null) {
            throw new Exception("Required parameters missing");
        }

        context.setResult(invoke(objName, objMethod, params, types));
    } catch (Exception e) {
        String m = "Caught a " + e.getClass().getName() + " exception : " + e.getMessage();
        getLog().error(m, e);
        throw new JobExecutionException(m, e, false);
    }
}

From source file:org.atemsource.atem.impl.common.attribute.primitive.PrimitiveTypeFactory.java

@PostConstruct
public void initialize() {
    classes = new ArrayList<Class>();
    classes.add(String.class);
    classes.add(Boolean.class);
    classes.add(Boolean.TYPE);// w  w w .j a  v  a 2  s.c o  m
    classes.add(Long.class);
    classes.add(Long.TYPE);
    classes.add(Integer.class);
    classes.add(Integer.TYPE);
    classes.add(Float.class);
    classes.add(Float.TYPE);
    classes.add(Double.TYPE);
    classes.add(Double.class);
    classes.add(Character.TYPE);
    classes.add(Character.TYPE);
    classes.add(Character.class);
    classes.add(Byte.TYPE);
    classes.add(Byte.class);
    classes.add(Enum.class);
    classes.add(BigInteger.class);
    classes.add(BigDecimal.class);
    Collection<PrimitiveTypeRegistrar> registrars = beanLocator.getInstances(PrimitiveTypeRegistrar.class);
    for (PrimitiveTypeRegistrar registrar : registrars) {
        PrimitiveType<?>[] types = registrar.getTypes();
        for (PrimitiveType<?> primitiveType : types) {
            classToType.put(primitiveType.getJavaType(), primitiveType);
            classes.add(primitiveType.getJavaType());
        }
    }
}

From source file:com.adobe.acs.commons.data.Variant.java

@SuppressWarnings("squid:S3776")
public final <T> void setValue(T val) {
    if (val == null) {
        return;//from  www  .  j  a  v a  2  s  .  c o m
    }
    Class type = val.getClass();
    if (type == Variant.class) {
        Variant v = (Variant) val;
        longVal = v.longVal;
        doubleVal = v.doubleVal;
        stringVal = v.stringVal;
        booleanVal = v.booleanVal;
        dateVal = v.dateVal;
    } else if (type == Byte.TYPE || type == Byte.class) {
        setLongVal(((Byte) val).longValue());
    } else if (type == Integer.TYPE || type == Integer.class) {
        setLongVal(((Integer) val).longValue());
    } else if (type == Long.TYPE || type == Long.class) {
        setLongVal((Long) val);
    } else if (type == Short.TYPE || type == Short.class) {
        setLongVal(((Short) val).longValue());
    } else if (type == Float.TYPE || type == Float.class) {
        setDoubleVal((Double) val);
    } else if (type == Double.TYPE || type == Double.class) {
        setDoubleVal((Double) val);
    } else if (type == Boolean.TYPE || type == Boolean.class) {
        setBooleanVal((Boolean) val);
    } else if (type == String.class) {
        setStringVal((String) val);
    } else if (type == Date.class) {
        setDateVal((Date) val);
    } else if (type == Instant.class) {
        setDateVal(new Date(((Instant) val).toEpochMilli()));
    } else if (type == Calendar.class) {
        setDateVal(((Calendar) val).getTime());
    } else {
        setStringVal(String.valueOf(val));
    }
}

From source file:org.wrml.runtime.schema.PropertyProtoSlot.java

PropertyProtoSlot(final Prototype prototype, final String slotName, final Property property) {

    super(prototype, slotName);

    if (property == null) {
        throw new NullPointerException(
                "Prototype (" + prototype + ") Slot (" + slotName + ") property cannot be null.");
    }/*from   ww  w . j  av a 2 s .  c om*/

    _Property = property;

    final Type heapValueType = getHeapValueType();

    final SyntaxLoader syntaxLoader = getContext().getSyntaxLoader();

    final DefaultValue defaultValue = getAnnotation(DefaultValue.class);
    if (defaultValue != null) {
        final String defaultValueString = defaultValue.value();

        try {
            _DefaultValue = syntaxLoader.parseSyntacticText(defaultValueString, heapValueType);
        } catch (final Exception e) {

            throw new PrototypeException(prototype + " slot named \"" + slotName
                    + "\" default value annotation's value could not be converted from text value \""
                    + defaultValueString + "\" to a Java " + heapValueType + ". Detail message: "
                    + e.getMessage(), e, prototype, slotName);
        }
    }

    if (Boolean.TYPE.equals(heapValueType)) {
        if (_DefaultValue == null) {
            _DefaultValue = Boolean.FALSE;
        }
    } else if (TypeUtils.isAssignable(heapValueType, Enum.class)) {

        if (_DefaultValue == null) {
            // Enum's default to their first constant
            // Single selects default to the first choice
            @SuppressWarnings("unchecked")
            final Class<Enum<?>> enumValueType = (Class<Enum<?>>) heapValueType;
            if (enumValueType != null) {
                final Enum<?>[] enumChoices = enumValueType.getEnumConstants();
                if (enumChoices != null && enumChoices.length > 0) {
                    _DefaultValue = enumChoices[0];
                }
            }
        }

    } else if (TypeUtils.isAssignable(heapValueType, Number.class) || Integer.TYPE.equals(heapValueType)
            || Long.TYPE.equals(heapValueType) || Double.TYPE.equals(heapValueType)) {

        if (_DefaultValue == null && Integer.TYPE.equals(heapValueType) || Long.TYPE.equals(heapValueType)
                || Double.TYPE.equals(heapValueType)) {
            _DefaultValue = getValueType().getDefaultValue();
        }

        // isolate()
        {
            final MinimumValue minimumValue = getAnnotation(MinimumValue.class);
            if (minimumValue != null) {
                final String minimumValueString = minimumValue.value();

                try {
                    _MinimumValue = syntaxLoader.parseSyntacticText(minimumValueString, heapValueType);
                } catch (final Exception e) {

                    throw new PrototypeException(prototype + " slot named \"" + slotName
                            + "\" minimum value annotation's value could not be converted from text value \""
                            + minimumValueString + "\" to a Java " + heapValueType + ". Detail message: "
                            + e.getMessage(), e, prototype, slotName);
                }

                _IsExclusiveMinimum = minimumValue.exclusive();

            }
        }

        // isolate()
        {
            final MaximumValue maximumValue = getAnnotation(MaximumValue.class);
            if (maximumValue != null) {
                final String maximumValueString = maximumValue.value();

                try {
                    _MaximumValue = syntaxLoader.parseSyntacticText(maximumValueString, heapValueType);
                } catch (final Exception e) {

                    throw new PrototypeException(prototype + " slot named \"" + slotName
                            + "\" maximum value annotation's value could not be converted from text value \""
                            + maximumValueString + "\" to a Java " + heapValueType + ". Detail message: "
                            + e.getMessage(), e, prototype, slotName);
                }

                _IsExclusiveMaximum = maximumValue.exclusive();
            }
        }

        // isolate()
        {
            final DivisibleByValue divisibleByValue = getAnnotation(DivisibleByValue.class);
            if (divisibleByValue != null &&
            // The "divisible by" constraint does not apply to doubles
                    !Double.TYPE.equals(heapValueType)
                    && !TypeUtils.isAssignable(heapValueType, Double.class)) {
                final String divisibleByValueString = divisibleByValue.value();

                try {
                    _DivisibleByValue = syntaxLoader.parseSyntacticText(divisibleByValueString, heapValueType);
                } catch (final Exception e) {

                    throw new PrototypeException(prototype + " slot named \"" + slotName
                            + "\" divisibleBy value annotation's value could not be converted from text value \""
                            + divisibleByValueString + "\" to a Java " + heapValueType + ". Detail message: "
                            + e.getMessage(), e, prototype, slotName);
                }

                if (_DivisibleByValue.equals(0)) {
                    throw new PrototypeException(prototype + " slot named \"" + slotName
                            + "\" divisibleBy value annotation's value could not be converted from text value \""
                            + divisibleByValueString + "\" to a Java " + heapValueType + ". Detail message: "
                            + "zero value", null, prototype, slotName);

                }

            }
        }

        // isolate()
        {
            final DisallowedValues disallowedValues = getAnnotation(DisallowedValues.class);
            if (disallowedValues != null) {
                final String[] disallowedValuesArray = disallowedValues.value();
                if (disallowedValuesArray != null) {
                    _DisallowedValues = new LinkedHashSet<>(disallowedValuesArray.length);
                    for (final String disallowedValueString : disallowedValuesArray) {

                        final Object disallowedValue = syntaxLoader.parseSyntacticText(disallowedValueString,
                                heapValueType);

                        _DisallowedValues.add(disallowedValue);
                    }
                }
            }
        }

    } else if (String.class.equals(heapValueType)) {

        final MinimumLength minimumLength = getAnnotation(MinimumLength.class);
        if (minimumLength != null) {
            _MinimumLength = minimumLength.value();
        }

        final MaximumLength maximumLength = getAnnotation(MaximumLength.class);
        if (maximumLength != null) {
            _MaximumLength = maximumLength.value();
        }

        final Multiline multiline = getAnnotation(Multiline.class);
        if (multiline != null) {
            _IsMultiline = true;
        }

        final DisallowedValues disallowedValues = getAnnotation(DisallowedValues.class);
        if (disallowedValues != null) {
            final String[] disallowedValuesArray = disallowedValues.value();
            if (disallowedValuesArray != null) {
                _DisallowedValues = new LinkedHashSet<>(disallowedValuesArray.length);
                _DisallowedValues.addAll(Arrays.asList(disallowedValuesArray));
            }
        }

    } else if (TypeUtils.isAssignable(heapValueType, Collection.class)) {

        final MinimumSize minimumSize = getAnnotation(MinimumSize.class);
        if (minimumSize != null) {
            _MinimumSize = minimumSize.value();
        }

        final MaximumSize maximumSize = getAnnotation(MaximumSize.class);
        if (maximumSize != null) {
            _MaximumSize = maximumSize.value();
        }

    }

    final Searchable searchable = getAnnotation(Searchable.class);
    if (searchable != null) {
        _Searchable = true;
    }

}

From source file:in.hatimi.nosh.support.CmdLineManager.java

private boolean injectString(Object target, Field field, String value) {
    if (field.getType().equals(Boolean.class) || field.getType().equals(Boolean.TYPE)) {
        Boolean vobj = new Boolean(value);
        return injectImpl(target, field, vobj);
    }/*from   www  . ja v a  2  s .c  o m*/
    if (field.getType().equals(Double.class) || field.getType().equals(Double.TYPE)) {
        Double vobj = Double.valueOf(value);
        return injectImpl(target, field, vobj);
    }
    if (field.getType().equals(Float.class) || field.getType().equals(Float.TYPE)) {
        Float vobj = Float.valueOf(value);
        return injectImpl(target, field, vobj);
    }
    if (field.getType().equals(Long.class) || field.getType().equals(Long.TYPE)) {
        Long vobj = Long.valueOf(value);
        return injectImpl(target, field, vobj);
    }
    if (field.getType().equals(Integer.class) || field.getType().equals(Integer.TYPE)) {
        Integer vobj = Integer.valueOf(value);
        return injectImpl(target, field, vobj);
    }
    if (field.getType().equals(String.class)) {
        return injectImpl(target, field, value);
    }
    if (field.getType().equals(byte[].class)) {
        return injectImpl(target, field, value.getBytes());
    }
    if (field.getType().equals(char[].class)) {
        return injectImpl(target, field, value.toCharArray());
    }
    return false;
}

From source file:org.briljantframework.data.resolver.Resolve.java

private static Resolver<Double> initializeDoubleResolver() {
    Resolver<Double> doubleResolver = new Resolver<>(Double.class);
    doubleResolver.put(Number.class, Number::doubleValue);
    doubleResolver.put(Double.class, Number::doubleValue);
    doubleResolver.put(Double.TYPE, Number::doubleValue);
    doubleResolver.put(Float.class, Number::doubleValue);
    doubleResolver.put(Float.TYPE, Number::doubleValue);
    doubleResolver.put(Long.class, Number::doubleValue);
    doubleResolver.put(Long.TYPE, Number::doubleValue);
    doubleResolver.put(Integer.class, Number::doubleValue);
    doubleResolver.put(Integer.TYPE, Number::doubleValue);
    doubleResolver.put(Short.class, Number::doubleValue);
    doubleResolver.put(Short.TYPE, Number::doubleValue);
    doubleResolver.put(Byte.class, Number::doubleValue);
    doubleResolver.put(Byte.TYPE, Number::doubleValue);

    doubleResolver.put(String.class, s -> {
        Number n = toNumber(s);/*from  w w  w .java2  s.  c o  m*/
        return n != null ? n.doubleValue() : Na.BOXED_DOUBLE;
    });
    return doubleResolver;
}

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

private Supplier<?> getConfigurationSupplier(final Field field, final ConfigurationKey key, final Class<?> type,
        Supplier<?> current) {
    if (String.class.isAssignableFrom(type)) {
        return configurationProvider.getStringSupplier(key, (String) current.get());
    } else if (Boolean.class.isAssignableFrom(type) || Boolean.TYPE.isAssignableFrom(type)) {
        return configurationProvider.getBooleanSupplier(key, (Boolean) current.get());
    } else if (Integer.class.isAssignableFrom(type) || Integer.TYPE.isAssignableFrom(type)) {
        return configurationProvider.getIntegerSupplier(key, (Integer) current.get());
    } else if (Long.class.isAssignableFrom(type) || Long.TYPE.isAssignableFrom(type)) {
        return configurationProvider.getLongSupplier(key, (Long) current.get());
    } else if (Double.class.isAssignableFrom(type) || Double.TYPE.isAssignableFrom(type)) {
        return configurationProvider.getDoubleSupplier(key, (Double) current.get());
    } else if (Date.class.isAssignableFrom(type)) {
        return configurationProvider.getDateSupplier(key, (Date) current.get());
    } else {//from  w w  w .  j  a  v  a2 s .  c  om
        log.error("Field type not supported: " + type + " (" + field.getName() + ")");
        return null;
    }
}

From source file:com.nonninz.robomodel.RoboModel.java

private void loadField(Field field, Cursor query) throws DatabaseNotUpToDateException {
    final Class<?> type = field.getType();
    final boolean wasAccessible = field.isAccessible();
    final int columnIndex = query.getColumnIndex(field.getName());
    field.setAccessible(true);/*from  www.j a v  a  2s  .c om*/

    /*
     * TODO: There is the potential of a problem here:
     * What happens if the developer changes the type of a field between releases?
     *
     * If he saves first, then the column type will be changed (In the future).
     * If he loads first, we don't know if an Exception will be thrown if the
     * types are incompatible, because it's undocumented in the Cursor documentation.
     */

    try {
        if (type == String.class) {
            field.set(this, query.getString(columnIndex));
        } else if (type == Boolean.TYPE) {
            final boolean value = query.getInt(columnIndex) == 1 ? true : false;
            field.setBoolean(this, value);
        } else if (type == Byte.TYPE) {
            field.setByte(this, (byte) query.getShort(columnIndex));
        } else if (type == Double.TYPE) {
            field.setDouble(this, query.getDouble(columnIndex));
        } else if (type == Float.TYPE) {
            field.setFloat(this, query.getFloat(columnIndex));
        } else if (type == Integer.TYPE) {
            field.setInt(this, query.getInt(columnIndex));
        } else if (type == Long.TYPE) {
            field.setLong(this, query.getLong(columnIndex));
        } else if (type == Short.TYPE) {
            field.setShort(this, query.getShort(columnIndex));
        } else if (type.isEnum()) {
            final String string = query.getString(columnIndex);
            if (string != null && string.length() > 0) {
                final Object[] constants = type.getEnumConstants();
                final Method method = type.getMethod("valueOf", Class.class, String.class);
                final Object value = method.invoke(constants[0], type, string);
                field.set(this, value);
            }
        } else {
            // Try to de-json it (db column must be of type text)
            try {
                final Object value = mMapper.readValue(query.getString(columnIndex), field.getType());
                field.set(this, value);
            } catch (final Exception e) {
                final String msg = String.format("Type %s is not supported for field %s", type,
                        field.getName());
                Ln.w(e, msg);
                throw new IllegalArgumentException(msg);
            }
        }
    } catch (final IllegalAccessException e) {
        final String msg = String.format("Field %s is not accessible", type, field.getName());
        throw new IllegalArgumentException(msg);
    } catch (final NoSuchMethodException e) {
        // Should not happen
        throw new RuntimeException(e);
    } catch (final InvocationTargetException e) {
        // Should not happen
        throw new RuntimeException(e);
    } catch (IllegalStateException e) {
        // This is when there is no column in db, but there is in the model
        throw new DatabaseNotUpToDateException(e);
    } finally {
        field.setAccessible(wasAccessible);
    }
}

From source file:org.opensaas.jaudit.test.BeanTest.java

/**
 * Returns a new Map of default test class to test values types useful in
 * testing getters/setters.//from  w  ww .j av a  2s  .  c om
 * 
 * @return Map of supported types and associated values.
 */
protected static Map<Class<?>, Object[]> newClassToValues() {
    final Map<Class<?>, Object[]> ctov = new HashMap<Class<?>, Object[]>();

    ctov.put(Boolean.class, new Object[] { Boolean.TRUE, Boolean.FALSE, null });
    ctov.put(Boolean.TYPE, new Object[] { Boolean.TRUE, Boolean.FALSE });
    ctov.put(Date.class, new Object[] { new Date(), new Date(0L), new Date(1000L), null });
    ctov.put(Double.class, new Object[] { 0d, Double.MAX_VALUE, Double.MIN_VALUE, null });
    ctov.put(Double.TYPE, new Object[] { 0d, Double.MAX_VALUE, Double.MIN_VALUE });
    ctov.put(Integer.class, new Object[] { 0, Integer.MAX_VALUE, Integer.MIN_VALUE, null });
    ctov.put(Integer.TYPE, new Object[] { 0, Integer.MAX_VALUE, Integer.MIN_VALUE });
    ctov.put(Long.class, new Object[] { 0L, Long.MAX_VALUE, Long.MIN_VALUE, null });
    ctov.put(Long.TYPE, new Object[] { 0L, Long.MAX_VALUE, Long.MIN_VALUE });
    ctov.put(String.class, new Object[] { "", " ", "Texas Fight!", UUID.randomUUID().toString(), null });

    return Collections.unmodifiableMap(ctov);
}

From source file:org.kordamp.ezmorph.object.NumberMorpher.java

public Object morph(Object value) {
    if (value != null && type.isAssignableFrom(value.getClass())) {
        // no conversion needed
        return value;
    }//from w  ww  . j a va2 s  . c  om

    String str = String.valueOf(value).trim();

    if (!type.isPrimitive() && (value == null || str.length() == 0 || "null".equalsIgnoreCase(str))) {
        // if empty string and class != primitive treat it like null
        return null;
    }

    if (isDecimalNumber(type)) {
        if (Float.class.isAssignableFrom(type) || Float.TYPE == type) {
            return morphToFloat(str);
        } else if (Double.class.isAssignableFrom(type) || Double.TYPE == type) {
            return morphToDouble(str);
        } else {
            return morphToBigDecimal(str);
        }
    } else {
        if (Byte.class.isAssignableFrom(type) || Byte.TYPE == type) {
            return morphToByte(str);
        } else if (Short.class.isAssignableFrom(type) || Short.TYPE == type) {
            return morphToShort(str);
        } else if (Integer.class.isAssignableFrom(type) || Integer.TYPE == type) {
            return morphToInteger(str);
        } else if (Long.class.isAssignableFrom(type) || Long.TYPE == type) {
            return morphToLong(str);
        } else {
            return morphToBigInteger(str);
        }
    }
}