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:Main.java

/**
 * renderArray returns an array similar to a List. If the array type is an
 * object they are rendered with "render(object)" for each. If the array
 * type is a primitive each element is added directly to the string buffer
 * collecting the result./*w ww  . jav a2s.c  om*/
 * 
 * @param o
 * @param objectClass
 * @return
 */
private static StringBuffer renderArray(Object o, Class<?> objectClass) {
    Class<?> componentType = objectClass.getComponentType();
    StringBuffer sb = new StringBuffer(ARRAY_PREFIX);

    if (componentType.isPrimitive() == false) {
        Object[] oa = (Object[]) o;
        for (int i = 0; i < oa.length; i++) {
            if (i > 0) {
                sb.append(ELEMENT_SEPARATOR);
            }
            sb.append(render(oa[i]));
        }
    } else {
        if (Boolean.TYPE.equals(componentType)) {
            boolean[] ba = (boolean[]) o;
            for (int i = 0; i < ba.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ba[i]);
            }
        } else if (Integer.TYPE.equals(componentType)) {
            int[] ia = (int[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }

        } else if (Long.TYPE.equals(componentType)) {
            long[] ia = (long[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }
        } else if (Double.TYPE.equals(componentType)) {
            double[] ia = (double[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }
        } else if (Float.TYPE.equals(componentType)) {
            float[] ia = (float[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }
        } else if (Character.TYPE.equals(componentType)) {
            char[] ia = (char[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }
        } else if (Short.TYPE.equals(componentType)) {
            short[] ia = (short[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }
        } else if (Byte.TYPE.equals(componentType)) {
            byte[] ia = (byte[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }
        }
    }
    sb.append(ARRAY_SUFFIX);
    return sb;
}

From source file:org.apache.struts2.s1.DynaBeanPropertyAccessorTest.java

/**
 * Create and return a <code>DynaClass</code> instance for our test
 * <code>DynaBean</code>./*from  w  w  w  .  j a  v a  2  s. c o  m*/
 */
protected DynaClass createDynaClass() {

    int intArray[] = new int[0];
    String stringArray[] = new String[0];

    DynaClass dynaClass = new BasicDynaClass("TestDynaClass", null, new DynaProperty[] {
            new DynaProperty("booleanProperty", Boolean.TYPE), new DynaProperty("booleanSecond", Boolean.TYPE),
            new DynaProperty("doubleProperty", Double.TYPE), new DynaProperty("floatProperty", Float.TYPE),
            new DynaProperty("intArray", intArray.getClass()),
            new DynaProperty("intIndexed", intArray.getClass()), new DynaProperty("intProperty", Integer.TYPE),
            new DynaProperty("listIndexed", List.class), new DynaProperty("longProperty", Long.TYPE),
            new DynaProperty("mappedProperty", Map.class), new DynaProperty("mappedIntProperty", Map.class),
            new DynaProperty("nullProperty", String.class), new DynaProperty("shortProperty", Short.TYPE),
            new DynaProperty("stringArray", stringArray.getClass()),
            new DynaProperty("stringIndexed", stringArray.getClass()),
            new DynaProperty("stringProperty", String.class), });
    return (dynaClass);

}

From source file:com.link_intersystems.lang.Conversions.java

/**
 * float to double/*from   w  w w .jav a 2 s  . c o m*/
 */
private static boolean isPrimitiveFloatWidening(Class<?> to) {
    boolean isWidening = isIdentity(to, Double.TYPE);
    return isWidening;
}

From source file:com.l2jfree.gameserver.model.skills.funcs.FuncTemplate.java

public FuncTemplate(Condition pApplayCond, String pFunc, Stats pStat, int pOrder, double pLambda) {
    Class<?> clazz;/*from  w  w w  .jav  a2  s .co  m*/
    try {
        final StringBuilder sb = new StringBuilder();
        sb.append(IFuncMarker.class.getPackage().getName());
        sb.append(".Func");
        sb.append(pFunc);
        clazz = Class.forName(sb.toString());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    // Ugly fixes for DP errors
    switch (pStat) {
    case CRITICAL_DAMAGE_ADD: {
        if (clazz != FuncAdd.class && clazz != FuncSub.class) {
            throwException(pFunc, pStat, pOrder, pLambda);
            pStat = Stats.CRITICAL_DAMAGE;
        }
        break;
    }
    case CRITICAL_DAMAGE: {
        if (clazz == FuncAdd.class || clazz == FuncSub.class) {
            throwException(pFunc, pStat, pOrder, pLambda);
            pStat = Stats.CRITICAL_DAMAGE_ADD;
        }
        break;
    }
    case CRITICAL_RATE: {
        if (clazz == FuncMul.class) {
            //throwException(pFunc, pStat, pOrder, pLambda);
            clazz = FuncBaseMul.class;
            pLambda = (pLambda - 1.0);
        } else if (clazz == FuncDiv.class) {
            //throwException(pFunc, pStat, pOrder, pLambda);
            clazz = FuncBaseMul.class;
            pLambda = ((1.0 / pLambda) - 1.0);
        }
        break;
    }
    case MCRITICAL_RATE: {
        if (clazz == FuncMul.class) {
            //throwException(pFunc, pStat, pOrder, pLambda);
            clazz = FuncBaseMul.class;
            pLambda = (pLambda - 1.0);
        } else if (clazz == FuncDiv.class) {
            //throwException(pFunc, pStat, pOrder, pLambda);
            clazz = FuncBaseMul.class;
            pLambda = ((1.0 / pLambda) - 1.0);
        }
        break;
    }
    }

    if (pStat.isMultiplicativeResist()) {
        if (clazz != FuncMul.class && clazz != FuncDiv.class)
            throwException(pFunc, pStat, pOrder, pLambda);

        if (pLambda > 2 || pLambda < 0)
            throwException(pFunc, pStat, pOrder, pLambda);
    }

    if (pStat.isAdditiveResist()) {
        if (clazz != FuncAdd.class && clazz != FuncSub.class)
            throwException(pFunc, pStat, pOrder, pLambda);

        if ((int) pLambda != pLambda) // it wasn't an integer value
            throwException(pFunc, pStat, pOrder, pLambda);
    }

    if (clazz == FuncEnchant.class) {
        switch (pStat) {
        case MAGIC_DEFENCE:
        case POWER_DEFENCE:
        case SHIELD_DEFENCE:
        case MAGIC_ATTACK:
        case POWER_ATTACK:
            break;
        default:
            throwException(pFunc, pStat, pOrder, pLambda);
        }
    } else if (clazz == FuncBaseMul.class) {
        switch (pStat) {
        case CRITICAL_RATE:
        case MCRITICAL_RATE:
            break;
        default:
            throwException(pFunc, pStat, pOrder, pLambda);
        }
    }

    stat = pStat;
    order = pOrder;
    lambda = pLambda;
    applayCond = pApplayCond;

    try {
        _constructor = clazz.getConstructor(Stats.class, Integer.TYPE, FuncOwner.class, Double.TYPE,
                Condition.class);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.pig.builtin.Invoker.java

private static Class<?> unPrimitivize(Class<?> klass) {
    if (klass.equals(Integer.TYPE)) {
        return Integer.class;
    }/* w  ww  . j  a va2  s .c o m*/
    if (klass.equals(Long.TYPE)) {
        return Long.class;
    } else if (klass.equals(Float.TYPE)) {
        return Float.class;
    } else if (klass.equals(Double.TYPE)) {
        return Double.class;
    } else {
        return klass;
    }
}

From source file:io.coala.guice.config.ConfigMembersInjector.java

@Override
public void injectMembers(final T instance) {
    final InjectConfig injectConfigAnnotation = field.getAnnotation(InjectConfig.class);
    final String configurationParameterName = injectConfigAnnotation.name();
    try {/*w w  w. j  av  a  2 s.  c om*/
        final Class<?> type = this.field.getType();
        if (type == Integer.TYPE) {
            if (this.configuration.containsKey(configurationParameterName)) {
                this.field.setInt(instance, this.configuration.getInt(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setInt(instance, injectConfigAnnotation.defaultIntValue());
            }
        } else if (type == Boolean.TYPE) {
            if (this.configuration.containsKey(configurationParameterName)) {
                this.field.setBoolean(instance, this.configuration.getBoolean(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setBoolean(instance, injectConfigAnnotation.defaultBooleanValue());
            }

        } else if (type == Short.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                this.field.setShort(instance, this.configuration.getShort(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setShort(instance, injectConfigAnnotation.defaultShortValue());
            }
        } else if (type == Byte.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                this.field.setByte(instance, this.configuration.getByte(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setByte(instance, injectConfigAnnotation.defaultByteValue());
            }
        } else if (type == Long.TYPE) {
            if (this.configuration.containsKey(configurationParameterName)) {
                this.field.setLong(instance, this.configuration.getLong(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setLong(instance, injectConfigAnnotation.defaultLongValue());
            }
        } else if (type == Float.TYPE) {
            if (this.configuration.containsKey(configurationParameterName)) {
                this.field.setFloat(instance, this.configuration.getFloat(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setFloat(instance, injectConfigAnnotation.defaultFloatValue());
            }
        } else if (type == Double.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                this.field.setDouble(instance, this.configuration.getDouble(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setDouble(instance, injectConfigAnnotation.defaultDoubleValue());
            }
        } else if (type == Character.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                this.field.setChar(instance,
                        this.configuration.getString(configurationParameterName).charAt(0));
            }
        } else {
            final Object property = getProperty(configurationParameterName, injectConfigAnnotation);
            this.field.set(instance, property);
        }
    } catch (final Throwable ex) {
        LOG.error("Problem injecting configuration", ex);
    }
}

From source file:com.ms.commons.summer.web.util.json.JsonNumberMorpher.java

public Object morph(Object value) {
    if (value != null && type.isAssignableFrom(value.getClass())) {
        // no conversion needed
        return value;
    }//from www  . j  ava  2 s .co m

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

    try {
        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);
            }
        }
    } catch (ConvertErrorException e) {
        // JsonPropertyConvertContext.setConvertError((ConvertErrorException) e);
        return null;
    }
}

From source file:org.apache.drill.yarn.core.DoYUtil.java

public static void callSetDiskIfExists(Object target, double arg) {
    dynamicCall(target, "setDisks", new Object[] { arg }, new Class<?>[] { Double.TYPE });
}

From source file:net.sf.jrf.domain.PersistentObjectDynaProperty.java

/** Constructs instance and property name and class.
* @param name property name.// w w w  . j av  a  2 s .co m
* @param cls value object <code>Class</code>.
* @param readMethodName name of the read <code>Method</code>
* @param writeMethodName name of the write <code>Method</code>
*/
public PersistentObjectDynaProperty(String name, Class cls, String readMethodName, String writeMethodName) {
    super(name, cls);
    this.readMethodName = readMethodName;
    this.writeMethodName = writeMethodName;
    if (cls.isPrimitive()) {
        if (cls.equals(Boolean.TYPE))
            primitiveWrapperClass = Boolean.class;
        else if (cls.equals(Byte.TYPE))
            primitiveWrapperClass = Byte.class;
        else if (cls.equals(Character.TYPE))
            primitiveWrapperClass = Character.class;
        else if (cls.equals(Double.TYPE))
            primitiveWrapperClass = Double.class;
        else if (cls.equals(Float.TYPE))
            primitiveWrapperClass = Float.class;
        else if (cls.equals(Integer.TYPE))
            primitiveWrapperClass = Integer.class;
        else if (cls.equals(Long.TYPE))
            primitiveWrapperClass = Long.class;
        else if (cls.equals(Short.TYPE))
            primitiveWrapperClass = Short.class;

    } else if (java.util.List.class.isAssignableFrom(cls) || cls.isArray()) {
        indexed = true;
    } else if (java.util.Map.class.isAssignableFrom(cls)) {
        mapped = true;
    }
}

From source file:org.trianacode.taskgraph.tool.ClassLoaders.java

public static Class forName(String className) throws ClassNotFoundException {
    className = getTextClassName(className);
    boolean isArray = false;
    int dims = 0;
    if (className.endsWith("[]")) {
        isArray = true;//from   w w w  .j a va  2s . c  o  m
        dims = className.substring(className.indexOf("[]"), className.length()).length() / 2;
        className = className.substring(0, className.indexOf("[]"));

    }
    Class cls;
    if (className.equals("boolean")) {
        cls = Boolean.TYPE;
    } else if (className.equals("char")) {
        cls = Character.TYPE;
    } else if (className.equals("byte")) {
        cls = Byte.TYPE;
    } else if (className.equals("short")) {
        cls = Short.TYPE;
    } else if (className.equals("int")) {
        cls = Integer.TYPE;
    } else if (className.equals("long")) {
        cls = Long.TYPE;
    } else if (className.equals("float")) {
        cls = Float.TYPE;
    } else if (className.equals("double")) {
        cls = Double.TYPE;
    } else if (className.equals("void")) {
        cls = void.class;
    } else {
        cls = loadClass(className);
    }
    if (isArray) {
        Object arr = Array.newInstance(cls, new int[dims]);
        cls = arr.getClass();
    }
    return cls;
}