Example usage for java.lang Float valueOf

List of usage examples for java.lang Float valueOf

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static Float valueOf(float f) 

Source Link

Document

Returns a Float instance representing the specified float value.

Usage

From source file:com.ecofactor.qa.automation.consumerapi.ThermostatRuntimeSavings_Test.java

/**
 * APPS-250 Negative runtime savings thermostat.
 * @param username the username/*from w  w  w.  j av  a 2  s .  c o m*/
 * @param password the password
 * @param thermostatId the thermostat id
 */
@Test(groups = { Groups.SANITY1,
        Groups.BROWSER }, dataProvider = "negativeruntimethermostat", dataProviderClass = ApiDataProvider.class, priority = 6)
public void negativeRuntimeSavings(final String username, final String password, final String thermostatId) {

    final Response response = consumerApiURL.getThermostatRuntimeSavings(thermostatId, securityCookie);
    setLogString("Response :'" + response + "'", true);
    final String content = response.readEntity(String.class);

    setLogString(JSON_RESPONSE, true, CustomLogLevel.MEDIUM);
    setLogString(content, true, CustomLogLevel.MEDIUM);

    final JSONObject jsonObject = JsonUtil.parseObject(content);
    final JSONObject mesgs = (JSONObject) jsonObject.get(MONTHS);
    final Object[] runtimes = mesgs.values().toArray();

    setLogString("Verify negative runtime hours for given thermostat.", true);
    for (final Object runtime : runtimes) {

        final JSONObject json = (JSONObject) runtime;
        final JSONObject jsonRuntimeCool = (JSONObject) json.get(COOL);
        final JSONObject jsonRuntimeHeat = (JSONObject) json.get(HEAT);

        final float coolRuntimeHrsActual = Float.valueOf(jsonRuntimeCool.get("runtime_hours_saved").toString());
        final float heatRuntimeHrsActual = Float.valueOf(jsonRuntimeHeat.get("runtime_hours_saved").toString());

        setLogString("coolRuntimeHrsActual: " + coolRuntimeHrsActual, true);
        Assert.assertTrue(coolRuntimeHrsActual < 0, "Cool run time hours actual is not negative.");
        setLogString("heatRuntimeHrsActual: " + heatRuntimeHrsActual, true);
        Assert.assertTrue(heatRuntimeHrsActual < 0, "Heat run time hours actual is not negative.");
    }

    setLogString("Verified negative runtime hours for given thermostat.", true);
}

From source file:Highcharts.ExportController.java

private static Float scaleToFloat(String scale) {
        scale = sanitize(scale);/*from  w w  w  .j  av  a 2s.c  o m*/
        if (scale != null) {
            Float parsedScale = Float.valueOf(scale);
            if (parsedScale.compareTo(MAX_SCALE) > 0) {
                return MAX_SCALE;
            } else if (parsedScale.compareTo(0.0F) > 0) {
                return parsedScale;
            }
        }
        return null;
    }

From source file:au.org.paperminer.main.LocationFilter.java

/**
 *  Locate an existing locations by its Latitude & Longitude values.
 * //from   ww  w .  j a  v a2  s  . c o  m
 * @param req
 * @param resp
 */
private void findLatLongLocation(HttpServletRequest req, HttpServletResponse resp) {
    String lat = req.getParameter("lat");
    String lng = req.getParameter("lng");

    try {
        ArrayList<HashMap<String, String>> list = m_helper.locationsLikeLatLng(Float.valueOf(lat).floatValue(),
                Float.valueOf(lng).floatValue());
        m_logger.debug("locationFilter locn lookup: " + lat + ", " + lng + " -- List Size: " + list.size());

        resp.setContentType("text/json");
        PrintWriter pm = resp.getWriter();
        pm.write(JSONValue.toJSONString(list));
        pm.close();
    } catch (PaperMinerException ex) {
        m_logger.error("lookup failed", ex);
        req.setAttribute(PaperMinerConstants.ERROR_PAGE, "e305");
    } catch (IOException ex) {
        req.setAttribute(PaperMinerConstants.ERROR_PAGE, "e114");
    }
}

From source file:com.netsteadfast.greenstep.bsc.util.HistoryItemScoreReportContentQueryUtils.java

