Example usage for java.lang Double doubleValue

List of usage examples for java.lang Double doubleValue

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public double doubleValue() 

Source Link

Document

Returns the double value of this Double object.

Usage

From source file:msi.gama.util.matrix.GamaFloatMatrix.java

@Override
public boolean _removeFirst(final IScope scope, final Double o) throws GamaRuntimeException {
    // Exception if o == null
    return remove(o.doubleValue());
}

From source file:org.pentaho.di.core.row.ValueDataUtil.java

public static Double multiplyDoubles(Double a, Double b) {
    return new Double(a.doubleValue() * b.doubleValue());
}

From source file:org.pentaho.di.core.row.ValueDataUtil.java

public static Double divideDoubles(Double a, Double b) {
    return new Double(a.doubleValue() / b.doubleValue());
}

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

@Override
public Integer bytesToInteger(byte[] b) throws IOException {
    if (b == null || b.length == 0) {
        return null;
    }/*ww  w .java  2  s. c o  m*/

    String s = new String(b);
    s = s.trim();
    Integer ret = null;

    // See PIG-2835. Using exception handling to check if it's a double is very expensive.
    // So we write our sanity check.
    if (sanityCheckIntegerLong(s)) {
        try {
            ret = Integer.valueOf(s);
        } catch (NumberFormatException nfe) {
        }
    }
    if (ret == null) {
        // It's possible that this field can be interpreted as a double.
        // Unfortunately Java doesn't handle this in Integer.valueOf.  So
        // we need to try to convert it to a double and if that works then
        // go to an int.
        try {
            Double d = Double.valueOf(s);
            // Need to check for an overflow error
            if (Double.compare(d.doubleValue(), mMaxInt.doubleValue() + 1) >= 0
                    || Double.compare(d.doubleValue(), mMinInt.doubleValue() - 1) <= 0) {
                LogUtils.warn(this, "Value " + d + " too large for integer", PigWarning.TOO_LARGE_FOR_INT,
                        mLog);
                return null;
            }
            return Integer.valueOf(d.intValue());
        } catch (NumberFormatException nfe2) {
            LogUtils.warn(this,
                    "Unable to interpret value " + Arrays.toString(b) + " in field being "
                            + "converted to int, caught NumberFormatException <" + nfe2.getMessage()
                            + "> field discarded",
                    PigWarning.FIELD_DISCARDED_TYPE_CONVERSION_FAILED, mLog);
            return null;
        }
    }
    return ret;
}

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

@Override
public Long bytesToLong(byte[] b) throws IOException {
    if (b == null || b.length == 0) {
        return null;
    }/*from  w  ww  .j  ava  2 s. c  o m*/

    String s = new String(b).trim();
    if (s.endsWith("l") || s.endsWith("L")) {
        s = s.substring(0, s.length() - 1);
    }

    // See PIG-2835. Using exception handling to check if it's a double is very expensive.
    // So we write our sanity check.
    Long ret = null;
    if (sanityCheckIntegerLong(s)) {
        try {
            ret = Long.valueOf(s);
        } catch (NumberFormatException nfe) {
        }
    }

    if (ret == null) {
        // It's possible that this field can be interpreted as a double.
        // Unfortunately Java doesn't handle this in Long.valueOf.  So
        // we need to try to convert it to a double and if that works then
        // go to an long.
        try {
            Double d = Double.valueOf(s);
            // Need to check for an overflow error
            if (Double.compare(d.doubleValue(), mMaxLong.doubleValue() + 1) > 0
                    || Double.compare(d.doubleValue(), mMinLong.doubleValue() - 1) < 0) {
                LogUtils.warn(this, "Value " + d + " too large for long", PigWarning.TOO_LARGE_FOR_INT, mLog);
                return null;
            }
            return Long.valueOf(d.longValue());
        } catch (NumberFormatException nfe2) {
            LogUtils.warn(this,
                    "Unable to interpret value " + Arrays.toString(b) + " in field being "
                            + "converted to long, caught NumberFormatException <" + nfe2.getMessage()
                            + "> field discarded",
                    PigWarning.FIELD_DISCARDED_TYPE_CONVERSION_FAILED, mLog);
            return null;
        }
    }
    return ret;
}

From source file:edu.uci.ics.pregelix.example.util.TestExecutor.java

