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.converter.def.AbstractDefaultConverterTool.java

/**
 * Populates the simple converters.// www . j  ava 2  s.  c o  m
 */
private void populateSimpleConverters() {
    // Primitives.
    this.converters.put(Integer.TYPE, new IntegerConverter());
    this.converters.put(Double.TYPE, new DoubleConverter());
    this.converters.put(Float.TYPE, new FloatConverter());
    this.converters.put(Long.TYPE, new LongConverter());
    this.converters.put(Byte.TYPE, new ByteConverter());
    this.converters.put(Short.TYPE, new ShortConverter());
    this.converters.put(Character.TYPE, new CharacterConverter());
    this.converters.put(Boolean.TYPE, new BooleanConverter());
    // Date types.
    this.addConverter(new CalendarConverter());
    this.addConverter(new DateConverter());
    // SQL Date types.
    this.addConverter(new SqlDateConverter());
    this.addConverter(new SqlTimeConverter());
    this.addConverter(new SqlTimestampConverter());
    // String.
    this.addConverter(new IdempotentConverter());
    // Numbers.
    this.addConverter(new IntegerConverter());
    this.addConverter(new DoubleConverter());
    this.addConverter(new FloatConverter());
    this.addConverter(new LongConverter());
    this.addConverter(new ByteConverter());
    this.addConverter(new ShortConverter());
    // Character.
    this.addConverter(new CharacterConverter());
    // Math types.
    this.addConverter(new BigDecimalConverter());
    this.addConverter(new BigIntegerConverter());
    // Boolean.
    this.addConverter(new BooleanConverter());
}

From source file:org.wisdom.template.thymeleaf.OgnlOpsByReflectionTest.java

@Test
public void testConvertValue() throws Exception {
    Class[] classes = new Class[] { Object.class, Class.class };
    // Null value
    assertThat(invoke("convertValue", classes, null, Long.TYPE)).isEqualTo(0l);
    assertThat(invoke("convertValue", classes, null, String.class)).isNull();

    // Primitive//from w  w  w.  ja  va  2 s . c o  m
    assertThat(invoke("convertValue", classes, "42", Integer.class)).isEqualTo(42);
    assertThat(invoke("convertValue", classes, "42", Integer.TYPE)).isEqualTo(42);
    assertThat(invoke("convertValue", classes, "42", Byte.class)).isEqualTo(Byte.valueOf("42"));
    assertThat(invoke("convertValue", classes, "42", Byte.TYPE)).isEqualTo(Byte.valueOf("42"));
    assertThat(invoke("convertValue", classes, "42", Short.class)).isEqualTo(Short.valueOf("42"));
    assertThat(invoke("convertValue", classes, "42", Short.TYPE)).isEqualTo(Short.valueOf("42"));
    assertThat(invoke("convertValue", classes, String.valueOf((int) 'c'), Character.class)).isEqualTo('c');
    assertThat(invoke("convertValue", classes, String.valueOf((int) 'c'), Character.TYPE)).isEqualTo('c');
    assertThat(invoke("convertValue", classes, "42", Long.class)).isEqualTo(42l);
    assertThat(invoke("convertValue", classes, "42", Long.TYPE)).isEqualTo(42l);
    assertThat(invoke("convertValue", classes, "true", Boolean.class)).isEqualTo(true);
    assertThat(invoke("convertValue", classes, "true", Boolean.TYPE)).isEqualTo(true);
    assertThat(invoke("convertValue", classes, "42", Double.class)).isEqualTo(42.0);
    assertThat(invoke("convertValue", classes, "42", Double.TYPE)).isEqualTo(42.0);
    assertThat(invoke("convertValue", classes, "42", Float.class)).isEqualTo(42.0f);
    assertThat(invoke("convertValue", classes, "42", Float.TYPE)).isEqualTo(42.0f);

    // BigInteger, BigDecimal and String
    assertThat(invoke("convertValue", classes, "42", BigDecimal.class)).isEqualTo(new BigDecimal("42"));
    assertThat(invoke("convertValue", classes, "42", BigInteger.class)).isEqualTo(new BigInteger("42"));
    assertThat(invoke("convertValue", classes, "42", String.class)).isEqualTo("42");

    //Array
    assertThat(invoke("convertValue", classes, new Object[] { 1, 2, 3 }, (new int[0]).getClass())).isNotNull();
}

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