public static List<Map<String, Object>> getLineChartData(String itemType, String frequency, String dateVal,
        String orgId, String empId) throws ServiceException, Exception {

    List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
    Map<String, List<MonitorItemScoreVO>> itemScoreDataMap = monitorItemScoreService
            .getHistoryDataList(itemType, frequency, dateVal, orgId, empId);
    if (itemScoreDataMap == null || itemScoreDataMap.size() < 1) {
        return dataList;
    }//from   w  w w .  j a v a2s.com
    List<VisionVO> basicDataList = getBasicDataList();
    for (Map.Entry<String, List<MonitorItemScoreVO>> entry : itemScoreDataMap.entrySet()) {
        String name = "";
        String id = entry.getKey();
        List<MonitorItemScoreVO> scoreList = entry.getValue();
        if (scoreList == null || scoreList.size() < 1) {
            continue;
        }
        if (MonitorItemType.VISION.equals(itemType)) {
            DefaultResult<VisionVO> visionResult = visionService.findForSimpleByVisId(id);
            if (visionResult.getValue() == null) {
                throw new ServiceException(visionResult.getSystemMessage().getValue());
            }
            VisionVO vision = visionResult.getValue();
            name = getItemNameWithVisionGroup(MonitorItemType.VISION, vision.getVisId(), vision.getTitle(),
                    basicDataList);
        }
        if (MonitorItemType.PERSPECTIVES.equals(itemType)) {
            PerspectiveVO perspective = new PerspectiveVO();
            perspective.setPerId(id);
            DefaultResult<PerspectiveVO> perspectiveResult = perspectiveService.findByUK(perspective);
            if (perspectiveResult.getValue() == null) {
                throw new ServiceException(perspectiveResult.getSystemMessage().getValue());
            }
            perspective = perspectiveResult.getValue();
            name = getItemNameWithVisionGroup(MonitorItemType.PERSPECTIVES, perspective.getPerId(),
                    perspective.getName(), basicDataList);
        }
        if (MonitorItemType.STRATEGY_OF_OBJECTIVES.equals(itemType)) {
            ObjectiveVO objective = new ObjectiveVO();
            objective.setObjId(id);
            DefaultResult<ObjectiveVO> objectiveResult = objectiveService.findByUK(objective);
            if (objectiveResult.getValue() == null) {
                throw new ServiceException(objectiveResult.getSystemMessage().getValue());
            }
            objective = objectiveResult.getValue();
            name = getItemNameWithVisionGroup(MonitorItemType.STRATEGY_OF_OBJECTIVES, objective.getObjId(),
                    objective.getName(), basicDataList);
        }
        if (MonitorItemType.KPI.equals(itemType)) {
            KpiVO kpi = new KpiVO();
            kpi.setId(id);
            DefaultResult<KpiVO> kpiResult = kpiService.findByUK(kpi);
            if (kpiResult.getValue() == null) {
                throw new ServiceException(kpiResult.getSystemMessage().getValue());
            }
            kpi = kpiResult.getValue();
            name = getItemNameWithVisionGroup(MonitorItemType.KPI, kpi.getId(), kpi.getName(), basicDataList);
        }
        if (StringUtils.isBlank(name)) {
            throw new ServiceException("Name not found!");
        }
        Map<String, Object> chartDataMap = new HashMap<String, Object>();
        chartDataMap.put("name", name);
        chartDataMap.put("data", new LinkedList<Float>());
        for (MonitorItemScoreVO itemScore : scoreList) {
            ((List<Float>) chartDataMap.get("data")).add(Float.valueOf(itemScore.getScore()));
        }
        dataList.add(chartDataMap);
    }
    return dataList;
}

From source file:org.ow2.proactive.connector.iaas.cloud.provider.jclouds.aws.AWSEC2JCloudsProviderTest.java