private boolean equalStrings(String s1, String s2) {
    String[] rowsOne = s1.split("\n");
    String[] rowsTwo = s2.split("\n");

    for (int i = 0; i < rowsOne.length; i++) {
        String row1 = rowsOne[i];
        String row2 = rowsTwo[i];

        if (row1.equals(row2))
            continue;

        String[] fields1 = row1.split(" ");
        String[] fields2 = row2.split(" ");

        boolean bagEncountered = false;
        Set<String> bagElements1 = new HashSet<String>();
        Set<String> bagElements2 = new HashSet<String>();

        for (int j = 0; j < fields1.length; j++) {
            if (j >= fields2.length) {
                return false;
            } else if (fields1[j].equals(fields2[j])) {
                if (fields1[j].equals("{{"))
                    bagEncountered = true;
                if (fields1[j].startsWith("}}")) {
                    if (!bagElements1.equals(bagElements2))
                        return false;
                    bagEncountered = false;
                    bagElements1.clear();
                    bagElements2.clear();
                }//from ww w  .  j a v  a2 s  . c o  m
                continue;
            } else if (fields1[j].indexOf('.') < 0) {
                if (bagEncountered) {
                    bagElements1.add(fields1[j].replaceAll(",$", ""));
                    bagElements2.add(fields2[j].replaceAll(",$", ""));
                    continue;
                }
                return false;
            } else {
                // If the fields are floating-point numbers, test them
                // for equality safely
                fields1[j] = fields1[j].split(",")[0];
                fields2[j] = fields2[j].split(",")[0];
                try {
                    Double double1 = Double.parseDouble(fields1[j]);
                    Double double2 = Double.parseDouble(fields2[j]);
                    float float1 = (float) double1.doubleValue();
                    float float2 = (float) double2.doubleValue();

                    if (Math.abs(float1 - float2) == 0)
                        continue;
                    else {
                        return false;
                    }
                } catch (NumberFormatException ignored) {
                    // Guess they weren't numbers - must simply not be equal
                    return false;
                }
            }
        }
    }
    return true;
}

From source file:org.sakaiproject.tool.gradebook.test.GradebookServiceInternalTest.java

public void testExternalClientSupport() throws Exception {
    setAuthnId(TA_UID);/*from  w w w .  j  av a 2s.  c o m*/

    List assignments = gradebookService.getAssignments(GRADEBOOK_UID);
    Assert.assertTrue(assignments.size() == 2);

    for (Iterator iter = assignments.iterator(); iter.hasNext();) {
        Assignment assignment = (Assignment) iter.next();

        if (assignment.isExternallyMaintained()) {
            Assert.assertTrue(EXT_TITLE_1.equals(assignment.getName()));
            // Make sure we can't update it.
            boolean gotSecurityException = false;
            try {
                if (log.isInfoEnabled())
                    log.info("Ignore the upcoming authorization error...");
                gradebookService.setAssignmentScoreString(GRADEBOOK_UID, EXT_TITLE_1, STUDENT_IN_SECTION_UID,
                        new String("9"), "Service Test");
            } catch (SecurityException e) {
                gotSecurityException = true;
            }
            Assert.assertTrue(gotSecurityException);
        } else {
            Assert.assertTrue(ASN_TITLE.equals(assignment.getName()));
            Assert.assertTrue(assignment.getPoints().equals(ASN_POINTS));

            Assert.assertFalse(gradebookService.isUserAbleToGradeItemForStudent(GRADEBOOK_UID,
                    assignment.getId(), STUDENT_NOT_IN_SECTION_UID));
            boolean gotSecurityException = false;
            try {
                if (log.isInfoEnabled())
                    log.info("Ignore the upcoming authorization error...");
                gradebookService.getAssignmentScoreString(GRADEBOOK_UID, ASN_TITLE, STUDENT_NOT_IN_SECTION_UID);
            } catch (SecurityException e) {
                gotSecurityException = true;
            }
            gotSecurityException = false;
            try {
                if (log.isInfoEnabled())
                    log.info("Ignore the upcoming authorization error...");
                gradebookService.setAssignmentScoreString(GRADEBOOK_UID, ASN_TITLE, STUDENT_NOT_IN_SECTION_UID,
                        new String("39"), "Service Test");
            } catch (SecurityException e) {
                gotSecurityException = true;
            }
            Assert.assertTrue(gotSecurityException);

            Assert.assertTrue(gradebookService.isUserAbleToGradeItemForStudent(GRADEBOOK_UID,
                    assignment.getId(), STUDENT_IN_SECTION_UID));
            String scoreAsString = gradebookService.getAssignmentScoreString(GRADEBOOK_UID, ASN_TITLE,
                    STUDENT_IN_SECTION_UID);
            Assert.assertTrue(scoreAsString == null);
            gradebookService.setAssignmentScoreString(GRADEBOOK_UID, ASN_TITLE, STUDENT_IN_SECTION_UID,
                    new String("39"), "Service Test");
            Double score = new Double(gradebookService.getAssignmentScoreString(GRADEBOOK_UID, ASN_TITLE,
                    STUDENT_IN_SECTION_UID));
            Assert.assertTrue(score.doubleValue() == 39.0);

            // Make sure a record was made in the history log.
            List studentUids = Arrays.asList(new String[] { STUDENT_IN_SECTION_UID, });
            GradingEvents gradingEvents = gradebookManager
                    .getGradingEvents(gradebookManager.getAssignment(asnId), studentUids);
            List events = gradingEvents.getEvents(STUDENT_IN_SECTION_UID);
            Assert.assertTrue(events.size() == 1);

            // Also test the case where there's a score already there.
            gradebookService.setAssignmentScoreString(GRADEBOOK_UID, ASN_TITLE, STUDENT_IN_SECTION_UID,
                    new String("37"), "Different Service Test");
            score = new Double(gradebookService.getAssignmentScoreString(GRADEBOOK_UID, ASN_TITLE,
                    STUDENT_IN_SECTION_UID));
            Assert.assertTrue(score.doubleValue() == 37.0);
        }
    }
}