/**
 * Tests if Class represents a primitive number or wrapper.<br>
 */// ww  w .java2s  .  c o m
public static boolean isNumber(Class clazz) {
    return clazz != null && (Byte.TYPE.isAssignableFrom(clazz) || Short.TYPE.isAssignableFrom(clazz)
            || Integer.TYPE.isAssignableFrom(clazz) || Long.TYPE.isAssignableFrom(clazz)
            || Float.TYPE.isAssignableFrom(clazz) || Double.TYPE.isAssignableFrom(clazz)
            || Number.class.isAssignableFrom(clazz));
}

From source file:com.mawujun.util.AnnotationUtils.java

/**
 * Helper method for comparing two objects of an array type.
 *
 * @param componentType the component type of the array
 * @param o1 the first object/*from   w  w  w .  j  av a  2 s .c  om*/
 * @param o2 the second object
 * @return a flag whether these objects are equal
 */
private static boolean arrayMemberEquals(Class<?> componentType, Object o1, Object o2) {
    if (componentType.isAnnotation()) {
        return annotationArrayMemberEquals((Annotation[]) o1, (Annotation[]) o2);
    }
    if (componentType.equals(Byte.TYPE)) {
        return Arrays.equals((byte[]) o1, (byte[]) o2);
    }
    if (componentType.equals(Short.TYPE)) {
        return Arrays.equals((short[]) o1, (short[]) o2);
    }
    if (componentType.equals(Integer.TYPE)) {
        return Arrays.equals((int[]) o1, (int[]) o2);
    }
    if (componentType.equals(Character.TYPE)) {
        return Arrays.equals((char[]) o1, (char[]) o2);
    }
    if (componentType.equals(Long.TYPE)) {
        return Arrays.equals((long[]) o1, (long[]) o2);
    }
    if (componentType.equals(Float.TYPE)) {
        return Arrays.equals((float[]) o1, (float[]) o2);
    }
    if (componentType.equals(Double.TYPE)) {
        return Arrays.equals((double[]) o1, (double[]) o2);
    }
    if (componentType.equals(Boolean.TYPE)) {
        return Arrays.equals((boolean[]) o1, (boolean[]) o2);
    }
    return Arrays.equals((Object[]) o1, (Object[]) o2);
}

From source file:org.fhcrc.cpl.toolbox.filehandler.TabLoader.java

/**
 * Look at first 5 lines of the file and infer col names, data types.
 * Most useful if maps are being returned, otherwise use inferColumnInfo(reader, clazz) to
 * use properties of a bean instead./*from  ww w. j a v a  2  s  .c o  m*/
 *
 * @param reader
 * @throws IOException
 */