@Test
public void testCreateInstanceWithSpotPrice() throws NumberFormatException, RunNodesException {

    Infrastructure infratructure = InfrastructureFixture.getInfrastructure("id-aws", "aws", "endPoint",
            "userName", "password");

    when(computeServiceCache.getComputeService(infratructure)).thenReturn(computeService);

    when(computeService.templateBuilder()).thenReturn(templateBuilder);

    Instance instance = InstanceFixture.getInstanceWithSpotPrice("instance-id", "instance-name", "image", "2",
            "512", "2", "77.154.227.148", "1.0.0.2", "running", "0.05f");

    when(templateBuilder.minRam(Integer.parseInt(instance.getHardware().getMinRam())))
            .thenReturn(templateBuilder);

    when(templateBuilder.minCores(Double.parseDouble(instance.getHardware().getMinCores())))
            .thenReturn(templateBuilder);

    when(templateBuilder.imageId(instance.getImage())).thenReturn(templateBuilder);

    when(templateBuilder.build()).thenReturn(template);

    Set nodes = Sets.newHashSet();
    NodeMetadataImpl node = mock(NodeMetadataImpl.class);
    when(node.getId()).thenReturn("RegionOne/1cde5a56-27a6-46ce-bdb7-8b01b8fe2592");
    when(node.getName()).thenReturn("someName");
    Hardware hardware = mock(Hardware.class);
    when(hardware.getProcessors()).thenReturn(Lists.newArrayList());
    when(node.getHardware()).thenReturn(hardware);
    when(hardware.getType()).thenReturn(ComputeType.HARDWARE);
    when(node.getStatus()).thenReturn(Status.RUNNING);
    nodes.add(node);/*from w  ww. j ava2 s .  c om*/
    when(computeService.listNodes()).thenReturn(nodes);

    when(computeService.createNodesInGroup(instance.getTag(), Integer.parseInt(instance.getNumber()), template))
            .thenReturn(nodes);

    TemplateOptions templateOptions = mock(TemplateOptions.class);
    when(template.getOptions()).thenReturn(templateOptions);

    when(templateOptions.runAsRoot(true)).thenReturn(templateOptions);

    when(templateOptions.as(AWSEC2TemplateOptions.class)).thenReturn(awsEC2TemplateOptions);

    // Tags
    when(tagManager.retrieveAllTags(any(Options.class))).thenReturn(Lists.newArrayList(connectorIaasTag));

    Set<Instance> created = jcloudsProvider.createInstance(infratructure, instance);

    assertThat(created.size(), is(1));

    assertThat(created.stream().findAny().get().getId(), is("RegionOne/1cde5a56-27a6-46ce-bdb7-8b01b8fe2592"));

    verify(computeService, times(1)).createNodesInGroup(instance.getTag(),
            Integer.parseInt(instance.getNumber()), template);

    verify(awsEC2TemplateOptions, times(1)).spotPrice(Float.valueOf(instance.getOptions().getSpotPrice()));

}

From source file:com.bringcommunications.etherpay.SendActivity.java

@Override
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
    EditText size_view = (EditText) findViewById(R.id.size);
    String cur_size_str = size_view.getText().toString();
    float cur_size = Float.valueOf(cur_size_str);
    eth_size = (denomination == Denomination.ETH) ? cur_size : cur_size / 1000;
    denomination = (position == 0) ? Denomination.ETH : Denomination.FINNEY;
    if (denomination == Denomination.FINNEY) {
        eth_size = (float) ((int) (eth_size * 1000 + 0.5)) / 1000;
    }/*from  w  w w .j  ava 2s  .co m*/
    boolean denomination_eth = (denomination == Denomination.ETH) ? true : false;
    SharedPreferences.Editor preferences_editor = preferences.edit();
    preferences_editor.putBoolean("denomination_eth", denomination_eth);
    System.out.println("set denomination_eth to " + denomination_eth + ", id = " + id);
    preferences_editor.apply();
    String size_str = (denomination == Denomination.ETH) ? String.format("%1.03f", eth_size)
            : String.format("%03d", (int) (eth_size * 1000 + 0.5));
    size_view.setText(size_str);
}

From source file:com.github.NearestNeighbors.java

