Example usage for java.lang Double valueOf

List of usage examples for java.lang Double valueOf

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static Double valueOf(double d) 

Source Link

Document

Returns a Double instance representing the specified double value.

Usage

From source file:de.tudarmstadt.informatik.lt.sogaardparser.MWEData.java

/**
 * Reads in a file in DRUID data format, discards any unigrams, and stores multi word expressions together with
 * their druid score./*w ww  .  j a va 2  s  .c  om*/
 *
 * @param file     the MWE file
 * @param minScore the minimum druid score to load a MWE
 */
public MWEData(Path file, double minScore) throws IOException {
    entries = new HashMap<>();
    try (BufferedReader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
        String line = null;
        while ((line = reader.readLine()) != null) {
            String[] parts = line.split("\t");
            if (Integer.valueOf(parts[0]) > 1 && Double.valueOf(parts[2]) >= minScore) {
                entries.put(parts[1], Double.valueOf(parts[2]));
            }
        }
    }
    if (entries.isEmpty()) {
        Logger.getLogger(this.getClass().getName())
                .warning("Found no multiword expressions in file " + file.toString());
    }
}

From source file:de.tudarmstadt.ukp.dkpro.wsd.si.dictionary.util.AbstractDictionary.java

public Map<String, Double> getWeightedSenses(String sod) {
    Map<String, Double> weightedSenses = new HashMap<String, Double>();
    double sum = 0;
    double max = 0;
    for (String[] sense : getTargetValuePairs(sod)) {
        sum += Double.valueOf(sense[1]);
        if (Double.valueOf(sense[1]) > max) {
            max = Double.valueOf(sense[1]);
        }/* w  ww .  j a va2s.  co  m*/
    }

    for (String[] sense : getTargetValuePairs(sod)) {
        if (weightedSenses.containsKey(sense[0])) {
            weightedSenses.put(sense[0], Double.valueOf(sense[1]) / sum + weightedSenses.get(sense[0]));
        } else {
            if (Double.valueOf(sense[1]) / max > 0.01) {
                weightedSenses.put(sense[0], Double.valueOf(sense[1]) / sum);
            }
        }
    }

    return weightedSenses;
}

From source file:ca.uwaterloo.iss4e.algorithm.PAR.java