private void inferColumnInfo(BufferedReader reader) throws IOException {
    reader.mark(4096 * _scanAheadLineCount);

    String[] lines = new String[_scanAheadLineCount + Math.max(_skipLines, 0)];
    int i;
    for (i = 0; i < lines.length;) {
        String line = reader.readLine();
        if (null == line)
            break;
        if (line.length() == 0 || line.charAt(0) == '#')
            continue;
        lines[i++] = line;
    }
    int nLines = i;
    reader.reset();
    if (nLines == 0) {
        _columns = new ColumnDescriptor[0];
        return;
    }

    int nCols = 0;
    String[][] lineFields = new String[nLines][];
    for (i = 0; i < nLines; i++) {
        lineFields[i] = parseLine(lines[i]);
        nCols = Math.max(nCols, lineFields[i].length);
    }

    ColumnDescriptor[] colDescs = new ColumnDescriptor[nCols];
    for (i = 0; i < nCols; i++)
        colDescs[i] = new ColumnDescriptor();

    //Try to infer types
    int inferStartLine = _skipLines == -1 ? 1 : _skipLines;
    for (int f = 0; f < nCols; f++) {
        int classIndex = -1;
        for (int line = inferStartLine; line < nLines; line++) {
            if (f >= lineFields[line].length)
                continue;
            String field = lineFields[line][f];
            if ("".equals(field))
                continue;

            for (int c = Math.max(classIndex, 0); c < convertClasses.length; c++) {
                //noinspection EmptyCatchBlock
                try {
                    Object o = ConvertUtils.convert(field, convertClasses[c]);
                    //We found a type that works. If it is more general than
                    //what we had before, we must use it.
                    if (o != null && c > classIndex)
                        classIndex = c;
                    break;
                } catch (Exception x) {
                }
            }
        }
        colDescs[f].clazz = classIndex == -1 ? String.class : convertClasses[classIndex];
    }

    //If first line is compatible type for all fields, AND all fields not Strings (dhmay adding 20100502)
    // then there is no header row
    if (_skipLines == -1) {
        boolean firstLineCompat = true;
        boolean allStrings = true;
        String[] fields = lineFields[0];
        for (int f = 0; f < nCols; f++) {
            if ("".equals(fields[f]))
                continue;
            if (colDescs[f].clazz.equals(Integer.TYPE) || colDescs[f].clazz.equals(Double.TYPE)
                    || colDescs[f].clazz.equals(Float.TYPE))
                allStrings = false;
            try {
                Object o = ConvertUtils.convert(fields[f], colDescs[f].clazz);
                if (null == o) {
                    firstLineCompat = false;
                    break;
                }
            } catch (Exception x) {
                firstLineCompat = false;
                break;
            }
        }
        if (firstLineCompat && !allStrings)
            _skipLines = 0;
        else
            _skipLines = 1;
    }

    if (_skipLines > 0) {
        String[] headers = lineFields[_skipLines - 1];
        for (int f = 0; f < nCols; f++)
            colDescs[f].name = (f >= headers.length || "".equals(headers[f])) ? "column" + f : headers[f];
    } else {
        for (int f = 0; f < colDescs.length; f++) {
            ColumnDescriptor colDesc = colDescs[f];
            colDesc.name = "column" + f;
        }
    }

    _columns = colDescs;
}

From source file:net.sf.json.JSONDynaBean.java

/**
 * DOCUMENT ME!/*from   w w w. j  a v a2 s. c o  m*/
 *
 * @param dest DOCUMENT ME!
 * @param src DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
protected boolean isDynaAssignable(Class dest, Class src) {
    boolean assignable = dest.isAssignableFrom(src);
    assignable = ((dest == Boolean.TYPE) && (src == Boolean.class)) ? true : assignable;
    assignable = ((dest == Byte.TYPE) && (src == Byte.class)) ? true : assignable;
    assignable = ((dest == Character.TYPE) && (src == Character.class)) ? true : assignable;
    assignable = ((dest == Short.TYPE) && (src == Short.class)) ? true : assignable;
    assignable = ((dest == Integer.TYPE) && (src == Integer.class)) ? true : assignable;
    assignable = ((dest == Long.TYPE) && (src == Long.class)) ? true : assignable;
    assignable = ((dest == Float.TYPE) && (src == Float.class)) ? true : assignable;
    assignable = ((dest == Double.TYPE) && (src == Double.class)) ? true : assignable;

    if ((src == Double.TYPE) || Double.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest) || isFloat(dest)) ? true
                : assignable;
    }

    if ((src == Float.TYPE) || Float.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest)) ? true : assignable;
    }

    if ((src == Long.TYPE) || Long.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest)) ? true : assignable;
    }

    if ((src == Integer.TYPE) || Integer.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest)) ? true : assignable;
    }

    if ((src == Short.TYPE) || Short.class.isAssignableFrom(src)) {
        assignable = (isByte(dest)) ? true : assignable;
    }

    return assignable;
}

From source file:org.eclipse.eavp.viz.service.csv.CSVPlot.java

/**
 * Attempts to load the CSV series data from the specified file. This
 * operation ignores all data that is marked as comments (i.e. if the line
 * starts with #), and ignores comments after the data in a line as well.
 * This operation takes the first column of CSV data as the independent
 * series, and the rest as normal, dependent series to be added to the plot.
 * Note that only the first dependent series (the second column) will be
 * initially enabled to be drawn on the plot editor.
 * //from w  w  w  .  j av  a  2s .com
 * @param file
 *            The file to load, assumed to be a valid file.
 */
