Example usage for java.lang Double floatValue

List of usage examples for java.lang Double floatValue

Introduction

In this page you can find the example usage for java.lang Double floatValue.

Prototype

public float floatValue() 

Source Link

Document

Returns the value of this Double as a float after a narrowing primitive conversion.

Usage

From source file:com.sparkplatform.ui.ListingFormatter.java

public static String getListingSubtitle(Listing listing) {
    if (listing == null)
        return null;

    StringBuilder builder = new StringBuilder();
    Listing.StandardFields standardFields = listing.getStandardFields();
    String value = null;//from   ww w . ja va2  s  .c om
    if ((value = standardFields.getCity()) != null && isStandardField(value))
        builder.append(value);
    if ((value = standardFields.getStateOrProvince()) != null && isStandardField(value)) {
        if (builder.length() > 0)
            builder.append(", ");
        builder.append(value);
    }
    if (builder.length() > 0)
        builder.append(" - ");
    if ((value = standardFields.getBedsTotal()) != null && isStandardField(value)) {
        builder.append(value);
        builder.append("br ");
    }
    Double dValue = null;
    if ((dValue = standardFields.getBathsTotal()) != null && isStandardField(value)) {
        builder.append(dValue.floatValue() - dValue.intValue() > 0 ? oneDecimalFormat.format(dValue)
                : dValue.intValue());
        builder.append("ba ");
    }
    if ((dValue = standardFields.getListPrice()) != null && isStandardField(value))
        builder.append(formatPriceShort(dValue));

    return builder.toString();
}

From source file:org.caleydo.view.enroute.correlation.wilcoxon.WilcoxonUtil.java

public static List<WilcoxonResult> calcAllWilcoxonCombinations(DataCellInfo sourceInfo,
        DataCellInfo targetInfo) {/*from w  w w.  ja  v  a  2s  .  c om*/
    List<WilcoxonResult> results = new ArrayList<>();

    Object description = sourceInfo.dataDomain.getDataClassSpecificDescription(sourceInfo.rowIDType,
            sourceInfo.rowID, sourceInfo.columnPerspective.getIdType(),
            sourceInfo.columnPerspective.getVirtualArray().get(0));

    if (description == null || description instanceof NumericalProperties) {
        List<Double> values = getSampleValues(sourceInfo,
                new HashSet<Object>(sourceInfo.columnPerspective.getVirtualArray().getIDs()));
        Collections.sort(values);

        for (Double threshold : values) {
            NumericalDataClassifier classifier = new NumericalDataClassifier(threshold.floatValue(),
                    WilcoxonRankSumTestWizard.CLASSIFICATION_COLORS_1.getFirst(),
                    WilcoxonRankSumTestWizard.CLASSIFICATION_COLORS_1.getSecond(),
                    Character.toString((char) 0x2264) + " " + threshold, "> " + threshold);

            WilcoxonResult result = calcWilcoxonRankSumTest(sourceInfo, classifier, targetInfo);

            if (result != null) {
                results.add(result);
            }
        }

    } else {

        CategoricalClassDescription<?> classDesc = (CategoricalClassDescription<?>) description;
        Set<Object> allCategories = new LinkedHashSet<>(classDesc.size());
        for (CategoryProperty<?> property : classDesc.getCategoryProperties()) {
            allCategories.add(property.getCategory());
        }
        Set<Set<Object>> combinations = new HashSet<>();
        calcCategoryCombinations(combinations, new HashSet<>(), allCategories);

        Set<Set<Object>> usedClass1s = new HashSet<>();

        for (Set<Object> class1 : combinations) {
            Set<Object> class2 = Sets.symmetricDifference(class1, allCategories);
            if (!class2.isEmpty() && !containsSet(usedClass1s, class2)) {
                usedClass1s.add(class1);
                CategoricalDataClassifier classifier = new CategoricalDataClassifier(class1, class2,
                        WilcoxonRankSumTestWizard.CLASSIFICATION_COLORS_1.getFirst(),
                        WilcoxonRankSumTestWizard.CLASSIFICATION_COLORS_1.getSecond(),
                        getCategoryName(class1, classDesc), getCategoryName(class2, classDesc), classDesc);

                WilcoxonResult result = calcWilcoxonRankSumTest(sourceInfo, classifier, targetInfo);

                if (result != null) {
                    results.add(result);
                }
            }
        }

    }

    return results;
}

From source file:de.iteratec.svg.SvgGraphicWriter.java

/**
 * Converts the generated SVG Document to a PDF and writes in onto the given output stream.
 * /*from   w w w .java2s .c om*/
 * @param document
 *          SVG-{@link Document} to write as PDF
 * @param outputStream
 *          The stream to write to.
 * @throws SvgExportException
 *           Iff the write operation was unsuccessful.
 */
public static void writeToPDF(org.w3c.dom.Document document, OutputStream outputStream)
        throws SvgExportException {
    PDFTranscoder t = new PDFTranscoder();

    LOGGER.debug("Trying to write the document to the output stream as PDF.");

    // Set the transcoding hints.
    Double width = getWidthFromDom(document);
    if (width != null) {
        t.addTranscodingHint(PDFTranscoder.KEY_WIDTH, Float.valueOf(width.floatValue()));
    }
    write(document, outputStream, t);
}