public Map<String, Map<String, Collection<Float>>> evaluate(final Collection<Watcher> test_instances)
        throws IOException, InterruptedException, ExecutionException {
    log.info("knn-evaluate: Loading watchers.");

    log.debug(String.format("knn-evaluate: Total unique test watchers: %d", test_instances.size()));

    final Map<String, Map<String, Collection<Float>>> results = new HashMap<String, Map<String, Collection<Float>>>();

    final ExecutorService pool = Executors.newFixedThreadPool(THREAD_POOL_SIZE);

    // For each watcher in the test set . . .
    log.info("knn-evaluate: Starting evaluations");
    int test_watcher_count = 0;
    for (final Watcher watcher : test_instances) {
        test_watcher_count++;//from  w ww  . j a va2  s. co  m
        log.info(String.format("Processing watcher (%d/%d)", test_watcher_count, test_instances.size()));

        results.put(watcher.id, new HashMap<String, Collection<Float>>());

        // See if we have any training instances for the watcher.  If not, we really can't guess anything.
        final Watcher training_watcher = training_watchers.get(watcher.id);
        if (training_watcher == null) {
            continue;
        }

        /***********************************
         *** Handling repository regions ***
         ***********************************/

        // Calculate the distance between the repository regions we know the test watcher is in, to every other
        // region in the training data.
        final Set<NeighborRegion> test_regions = watchers_to_regions.get(watcher.id);

        /*
        final List<NeighborRegion> related_regions = find_regions_with_most_cutpoints(watcher, test_regions);
        for (final NeighborRegion related_region : related_regions)
        {
          storeDistance(results, watcher, related_region.most_popular, 0.0f);
          storeDistance(results, watcher, related_region.most_forked, 0.0f);
        }
        */

        /*
          also_owned_counts = {}
          training_watcher.repositories.each do |repo_id|
            repo = @training_repositories[repo_id]
                
            also_owned_counts[repo.owner] ||= 0
            also_owned_counts[repo.owner] += 1
          end
                
          also_owned_counts.each do |owner, count|
            # If 5% or more of the test watcher's repositories are owned by the same person, look at the owner's other repositories.
            if (also_owned_repos.size.to_f / training_watcher.repositories.size) > 0.05 || (also_owned_repos.size.to_f / @owners_to_repositories[owner].size) > 0.3
              repositories_to_check.merge(@owners_to_repositories[owner].collect {|r| r.id})
            end
          end
          */

        // Add in the most forked regions from similar watchers.
        /*
        final Set<NeighborRegion> related_regions = find_regions_containing_fellow_watchers(test_regions);
        for (final NeighborRegion region : related_regions)
        {
          repositories_to_check.add(region.most_forked);
        }
        */

        /*************************************
         **** Begin distance calculations ****
         *************************************/
        int test_region_count = 0;

        for (final NeighborRegion test_region : test_regions) {
            test_region_count++;

            final CompletionService<Map<Repository, Float>> cs = new ExecutorCompletionService<Map<Repository, Float>>(
                    pool);
            int training_region_count = 0;

            final Set<Repository> repositories_to_check = new HashSet<Repository>();

            // Add in the most forked repositories from each region we know the test watcher is in.
            for (final NeighborRegion region : test_regions) {
                repositories_to_check.add(region.most_forked);
            }

            for (final Repository repo : training_watcher.repositories) {
                if (repo.parent != null) {
                    repositories_to_check.add(repo.parent);
                }
            }

            /********************************************************************
             *** Handling repositories owned by owners we're already watching ***
             ********************************************************************/
            if (training_watcher.owner_counts.get(test_region.most_forked.owner) != null
                    && (((training_watcher.owner_counts.get(test_region.most_forked.owner).floatValue()
                            / owners_to_repositories.get(test_region.most_forked.owner).size()) > 0.25)
                            || (training_watcher.owner_distribution(test_region.most_forked.owner) > 0.25))) {
                for (final Repository also_owned : owners_to_repositories.get(test_region.most_forked.owner)) {
                    {
                        // Only add repos that are the most forked in their respective regions.
                        if (also_owned.region.most_forked.equals(also_owned)) {
                            repositories_to_check.add(also_owned);
                        }
                    }
                }
            }

            for (final Repository training_repository : repositories_to_check) {
                training_region_count++;

                if (log.isDebugEnabled()) {
                    log.debug(String.format("Processing watcher (%d/%d) - (%d/%d):(%d/%d)", test_watcher_count,
                            test_instances.size(), test_region_count, test_regions.size(),
                            training_region_count, repositories_to_check.size()));
                }

                // Submit distance calculation task if the test watcher isn't already watching the repository.
                cs.submit(new Callable<Map<Repository, Float>>() {

                    public Map<Repository, Float> call() throws Exception {
                        final Map<Repository, Float> ret = new HashMap<Repository, Float>();

                        if (!training_repository.watchers.contains(training_watcher)) {
                            float distance = euclidian_distance(training_watcher, test_region.most_forked,
                                    training_repository);

                            ret.put(training_repository, Float.valueOf(distance));
                        }

                        return ret;
                    }

                });
            }

            // Process the distance calculation results.
            for (int i = 0; i < repositories_to_check.size(); i++) {
                final Map<Repository, Float> distance = cs.take().get();

                for (final Map.Entry<Repository, Float> pair : distance.entrySet()) {
                    storeDistance(results, watcher, pair.getKey(), pair.getValue().floatValue());
                }
            }
        }
    }

    /*
            
            
    =begin
      # Find a set of repositories from fellow watchers that happen to watch a lot of same repositories as the test watcher.
      repositories_to_check.merge find_repositories_containing_fellow_watchers(test_regions)
            
      # Add in the most popular and most forked regions we know the test watcher is in.
      related_regions = find_regions_containing_fellow_watchers(test_regions)
      related_regions.each do |region|
        repositories_to_check << region.most_popular.id
        repositories_to_check << region.most_forked.id
      end
            
      $LOG.info "Added regions from fellow watchers for watcher #{watcher.id} -- new size #{repositories_to_check.size} (+ #{repositories_to_check.size - old_size})"
      old_size = repositories_to_check.size
            
      $LOG.info "Added similarly owned for watcher #{watcher.id} -- new size #{repositories_to_check.size} (+ #{repositories_to_check.size - old_size})"
      old_size = repositories_to_check.size
    =end
            
            
            
            
    =begin
            
    end
            
    results
     */

    return results;
}