private void load(File file) {
    // Initially set the name to the file name.
    String plotName = file.getName();
    setPlotTitle(plotName);

    // Configure the list
    ArrayList<String[]> lines = new ArrayList<String[]>();

    try {
        // Grab the contents of the file
        BufferedReader reader = new BufferedReader(new FileReader(file));
        String line = null;
        while ((line = reader.readLine()) != null) {
            // Skip lines that pure comments
            if (!line.startsWith("#")) {
                // Clip the line if it has a comment symbol in it to be
                // everything before the symbol
                if (line.contains("#")) {
                    int index = line.indexOf("#");
                    line = line.substring(0, index);
                }
                // Clean up any bad stuff on the line
                String[] lineArray = line.trim().split(",");
                String[] trimmedLine = new String[lineArray.length];
                // And clean up any bad stuff on each split piece
                for (int i = 0; i < lineArray.length; i++) {
                    trimmedLine[i] = lineArray[i].trim();
                }
                // Put the lines in the list
                lines.add(trimmedLine);
            }
        }

        reader.close();

    } catch (IOException e) {
        // Complain
        logger.error(
                getClass().getName() + " Exception! Could not read in data from file: " + file.getName() + ".",
                e);
    }

    if (!lines.isEmpty()) {

        // TODO- Some sort of implementation to read in the style
        // configurations for the plot, axes, and series. How to go about
        // this? A large part of the series implementation is not being
        // utilized without some sort of recognition here of the style
        // attributes!

        // Assume that the first line has information about the data
        String[] seriesNames = lines.remove(0);

        // Creates the series that contain the data loaded from the file.
        CSVSeries[] series = new CSVSeries[seriesNames.length];
        for (int i = 0; i < seriesNames.length; i++) {
            series[i] = new CSVSeries();
            series[i].setEnabled(false);
            series[i].setLabel(seriesNames[i]);
        }

        // Sets the first two series to be automatically plotted
        series[0].setEnabled(true);
        if (series.length > 1) {
            series[1].setEnabled(true);
        }

        // Load the data as doubles
        for (int i = 0; i < lines.size(); i++) {
            double[] values = (double[]) ConvertUtils.convert(lines.get(i), Double.TYPE);
            for (int j = 0; j < values.length; j++) {
                series[j].add(values[j]);
            }
        }

        // If the independent series has not been set, use the default value
        // just created
        if (getIndependentSeries() == null) {
            // Just set the first series as the independent series for now
            setIndependentSeries(series[0]);
        } else {
            // Otherwise, update the series with the new data
            for (CSVSeries s : series) {
                ISeries current = getIndependentSeries();
                if (current.getLabel().equals(s.getLabel())) {
                    setIndependentSeries(s);
                    break;
                }
            }
        }

        // Add the rest of the series as dependent series
        List<ISeries> dependentSeries = new ArrayList<ISeries>(series.length);
        for (int i = 0; i < series.length; i++) {
            dependentSeries.add(series[i]);
        }
        dataSeries.put(IPlot.DEFAULT_CATEGORY, dependentSeries);

    }

    // Loading has completed.
    loaded.set(true);

    // Notify the listeners that loading has completed.
    notifyPlotListeners("loaded", "true");

    return;
}

From source file:com.haulmont.restapi.service.QueriesControllerManager.java