From source file:net.sourceforge.fenixedu.presentationTier.validator.form.GreaterThen.java

public static boolean validateFloat(Object bean, ValidatorAction va, Field field, ActionMessages errors,
        HttpServletRequest request, ServletContext application) {

    String inputString = ValidatorUtils.getValueAsString(bean, field.getProperty());
    String lowerValueString = field.getVarValue("value");

    if ((inputString == null) || (inputString.length() == 0)) {
        return true;
    }/*from  w w  w .j a  v a 2 s  .co  m*/
    Double input = null;
    Double lowerValue = null;

    try {
        input = new Double(inputString);
        lowerValue = new Double(lowerValueString);
    } catch (NumberFormatException e) {
        errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
        return false;
    }

    if (!GenericValidator.isBlankOrNull(inputString)) {
        if (input.floatValue() <= lowerValue.floatValue()) {
            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
        }
        return false;
    }

    return true;
}

From source file:net.sourceforge.fenixedu.presentationTier.validator.form.GreaterThen.java

public static boolean validateFloat0(Object bean, ValidatorAction va, Field field, ActionMessages errors,
        HttpServletRequest request, ServletContext application) {

    String inputString = ValidatorUtils.getValueAsString(bean, field.getProperty());
    String lowerValueString = field.getVarValue("value");

    if ((inputString == null) || (inputString.length() == 0)) {
        return true;
    }//from w  w w .  j a  v  a2s .  c  o m
    Double input = null;
    Double lowerValue = null;

    try {
        input = new Double(inputString);
        lowerValue = new Double(lowerValueString);
    } catch (NumberFormatException e) {
        errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
        return false;
    }

    if (!GenericValidator.isBlankOrNull(inputString)) {
        if (input.floatValue() < lowerValue.floatValue()) {
            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
        }
        return false;
    }

    return true;
}

From source file:Main.java

/**
 * <p>Turns a string value into a java.lang.Number.</p>
 *
 * <p>First, the value is examined for a type qualifier on the end
 * (<code>'f','F','d','D','l','L'</code>).  If it is found, it starts 
 * trying to create successively larger types from the type specified
 * until one is found that can hold the value.</p>
 *
 * <p>If a type specifier is not found, it will check for a decimal point
 * and then try successively larger types from <code>Integer</code> to
 * <code>BigInteger</code> and from <code>Float</code> to
 * <code>BigDecimal</code>.</p>
 *
 * <p>If the string starts with <code>0x</code> or <code>-0x</code>, it
 * will be interpreted as a hexadecimal integer.  Values with leading
 * <code>0</code>'s will not be interpreted as octal.</p>
 *
 * @param val String containing a number
 * @return Number created from the string
 * @throws NumberFormatException if the value cannot be converted
 *//*from   w ww  .ja va2s. c  om*/
public static Number createNumber(String val) throws NumberFormatException {
    if (val == null) {
        return null;
    }
    if (val.length() == 0) {
        throw new NumberFormatException("\"\" is not a valid number.");
    }
    if (val.startsWith("--")) {
        // this is protection for poorness in java.lang.BigDecimal.
        // it accepts this as a legal value, but it does not appear 
        // to be in specification of class. OS X Java parses it to 
        // a wrong value.
        return null;
    }
    if (val.startsWith("0x") || val.startsWith("-0x")) {
        return createInteger(val);
    }
    char lastChar = val.charAt(val.length() - 1);
    String mant;
    String dec;
    String exp;
    int decPos = val.indexOf('.');
    int expPos = val.indexOf('e') + val.indexOf('E') + 1;

    if (decPos > -1) {

        if (expPos > -1) {
            if (expPos < decPos) {
                throw new NumberFormatException(val + " is not a valid number.");
            }
            dec = val.substring(decPos + 1, expPos);
        } else {
            dec = val.substring(decPos + 1);
        }
        mant = val.substring(0, decPos);
    } else {
        if (expPos > -1) {
            mant = val.substring(0, expPos);
        } else {
            mant = val;
        }
        dec = null;
    }
    if (!Character.isDigit(lastChar)) {
        if (expPos > -1 && expPos < val.length() - 1) {
            exp = val.substring(expPos + 1, val.length() - 1);
        } else {
            exp = null;
        }
        //Requesting a specific type..
        String numeric = val.substring(0, val.length() - 1);
        boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
        switch (lastChar) {
        case 'l':
        case 'L':
            if (dec == null && exp == null
                    && (numeric.charAt(0) == '-' && isDigits(numeric.substring(1)) || isDigits(numeric))) {
                try {
                    return createLong(numeric);
                } catch (NumberFormatException nfe) {
                    //Too big for a long
                }
                return createBigInteger(numeric);

            }
            throw new NumberFormatException(val + " is not a valid number.");
        case 'f':
        case 'F':
            try {
                Float f = createFloat(numeric);
                if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
                    //If it's too big for a float or the float value = 0 and the string
                    //has non-zeros in it, then float does not have the precision we want
                    return f;
                }

            } catch (NumberFormatException e) {
                // ignore the bad number
            }
            //Fall through
        case 'd':
        case 'D':
            try {
                Double d = createDouble(numeric);
                if (!(d.isInfinite() || (d.floatValue() == 0.0D && !allZeros))) {
                    return d;
                }
            } catch (NumberFormatException nfe) {
                // empty catch
            }
            try {
                return createBigDecimal(numeric);
            } catch (NumberFormatException e) {
                // empty catch
            }
            //Fall through
        default:
            throw new NumberFormatException(val + " is not a valid number.");

        }
    } else {
        //User doesn't have a preference on the return type, so let's start
        //small and go from there...
        if (expPos > -1 && expPos < val.length() - 1) {
            exp = val.substring(expPos + 1, val.length());
        } else {
            exp = null;
        }
        if (dec == null && exp == null) {
            //Must be an int,long,bigint
            try {
                return createInteger(val);
            } catch (NumberFormatException nfe) {
                // empty catch
            }
            try {
                return createLong(val);
            } catch (NumberFormatException nfe) {
                // empty catch
            }
            return createBigInteger(val);

        } else {
            //Must be a float,double,BigDec
            boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
            try {
                Float f = createFloat(val);
                if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
                    return f;
                }
            } catch (NumberFormatException nfe) {
                // empty catch
            }
            try {
                Double d = createDouble(val);
                if (!(d.isInfinite() || (d.doubleValue() == 0.0D && !allZeros))) {
                    return d;
                }
            } catch (NumberFormatException nfe) {
                // empty catch
            }

            return createBigDecimal(val);

        }

    }
}