public static Double[][] computeParameters(final Double[] readings, int order, int seasons) {
    Double[][] parameters = new Double[seasons][];
    try {/*from w  w w.ja  v a2s  .co  m*/
        double[][] series = makeSeries(readings, seasons);
        for (int season = 0; season < series.length; ++season) {
            double[] serie = series[season];
            Pair pair = makePair(serie, order);
            double[] Y = (double[]) pair.getKey();
            double[][] X = (double[][]) pair.getValue();
            OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression();
            // regression.setNoIntercept(true);
            regression.newSampleData(Y, X);
            double[] params = regression.estimateRegressionParameters();
            Double[] bigParams = new Double[params.length];
            for (int i = 0; i < params.length; ++i) {
                bigParams[i] = Double.valueOf(params[i]);
            }
            parameters[season] = bigParams;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return parameters;
}

From source file:org.hawkular.alerter.prometheus.PrometheusQueryTest.java

@Ignore // Requires manually running Prom on localhost:9090
@Test/*from  w  w  w .  ja v a  2 s.c om*/
public void queryTest() throws Exception {
    CloseableHttpClient client = HttpClients.createDefault();

    StringBuffer url = new StringBuffer("http://localhost:9090");
    url.append("/api/v1/query?query=");
    url.append("up");

    HttpGet getRequest = new HttpGet(url.toString());
    HttpResponse response = client.execute(getRequest);

    if (response.getStatusLine().getStatusCode() != 200) {
        String msg = String.format("Prometheus GET failed. Status=[%d], message=[%s], url=[%s]",
                response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase(),
                url.toString());
        System.out.println(msg);
        fail();
    } else {
        try {
            QueryResponse queryResponse = JsonUtil.getMapper().readValue(response.getEntity().getContent(),
                    QueryResponse.class);
            assertEquals("success", queryResponse.getStatus());
            QueryResponse.Data data = queryResponse.getData();
            assertEquals("vector", data.getResultType());
            QueryResponse.Result[] result = data.getResult();
            assertEquals(1, result.length);
            QueryResponse.Result r = result[0];
            assertEquals("up", r.getMetric().get("__name__"));
            assertEquals("prometheus", r.getMetric().get("job"));
            assertEquals(2, r.getValue().length);
            long tsMillis = Double.valueOf((double) r.getValue()[0] * 1000).longValue();
            assertEquals(String.valueOf(r.getValue()[0]), String.valueOf(System.currentTimeMillis()).length(),
                    String.valueOf(tsMillis).length());
            assertEquals("1", r.getValue()[1]);
        } catch (IOException e) {
            String msg = String.format("Failed to Map prom response [%s]: %s", response.getEntity(), e);
            System.out.println(msg);
            fail();
        }
    }
    client.close();
}

From source file:com.ning.metrics.meteo.subscribers.FileSubscriber.java

private ImmutableList<LinkedHashMap<String, Object>> getDataPoints() {
    ImmutableList.Builder<LinkedHashMap<String, Object>> builder = new ImmutableList.Builder<LinkedHashMap<String, Object>>();

    try {//  ww  w.j av  a  2s. c  o  m
        for (String line : (List<String>) IOUtils.readLines(new FileReader(subscriberConfig.getFilePath()))) {
            if (line.trim().length() > 0) {
                map.clear();
                String[] items = line.split(subscriberConfig.getSeparator());
                long dateTime = new DateTime(items[0], DateTimeZone.forID("UTC")).getMillis();
                map.put("timestamp", dateTime);
                for (int j = 1; j < items.length; j++) {
                    double value = Double.valueOf(items[j]);
                    map.put(subscriberConfig.getAttributes()[j], value);
                }
                builder.add(new LinkedHashMap(map));
            }
        }

        return builder.build();
    } catch (IOException e) {
        log.error("Unable to read file: " + subscriberConfig.getFilePath());
        return null;
    }
}

From source file:com.marvelution.bamboo.plugins.sonar.tasks.web.contextproviders.SonarTimeMachineChartContextProvider.java

/**
 * {@inheritDoc}//from   ww w. ja  va 2  s . co m
 */
@Override
public Map<String, Object> getContextMap(Map<String, Object> context) {
    super.getContextMap(context);
    Collection<String> errors = Lists.newArrayList();
    Server serverInfo = (Server) context.get(SONAR_SERVER_INFO_CONTEXT_KEY);
    if (serverInfo != null && Double.valueOf(serverInfo.getVersion()) < 3.0D) {
        Chain chain = getChainPlan(context);
        User user = authenticationContext.getUser();
        List<String> metrics = null;
        if (chain != null && user != null) {
            LOGGER.debug("Checking if user " + user.getName() + " has custom metrics");
            metrics = sonarMetricsManager.getTimeMachineChartMetrics(chain, user);
        }
        if (metrics == null || metrics.isEmpty()) {
            metrics = sonarMetricsManager.getTimeMachineChartMetrics(chain);
        }
        context.put("metrics", metrics);
        SonarConfiguration sonarConfiguration = (SonarConfiguration) context.get("sonarConfiguration");
        if (sonarConfiguration.isAnalyzed()) {
            try {
                Sonar sonar = new Sonar(new HttpClient4Connector(sonarConfiguration.getSonarHost()));
                String json = sonar.getConnector()
                        .execute(new ProjectQuery(sonarConfiguration.getProjectKey()).setVersions(true));
                List<String> versionIds = Lists.newArrayList();
                if (json != null) {
                    Project project = new ProjectUnmarshaller().toModel(json);
                    for (Version version : project.getVersions()) {
                        versionIds.add(Integer.toString(version.getSid()));
                    }
                }
                context.put("versions", StringUtils.join(versionIds, ","));
            } catch (ConnectionException e) {
                LOGGER.error("Failed to get version IDs from Sonar: " + e.getMessage());
                if (e.getCause() instanceof HttpHostConnectException) {
                    context.put("exception", e.getCause());
                } else {
                    context.put("exception", e);
                }
            }
        }
    } else {
        errors.add("The Time Machine Chart is nolonger supported with Sonar 3.0 and up.");
        errors.add(
                "We are working on implementing a new Panel. (<a href='http://issues.marvelution.com/browse/BAMSON-64'>BAMSON-64</a>)");
    }
    context.put("errors", errors);
    return context;
}

From source file:com.nebhale.cyclinglibrary.repository.JdbcItemRepositoryTest.java

@Test
public void create() {
    this.jdbcTemplate.update("INSERT INTO types(id, name, shortName) VALUES(?, ?, ?)", 0, "test-name",
            "test-short-name");
    this.jdbcTemplate.update("INSERT INTO collections(id, typeId, name, shortName) VALUES(?, ?, ?, ?)", 1, 0,
            "test-name", "test-short-name");

    Item item = this.itemRepository.create(Long.valueOf(1), "test-name", "test-short-name",
            StubPointFactory.create(0), StubPointFactory.create(1));

    Map<String, Object> itemData = this.jdbcTemplate
            .queryForMap("SELECT id, collectionId, name, shortName FROM items");
    assertEquals(Long.valueOf(1), itemData.get("collectionId"));
    assertEquals("test-name", itemData.get("name"));
    assertEquals("test-short-name", itemData.get("shortName"));
    assertEquals(itemData.get("id"), item.getId());
    assertEquals(itemData.get("collectionId"), item.getCollectionId());
    assertEquals(itemData.get("name"), item.getName());
    assertEquals(itemData.get("shortName"), item.getShortName());

    List<Point> points = item.getPoints();
    List<Map<String, Object>> pointsData = this.jdbcTemplate
            .queryForList("SELECT id, itemId, latitude, longitude, elevation FROM points");

    Point point0 = points.get(0);
    Map<String, Object> point0Data = pointsData.get(0);
    assertEquals(item.getId(), point0Data.get("itemId"));
    assertEquals(Double.valueOf(0), point0Data.get("latitude"));
    assertEquals(Double.valueOf(1), point0Data.get("longitude"));
    assertEquals(Double.valueOf(2), point0Data.get("elevation"));
    assertEquals(point0Data.get("id"), point0.getId());
    assertEquals(point0Data.get("itemId"), point0.getItemId());
    assertEquals(point0Data.get("latitude"), point0.getLatitude());
    assertEquals(point0Data.get("longitude"), point0.getLongitude());
    assertEquals(point0Data.get("elevation"), point0.getElevation());

    Point point1 = points.get(1);
    Map<String, Object> point1Data = pointsData.get(1);
    assertEquals(item.getId(), point1Data.get("itemId"));
    assertEquals(Double.valueOf(1), point1Data.get("latitude"));
    assertEquals(Double.valueOf(2), point1Data.get("longitude"));
    assertEquals(Double.valueOf(3), point1Data.get("elevation"));
    assertEquals(point1Data.get("id"), point1.getId());
    assertEquals(point1Data.get("itemId"), point1.getItemId());
    assertEquals(point1Data.get("latitude"), point1.getLatitude());
    assertEquals(point1Data.get("longitude"), point1.getLongitude());
    assertEquals(point1Data.get("elevation"), point1.getElevation());
}

From source file:hip.ch3.seqfile.writable.StockPriceWritable.java

public static StockPriceWritable fromLine(String line) throws IOException {
    String[] parts = line.split(",");

    StockPriceWritable stock = new StockPriceWritable(
            //<co id="ch03_comment_seqfile_write3"/>
            parts[0], parts[1], Double.valueOf(parts[2]), Double.valueOf(parts[3]), Double.valueOf(parts[4]),
            Double.valueOf(parts[5]), Integer.valueOf(parts[6]), Double.valueOf(parts[7]));
    return stock;
}

From source file:functions.LoadCSVdata.java

public void LoadData() {
    // ArrayList<Resident> residents = new ArrayList<>();
    try {//from ww  w.j a v a2  s. com
        // READ FEE TABLE
        file = new File(PATH + FEE_FILE);
        System.out.println(file.toPath());
        parser = CSVParser.parse(file, Charset.forName("UTF-8"), CSVFormat.DEFAULT);
        Fee new_fee;
        Resident new_res;
        for (CSVRecord c : parser) {

            // skip first record
            if (c.getRecordNumber() == 1)
                continue;

            System.out.println(c.get(datatype.GlobalVariable.TYPE) + ", "
                    + c.get(datatype.GlobalVariable.AMOUNT) + ", " + c.get(datatype.GlobalVariable.PAID_BY)
                    + ", " + c.get(datatype.GlobalVariable.PAYER));
            String tmp = c.get(datatype.GlobalVariable.PAYER);
            //String payers;

            String[] payers = tmp.split(";");

            System.out.println(payers.length);
            new_fee = new Fee();
            new_fee.name = c.get(datatype.GlobalVariable.TYPE);
            new_fee.amount = Double.valueOf(c.get(datatype.GlobalVariable.AMOUNT));
            new_fee.number_of_payer = payers.length;

            System.out.println("new fee: " + new_fee.name);

            //datatype.GlobalVariable.FEES

            int res_index;
            // add payer

            for (int i = 0; i < payers.length; i++) {
                res_index = -1;
                for (Resident r : datatype.GlobalVariable.RESIDENTS) {
                    if (r.name.equals(payers[i])) {
                        res_index = datatype.GlobalVariable.RESIDENTS.indexOf(r);
                        break;
                    }
                }

                System.out.println(res_index);

                // new resident found
                if (res_index == -1) {
                    new_res = new Resident();

                    // System.out.println(payers[i]);
                    new_res.name = payers[i];
                    datatype.GlobalVariable.RESIDENTS.add(new_res);
                    res_index = datatype.GlobalVariable.RESIDENTS.indexOf(new_res);
                }

                // insert payer's fee
                //                    if(datatype.GlobalVariable.RESIDENTS.get(res_index).extra_fee.size()>=1)
                //                        System.out.println(datatype.GlobalVariable.RESIDENTS.get(res_index).extra_fee.get(datatype.GlobalVariable.RESIDENTS.get(res_index).extra_fee.size()-1).name);
                datatype.GlobalVariable.RESIDENTS.get(res_index).extra_fee.add(new_fee);
                //                    System.out.println(datatype.GlobalVariable.RESIDENTS.get(res_index).extra_fee.get(datatype.GlobalVariable.RESIDENTS.get(res_index).extra_fee.size()-1).name);
            }

            // add paid by

            res_index = -1;
            for (Resident r : datatype.GlobalVariable.RESIDENTS) {
                if (r.name.equals(c.get(datatype.GlobalVariable.PAID_BY))) {
                    res_index = datatype.GlobalVariable.RESIDENTS.indexOf(r);
                    break;
                }
            }

            // new resident found
            if (res_index == -1) {
                new_res = new Resident();

                new_res.name = c.get(datatype.GlobalVariable.PAID_BY);
                datatype.GlobalVariable.RESIDENTS.add(new_res);
                res_index = datatype.GlobalVariable.RESIDENTS.indexOf(new_res);
            }

            // insert paid
            datatype.GlobalVariable.RESIDENTS.get(res_index).paid.add(new_fee);

        }

        file = new File(PATH + RESIDENTS_FILE);
        // READ RESIDENT TABLE
        parser = CSVParser.parse(file, Charset.forName("UTF-8"), CSVFormat.DEFAULT);
        for (CSVRecord c : parser) {

            // skip first record
            if (c.getRecordNumber() == 1)
                continue;

            System.out
                    .println(c.get(datatype.GlobalVariable.NAME) + ", " + c.get(datatype.GlobalVariable.RENT));
            int res_index = -1;
            for (Resident r : datatype.GlobalVariable.RESIDENTS) {
                if (r.name.equals(c.get(datatype.GlobalVariable.NAME))) {
                    res_index = datatype.GlobalVariable.RESIDENTS.indexOf(r);
                    break;
                }
            }
            datatype.GlobalVariable.RESIDENTS.get(res_index).basic_rent = Integer
                    .parseInt(c.get(datatype.GlobalVariable.RENT));

        }

        //            for(int i=0;i<datatype.GlobalVariable.RESIDENTS.size();i++){
        //                System.out.println(datatype.GlobalVariable.RESIDENTS.get(i).name);
        //                for(Fee f:datatype.GlobalVariable.RESIDENTS.get(i).extra_fee){
        //                    System.out.println(f.name);
        //                }
        //            }

    } catch (Exception e) {
        System.out.println(e);
    }

    //return residents;
}

From source file:com.vangent.hieos.empi.config.FunctionConfig.java

/**
 *
 * @param name//from  ww w . j a  v  a 2  s. c om
 * @param defaultValue
 * @return
 */
public double getParameterAsDouble(String name, double defaultValue) {
    String value = this.getParameter(name);
    if (value != null) {
        return Double.valueOf(value);
    }
    return defaultValue;
}