Example usage for java.lang Double intValue

List of usage examples for java.lang Double intValue

Introduction

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

Prototype

public int intValue() 

Source Link

Document

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

Usage

From source file:Main.java

public static Integer stringToInteger(String str) {
    if (str == null) {
        return null;
    } else {//from w w  w.ja va  2  s. c  o m
        try {
            return Integer.parseInt(str);
        } catch (NumberFormatException e) {
            try {
                Double d = Double.valueOf(str);
                if (d.doubleValue() > mMaxInt.doubleValue() + 1.0) {
                    Log.w(TAG, "Value " + d + " too large for integer");
                    return null;
                }
                return Integer.valueOf(d.intValue());
            } catch (NumberFormatException nfe2) {
                Log.w(TAG,
                        "Unable to interpret value " + str + " in field being "
                                + "converted to int, caught NumberFormatException <" + e.getMessage()
                                + "> field discarded");
                return null;
            }
        }
    }
}

From source file:de.tudarmstadt.ukp.dkpro.tc.weka.report.WekaOutcomeIDReport.java

protected static Properties generateProperties(Instances predictions, boolean isMultilabel,
        boolean isRegression) {
    Properties props = new Properties();
    String[] classValues = new String[predictions.numClasses()];

    for (int i = 0; i < predictions.numClasses(); i++) {
        classValues[i] = predictions.classAttribute().value(i);
    }//ww w  .j a  v  a2  s . co m

    int attOffset = predictions.attribute(Constants.ID_FEATURE_NAME).index();
    for (Instance inst : predictions) {
        if (isMultilabel) {
            List<String> predictionOutcomes = new ArrayList<String>();
            List<String> goldOutcomes = new ArrayList<String>();
            for (int i = 0; i < predictions.classIndex(); i++) {
                if (inst.value(predictions.attribute(i)) == 1.) {
                    goldOutcomes.add(predictions.attribute(i).name());
                }
                if (inst.value(predictions.attribute(i + predictions.classIndex())) == 1.) {
                    predictionOutcomes.add(predictions.attribute(i).name());
                }
            }
            String s = (StringUtils.join(predictionOutcomes, ",") + SEPARATOR_CHAR
                    + StringUtils.join(goldOutcomes, ","));
            props.setProperty(inst.stringValue(attOffset), s);
        } else {
            Double gold;

            try {
                gold = new Double(inst.value(predictions
                        .attribute(Constants.CLASS_ATTRIBUTE_NAME + WekaUtils.COMPATIBLE_OUTCOME_CLASS)));
            } catch (NullPointerException e) {
                // if train and test data have not been balanced
                gold = new Double(inst.value(predictions.attribute(Constants.CLASS_ATTRIBUTE_NAME)));
            }
            Attribute gsAtt = predictions.attribute(WekaTestTask.PREDICTION_CLASS_LABEL_NAME);
            Double prediction = new Double(inst.value(gsAtt));
            if (!isRegression) {
                props.setProperty(inst.stringValue(attOffset),
                        gsAtt.value(prediction.intValue()) + SEPARATOR_CHAR + classValues[gold.intValue()]);
            } else {
                // the outcome is numeric
                props.setProperty(inst.stringValue(attOffset), prediction + SEPARATOR_CHAR + gold);
            }
        }
    }
    return props;
}

From source file:net.sourceforge.fenixedu.util.InquiriesUtil.java

public static String formatAnswer(final Double answer) {
    double ans = answer.doubleValue();

    if (ans > 0) {
        return Math.floor(ans) == ans ? String.valueOf(answer.intValue()) : String.valueOf(ans);
    }/*from  www. j av a  2  s. c o m*/

    return "-";
}

From source file:com.turt2live.xmail.mail.attachment.ItemAttachment.java

private static Map<String, Object> recursiveDoubleToInteger(Map<String, Object> map) {
    Map<String, Object> map2 = new HashMap<String, Object>();
    for (String key : map.keySet()) {
        Object o = map.get(key);//from   ww w . jav a 2s .  c o  m
        map2.put(key, o);
        if (o instanceof Double) {
            Double d = (Double) o;
            Integer i = d.intValue();
            map2.put(key, i);
        } else if (o instanceof Map) {
            @SuppressWarnings("unchecked")
            Map<String, Object> map3 = (Map<String, Object>) o;
            map2.put(key, recursiveDoubleToInteger(map3));
        }
    }
    return map2;
}

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. j  a  va2s.c  o m
    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.sonar.server.debt.DebtRulesXMLImporter.java