protected Object toObject(Class clazz, String value) throws ParseException {
    if (clazz.isArray()) {
        Class componentType = clazz.getComponentType();
        JsonParser jsonParser = new JsonParser();
        JsonArray jsonArray = jsonParser.parse(value).getAsJsonArray();
        List result = new ArrayList();
        for (JsonElement jsonElement : jsonArray) {
            String stringValue = (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isString())
                    ? jsonElement.getAsJsonPrimitive().getAsString()
                    : jsonElement.toString();
            Object arrayElementValue = toObject(componentType, stringValue);
            result.add(arrayElementValue);
        }/*from  w  w w  . jav  a  2 s .  c o  m*/
        return result;
    }
    if (String.class == clazz)
        return value;
    if (Integer.class == clazz || Integer.TYPE == clazz || Byte.class == clazz || Byte.TYPE == clazz
            || Short.class == clazz || Short.TYPE == clazz)
        return Datatypes.getNN(Integer.class).parse(value);
    if (Date.class == clazz) {
        try {
            return Datatypes.getNN(Date.class).parse(value);
        } catch (ParseException e) {
            try {
                return Datatypes.getNN(java.sql.Date.class).parse(value);
            } catch (ParseException e1) {
                return Datatypes.getNN(Time.class).parse(value);
            }
        }
    }
    if (BigDecimal.class == clazz)
        return Datatypes.getNN(BigDecimal.class).parse(value);
    if (Boolean.class == clazz || Boolean.TYPE == clazz)
        return Datatypes.getNN(Boolean.class).parse(value);
    if (Long.class == clazz || Long.TYPE == clazz)
        return Datatypes.getNN(Long.class).parse(value);
    if (Double.class == clazz || Double.TYPE == clazz || Float.class == clazz || Float.TYPE == clazz)
        return Datatypes.getNN(Double.class).parse(value);
    if (UUID.class == clazz)
        return UUID.fromString(value);
    throw new IllegalArgumentException("Parameters of type " + clazz.getName() + " are not supported");
}

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

/**
 * Tests if obj is a primitive number or wrapper.<br>
 *///from   ww  w .  jav  a2 s.c  om
public static boolean isNumber(Object obj) {
    if ((obj != null && obj.getClass() == Byte.TYPE) || (obj != null && obj.getClass() == Short.TYPE)
            || (obj != null && obj.getClass() == Integer.TYPE) || (obj != null && obj.getClass() == Long.TYPE)
            || (obj != null && obj.getClass() == Float.TYPE)
            || (obj != null && obj.getClass() == Double.TYPE)) {
        return true;
    }

    return obj instanceof Number;
}

From source file:org.openamf.io.AMFSerializer.java

protected Object[] convertPrimitiveArrayToObjectArray(Object array) throws IOException {
    Class componentType = array.getClass().getComponentType();

    Object[] result = null;/* w  w w .  j av a2 s.  c o m*/

    if (componentType == null) {
        throw new NullPointerException("componentType is null");
    } else if (componentType == Character.TYPE) {
        char[] carray = (char[]) array;
        result = new Object[carray.length];
        for (int i = 0; i < carray.length; i++) {
            result[i] = new Character(carray[i]);
        }
    } else if (componentType == Byte.TYPE) {
        byte[] barray = (byte[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Byte(barray[i]);
        }
    } else if (componentType == Short.TYPE) {
        short[] sarray = (short[]) array;
        result = new Object[sarray.length];
        for (int i = 0; i < sarray.length; i++) {
            result[i] = new Short(sarray[i]);
        }
    } else if (componentType == Integer.TYPE) {
        int[] iarray = (int[]) array;
        result = new Object[iarray.length];
        for (int i = 0; i < iarray.length; i++) {
            result[i] = new Integer(iarray[i]);
        }
    } else if (componentType == Long.TYPE) {
        long[] larray = (long[]) array;
        result = new Object[larray.length];
        for (int i = 0; i < larray.length; i++) {
            result[i] = new Long(larray[i]);
        }
    } else if (componentType == Double.TYPE) {
        double[] darray = (double[]) array;
        result = new Object[darray.length];
        for (int i = 0; i < darray.length; i++) {
            result[i] = new Double(darray[i]);
        }
    } else if (componentType == Float.TYPE) {
        float[] farray = (float[]) array;
        result = new Object[farray.length];
        for (int i = 0; i < farray.length; i++) {
            result[i] = new Float(farray[i]);
        }
    } else if (componentType == Boolean.TYPE) {
        boolean[] barray = (boolean[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Boolean(barray[i]);
        }
    } else {
        throw new IllegalArgumentException("unexpected component type: " + componentType.getClass().getName());
    }

    return result;
}