From source file:io.agi.framework.persistence.DataJsonSerializer.java

private static void decodeValue(String encoding, FloatArray fa, String value, String valueBefore,
        int numberIdx) {
    if ((encoding != null) && (encoding.equals(ENCODING_SPARSE_BINARY))) {
        int intValue = Integer.valueOf(value);
        fa._values[intValue] = 1.f;/*from  w  w w.j a  va  2 s.com*/
    } else if ((encoding != null) && (encoding.equals(ENCODING_SPARSE_REAL))) {
        if ((numberIdx & 1) == 0) {
            // even: 0, 2 etc: do nothing
        } else {
            // odd: 1, 3, 5 etc
            Integer elementIndex = Integer.valueOf(valueBefore);
            Float elementValue = Float.valueOf(value);
            fa._values[elementIndex] = elementValue;
        }
    } else { // default encoding
        Float elementValue = Float.valueOf(value);
        fa._values[numberIdx] = elementValue;
    }
}

From source file:name.setup.dance.StepService.java

public void reloadSettings() {
    mSettings = PreferenceManager.getDefaultSharedPreferences(this);

    if (mStepDetector != null) {
        mStepDetector.setSensitivity(Float.valueOf(mSettings.getString("sensitivity", "10")));
    }//from   w w w  .  j a v  a2s . com

    if (mStepDisplayer != null)
        mStepDisplayer.reloadSettings();
    if (mPaceNotifier != null)
        mPaceNotifier.reloadSettings();
    if (mDistanceNotifier != null)
        mDistanceNotifier.reloadSettings();
    if (mSpeedNotifier != null)
        mSpeedNotifier.reloadSettings();
    if (mCaloriesNotifier != null)
        mCaloriesNotifier.reloadSettings();
    if (mSpeakingTimer != null)
        mSpeakingTimer.reloadSettings();

}

From source file:com.netsteadfast.greenstep.bsc.util.AggregationMethod.java

public void countDateRange(KpiVO kpi, String frequency) throws Exception {
    BscReportSupportUtils.loadExpression();
    for (DateRangeScoreVO dateScore : kpi.getDateRangeScores()) {
        float score = 0.0f;
        int size = 0;
        for (BbMeasureData measureData : kpi.getMeasureDatas()) {
            String date = dateScore.getDate().replaceAll("/", "");
            if (!this.isDateRange(date, frequency, measureData)) {
                continue;
            }/*from  w  w w  . j  ava  2s  .  c  o m*/
            size++;
        }
        score = Float.valueOf(size);
        dateScore.setScore(score);
        dateScore.setFontColor(BscScoreColorUtils.getFontColor(score));
        dateScore.setBgColor(BscScoreColorUtils.getBackgroundColor(score));
        dateScore.setImgIcon(BscReportSupportUtils.getHtmlIcon(kpi, score));
    }
}