private static Property processProperty(ValidationMessages validationMessages, SMInputCursor cursor)
        throws XMLStreamException {
    SMInputCursor c = cursor.childElementCursor();
    String key = null;//ww w .  j  a  v a 2 s. com
    int value = 0;
    String textValue = null;
    while (c.getNext() != null) {
        String node = c.getLocalName();
        if (StringUtils.equals(node, PROPERTY_KEY)) {
            key = c.collectDescendantText().trim();

        } else if (StringUtils.equals(node, PROPERTY_VALUE)) {
            String s = c.collectDescendantText().trim();
            try {
                Double valueDouble = NumberUtils.createDouble(s);
                value = valueDouble.intValue();
            } catch (NumberFormatException ex) {
                validationMessages.addErrorText(String.format(
                        "Cannot import value '%s' for field %s - Expected a numeric value instead", s, key));
            }
        } else if (StringUtils.equals(node, PROPERTY_TEXT_VALUE)) {
            textValue = c.collectDescendantText().trim();
            textValue = "mn".equals(textValue) ? MINUTE : textValue;
        }
    }
    return new Property(key, value, textValue);
}

From source file:mx.developerbus.foodbus.utl.foodBUtil.java

public static int getProgressPercentage(long currentDuration, long totalDuration) {
    Double percentage = (double) 0;

    long currentSeconds = (int) (currentDuration / 1000);
    long totalSeconds = (int) (totalDuration / 1000);

    percentage = (((double) currentSeconds) / totalSeconds) * 100;

    return percentage.intValue();
}

From source file:org.cgiar.dapa.ccafs.tpe.util.Utils.java

public static Integer numberOfTiles(Double distance, Double tileSize) {
    Double tiles = 0.0;

    if (distance != null && distance != 0) {
        tiles = distance / TILE_SIZE_64;

        if (tiles > 1.0)
            return tiles.intValue();
    } else//from   w  ww .ja v  a 2 s  .c  o  m
        return 0;

    return tiles.intValue();
}

From source file:org.awknet.commons.model.business.CPFServiceProvider.java

public static String generateValidCPF() {
    String cpfBody = new String(), cpfComplete = "";
    Double rndDigit;
    Integer digit;//from w  ww. j  av a 2  s.c  om

    try {
        for (int i = 1; i < 10; i++) {
            rndDigit = (Math.random() * 10);
            digit = rndDigit.intValue();
            cpfBody += digit.toString();
        }

        if (!validateDocumentBody(cpfBody))
            throw new CPFException(CPFExceptionType.CPFGeneration);

        cpfComplete = cpfBody + getDigits(cpfBody);
        LOG.debug("value of CPF complete: " + cpfComplete);
        if (!validate(cpfComplete))
            throw new CPFException(CPFExceptionType.CPFCompleteValidation);
    } catch (CPFException e) {
        LOG.error("[genereteValidCPF] error during creation of CPF.", e);
        return null;
    }

    return cpfComplete;
}

From source file:org.dkpro.tc.ml.weka.report.WekaOutcomeIDReport.java

protected static Properties generateSlProperties(Instances predictions, boolean isRegression,
        List<String> labels) throws ClassNotFoundException, IOException {
    Properties props = new SortedKeyProperties();
    String[] classValues = new String[predictions.numClasses()];

    for (int i = 0; i < predictions.numClasses(); i++) {
        classValues[i] = predictions.classAttribute().value(i);
    }/*from  ww  w. jav a  2s  . c  o  m*/

    int attOffset = predictions.attribute(Constants.ID_FEATURE_NAME).index();

    for (Instance inst : predictions) {
        Double gold;
        try {
            gold = new Double(inst.value(predictions
                    .attribute(Constants.CLASS_ATTRIBUTE_NAME + WekaUtils.COMPATIBLE_OUTCOME_CLASS)));
        } catch (NullPointerException e) {
            // if train and test data have not been balanced
            gold = new Double(inst.value(predictions.attribute(Constants.CLASS_ATTRIBUTE_NAME)));
        }
        Attribute gsAtt = predictions.attribute(WekaTestTask.PREDICTION_CLASS_LABEL_NAME);
        Double prediction = new Double(inst.value(gsAtt));
        if (!isRegression) {
            Map<String, Integer> class2number = Id2Outcome.classNamesToMapping(labels);
            Integer predictionAsNumber = class2number.get(gsAtt.value(prediction.intValue()));
            Integer goldAsNumber = class2number.get(classValues[gold.intValue()]);

            String stringValue = inst.stringValue(attOffset);
            props.setProperty(stringValue,
                    predictionAsNumber + SEPARATOR_CHAR + goldAsNumber + SEPARATOR_CHAR + String.valueOf(-1));
        } else {
            // the outcome is numeric
            String stringValue = inst.stringValue(attOffset);
            props.setProperty(stringValue,
                    prediction + SEPARATOR_CHAR + gold + SEPARATOR_CHAR + String.valueOf(0));
        }
    }
    return props;
}