From source file:com.ctc.storefront.controllers.pages.StoreLocatorPageController.java

@RequestMapping(method = RequestMethod.GET, params = "q")
public String findStores(@RequestParam(value = "page", defaultValue = "0") final int page, // NOSONAR
        @RequestParam(value = "show", defaultValue = "Page") final AbstractSearchPageController.ShowMode showMode,
        @RequestParam(value = "sort", required = false) final String sortCode,
        @RequestParam(value = "q") final String locationQuery,
        @RequestParam(value = "latitude", required = false) final Double latitude,
        @RequestParam(value = "longitude", required = false) final Double longitude,
        final StoreFinderForm storeFinderForm, final Model model, final BindingResult bindingResult)
        throws CMSItemNotFoundException {
    final String sanitizedSearchQuery = XSSFilterUtil.filter(locationQuery);

    if (latitude != null && longitude != null) {
        final GeoPoint geoPoint = new GeoPoint();
        geoPoint.setLatitude(latitude.doubleValue());
        geoPoint.setLongitude(longitude.doubleValue());

        setUpSearchResultsForPosition(geoPoint,
                createPageableData(page, getStoreLocatorPageSize(), sortCode, showMode), model);
    } else if (StringUtils.isNotBlank(sanitizedSearchQuery)) {

        setUpSearchResultsForLocationQuery(sanitizedSearchQuery,
                createPageableData(page, getStoreLocatorPageSize(), sortCode, showMode), model);
        setUpMetaData(sanitizedSearchQuery, model);
        setUpPageForms(model);/*  w w w.j ava  2 s  . co  m*/
        setUpPageTitle(sanitizedSearchQuery, model);

    } else {

        GlobalMessages.addErrorMessage(model, "storelocator.error.no.results.subtitle");
        model.addAttribute(WebConstants.BREADCRUMBS_KEY,
                storefinderBreadcrumbBuilder.getBreadcrumbsForLocationSearch(sanitizedSearchQuery));

    }

    storeCmsPageInModel(model, getStoreFinderPage());

    return ControllerConstants.Views.Pages.StoreFinder.StoreFinderSearchPage;
}

From source file:eu.trentorise.game.test.GameTest.java

public void assertionPoint(String gameId, Double score, String playerId, String conceptName) {
    List<PlayerState> states = playerSrv.loadStates(gameId);
    StateAnalyzer analyzer = new StateAnalyzer(states);
    Assert.assertEquals(String.format("Failure point concept %s for  player %s", conceptName, playerId),
            score.doubleValue(), analyzer.getScore(analyzer.findPlayer(playerId), conceptName), 0);
}

From source file:com.germinus.easyconf.ComponentProperties.java

public double getDouble(String key, Filter filter) {
    Double value = getDouble(key, filter, null);
    validateValue(key, value);//from w  w  w .  j a  v  a 2 s  . co  m
    return value.doubleValue();
}