From source file:com.github.jessemull.microflex.util.DoubleUtil.java

/**
 * Converts a list of doubles to a list of floats.
 * @param    List<Double>    list of doubles
 * @return                   list of floats
 *///from   w w  w  . j a va  2  s . c o m
public static List<Float> toFloatList(List<Double> list) {

    List<Float> floatList = new ArrayList<Float>();

    for (Double val : list) {
        if (!OverFlowUtil.floatOverflow(val)) {
            OverFlowUtil.overflowError(val);
        }
        floatList.add(val.floatValue());
    }

    return floatList;

}

From source file:org.dbmfs.DbmfsUtil.java

public static Object deserializeType(Double value, String javaTypeName) {
    if (javaTypeName.equals("java.lang.Double")) {
        return value;
    }/*from   w w w. j  a  v  a2 s  . c o m*/

    if (javaTypeName.equals("java.lang.Float")) {
        return value.floatValue();
    }

    if (javaTypeName.equals("java.math.BigDecimal")) {
        return new BigDecimal(value.doubleValue());
    }
    return value;
}

From source file:com.projity.util.ClassUtils.java

/**
 * Convert a Double to an Object of a given class
 * @param value Double value to convert//from w  ww . ja va2 s.  c om
 * @param clazz Class the class to convert to
 * @return new object of the given class
 * @throws IllegalArgumentException if the value is not convertible to the class
 */
public static Object doubleToObject(Double value, Class clazz) {
    if (clazz == Boolean.class)
        return new Boolean(value.doubleValue() != 0.0);
    else if (clazz == Byte.class)
        return new Byte(value.byteValue());
    else if (clazz == Short.class)
        return new Short(value.shortValue());
    else if (clazz == Integer.class)
        return new Integer(value.intValue());
    else if (clazz == Long.class)
        return new Long(value.longValue());
    else if (clazz == Float.class)
        return new Float(value.floatValue());
    else if (clazz == Double.class)
        return value;
    else if (clazz == Money.class)
        return Money.getInstance(value.doubleValue());
    else if (clazz == Duration.class)
        return Duration.getInstanceFromDouble(value);
    else if (clazz == Work.class)
        return Work.getWorkInstanceFromDouble(value);

    throw new IllegalArgumentException("Class " + clazz + " cannot be converted from a Double");
}

From source file:de.walware.statet.r.core.rsource.ast.RAst.java

public static Float toJavaFloat(RAstNode node) {
    while (node != null) {
        switch (node.getNodeType()) {
        case NUM_CONST:
            switch (node.getOperator(0)) {
            case NUM_NUM: {
                final Double num = parseNum(node.getText());
                if (num != null && Math.abs(num.doubleValue()) <= Float.MAX_VALUE) {
                    return num.floatValue();
                }/*from   w  w  w.  j a v a 2  s.c  o  m*/
                break;
            }
            case NUM_INT: {
                final Integer num = parseInt(node.getText());
                if (num != null) {
                    return num.floatValue();
                }
                break;
            }
            case TRUE:
                return 1f;
            case FALSE:
                return 0f;
            default:
                break;
            }
            return null;
        case F_CALL_ARG:
            node = ((FCall.Arg) node).getValueChild();
            continue;
        default:
            return null;
        }
    }
    return null;
}