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.chinamobile.bcbsp.examples.kmeans.KMeansBSP.java

@Override
public void initBeforeSuperStep(SuperStepContextInterface context) {
    this.superStepCount = context.getCurrentSuperStepCounter();
    jobconf = context.getJobConf();// ww w . ja  v  a2  s.com
    if (superStepCount == 0) {
        this.k = Integer.valueOf(jobconf.get(KMeansBSP.KMEANS_K));
        // Init the k original centers from job conf.
        String originalCenters = jobconf.get(KMeansBSP.KMEANS_CENTERS);
        String[] centers = originalCenters.split("\\|");
        for (int i = 0; i < centers.length; i++) {
            ArrayList<Float> center = new ArrayList<Float>();
            String[] values = centers[i].split("-");
            for (int j = 0; j < values.length; j++) {
                center.add(Float.valueOf(values[j]));
            }
            kCenters.add(center);
        }
        this.dimension = kCenters.get(0).size();
        LOG.info("[KMeansBSP] K = " + k);
        LOG.info("[KMeansBSP] dimension = " + dimension);
        LOG.info("[KMeansBSP] k centers: ");
        for (int i = 0; i < k; i++) {
            String tmpCenter = "";
            for (int j = 0; j < dimension; j++) {
                tmpCenter = tmpCenter + " " + kCenters.get(i).get(j);
            }
            LOG.info("[KMeansBSP] <" + tmpCenter + " >");
        }
    } else {
        KCentersAggregateValue kCentersAgg = (KCentersAggregateValue) context
                .getAggregateValue(KMeansBSP.AGGREGATE_KCENTERS);
        ArrayList<ArrayList<Float>> newKCenters = new ArrayList<ArrayList<Float>>();
        // Calculate the new k centers and save them to newKCenters.
        ArrayList<ArrayList<Float>> contents = kCentersAgg.getValue();
        ArrayList<Float> nums = contents.get(k);
        for (int i = 0; i < k; i++) {
            ArrayList<Float> center = new ArrayList<Float>();
            // Get the sum of coordinates of points in class i.
            ArrayList<Float> sum = contents.get(i);
            // Get the number of points in class i.
            float num = nums.get(i);
            for (int j = 0; j < dimension; j++) {
                // the center's coordinate value.
                center.add(sum.get(j) / num);
            }
            // The i center.
            newKCenters.add(center);
        }
        this.errors = 0.0;
        // Calculate the errors sum between the new k centers and the last k
        // centers.
        for (int i = 0; i < k; i++) {
            for (int j = 0; j < dimension; j++) {
                this.errors = this.errors + Math.abs(kCenters.get(i).get(j) - newKCenters.get(i).get(j));
            }
        }
        this.errors = this.errors / (k * dimension);
        this.kCenters.clear();
        this.kCenters = newKCenters;
        LOG.info("[KMeansBSP] k centers: ");
        for (int i = 0; i < k; i++) {
            String tmpCenter = "[" + nums.get(i) + "]";
            for (int j = 0; j < dimension; j++) {
                tmpCenter = tmpCenter + " " + kCenters.get(i).get(j);
            }
            LOG.info("[KMeansBSP] <" + tmpCenter + " >");
        }
    }
    LOG.info("[KMeansBSP]******* Error = " + errors + " ********");
}

From source file:com.neophob.sematrix.core.jmx.PixelControllerStatus.java

@Override
public long getRecordedMilliSeconds() {
    return Float.valueOf(((this.configuredFps * SECONDS) / this.currentFps) * 1000).longValue();
}

From source file:business.security.control.OwmClient.java

/**
 * Find current weather around a city coordinates
 *
 * @param lat is the latitude of the geographic point of interest
 * (North/South coordinate)//from  w ww.  j a  v  a 2 s .com
 * @param lon is the longitude of the geographic point of interest
 * (East/West coordinate)
 * @param cnt is the requested number of weather stations to retrieve (the
 * actual answer might be less than the requested).
 * @throws JSONException if the response from the OWM server can't be parsed
 * @throws IOException if there's some network error or the OWM server
 * replies with a error.
 */
public WeatherStatusResponse currentWeatherAtCity(float lat, float lon, int cnt)
        throws IOException, JSONException { //, boolean cluster, OwmClient.Lang lang) {
    String subUrl = String.format(Locale.ROOT, "find/city?lat=%f&lon=%f&cnt=%d&cluster=yes", Float.valueOf(lat),
            Float.valueOf(lon), Integer.valueOf(cnt));
    JSONObject response = doQuery(subUrl);
    return new WeatherStatusResponse(response);
}

From source file:br.edu.ufcg.supervisor.SupervisorInterface.java

/**
 * Executes the model with some data and extracts recommendations.
 * @param args Passed from Javascript interface.
 * @param callbackContext Used to return the result of processing.
 * @throws JSONException/*  w w  w . ja v  a 2 s  .  c o m*/
 */
private void executeModel(JSONArray args, CallbackContext callbackContext) throws JSONException {
    JSONObject r = new JSONObject();
    String name = args.get(0).toString();
    Float value = Float.valueOf((String) args.get(1));
    map.put(name, value);
    map2.put(Integer.valueOf((String) args.get(2)), value);
    String recommendation = "";
    String currentState = "";
    try {
        Simulation.executeModel(r, model, map, map2, currentState, recommendation, logString);
    } catch (Exception e) {
        recommendation = "Value not monitored.";
        logString = logString + "(" + recommendation + ")\n";
        r.put("error", recommendation);
        r.put("rec", "Stop and verify your devices. If this appears again, call your healthcare professional.");
        callbackContext.error(r);
    }
    callbackContext.success(r);
}

From source file:org.kurento.demo.CrowdDetectorOrionPublisher.java

private static OrionContextElement directionEventToContextElement(String roiId) {
    OrionContextElement contextElement = new OrionContextElement();

    contextElement.setId(roiId);/* www .j  a va 2  s . c  o  m*/
    contextElement.setPattern(false);
    contextElement.setType(CrowdDetectorDirectionEvent.class.getSimpleName());

    OrionAttribute<Float> directionAttribute = new OrionAttribute<>(DIRECTION_ATTR, Float.class.getSimpleName(),
            Float.valueOf(0));

    contextElement.getAttributes().add(directionAttribute);
    return contextElement;
}

From source file:cn.ctyun.amazonaws.util.XpathUtils.java

/**
 * Evaluates the specified XPath expression and returns the result as a
 * Float./*w  w w .  j  av a  2  s . c  o  m*/
 *
 * @param expression
 *            The XPath expression to evaluate.
 * @param node
 *            The node to run the expression on.
 *
 * @return The Float result.
 *
 * @throws XPathExpressionException
 *             If there was a problem processing the specified XPath
 *             expression.
 */
public static Float asFloat(String expression, Node node) throws XPathExpressionException {
    String floatString = evaluateAsString(expression, node);
    return (isEmptyString(floatString)) ? null : Float.valueOf(floatString);
}

From source file:com.amitshekhar.utils.PrefHelper.java

public static UpdateRowResponse updateRow(Context context, String tableName,
        List<RowDataRequest> rowDataRequests) {
    UpdateRowResponse updateRowResponse = new UpdateRowResponse();

    if (tableName == null) {
        return updateRowResponse;
    }/*from   ww  w  .ja v a  2s. c om*/

    RowDataRequest rowDataKey = rowDataRequests.get(0);
    RowDataRequest rowDataValue = rowDataRequests.get(1);

    String key = rowDataKey.value;
    String value = rowDataValue.value;
    String dataType = rowDataValue.dataType;

    if (Constants.NULL.equals(value)) {
        value = null;
    }

    SharedPreferences preferences = context.getSharedPreferences(tableName, Context.MODE_PRIVATE);

    try {
        switch (dataType) {
        case DataType.TEXT:
            preferences.edit().putString(key, value).apply();
            updateRowResponse.isSuccessful = true;
            break;
        case DataType.INTEGER:
            preferences.edit().putInt(key, Integer.valueOf(value)).apply();
            updateRowResponse.isSuccessful = true;
            break;
        case DataType.LONG:
            preferences.edit().putLong(key, Long.valueOf(value)).apply();
            updateRowResponse.isSuccessful = true;
            break;
        case DataType.FLOAT:
            preferences.edit().putFloat(key, Float.valueOf(value)).apply();
            updateRowResponse.isSuccessful = true;
            break;
        case DataType.BOOLEAN:
            preferences.edit().putBoolean(key, Boolean.valueOf(value)).apply();
            updateRowResponse.isSuccessful = true;
            break;
        case DataType.STRING_SET:
            JSONArray jsonArray = new JSONArray(value);
            Set<String> stringSet = new HashSet<>();
            for (int i = 0; i < jsonArray.length(); i++) {
                stringSet.add(jsonArray.getString(i));
            }
            preferences.edit().putStringSet(key, stringSet).apply();
            updateRowResponse.isSuccessful = true;
            break;
        default:
            preferences.edit().putString(key, value).apply();
            updateRowResponse.isSuccessful = true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return updateRowResponse;
}

From source file:com.github.rvesse.airline.restrictions.factories.RangeRestrictionFactory.java

protected RangeRestriction createFloatRange(Annotation annotation) {
    FloatRange sRange = (FloatRange) annotation;
    return new RangeRestriction(
            sRange.min() != Float.MIN_VALUE || !sRange.minInclusive() ? Float.valueOf(sRange.min()) : null,
            sRange.minInclusive(),//from w w w.ja  v a  2  s.  c  o  m
            sRange.max() != Float.MAX_VALUE || !sRange.maxInclusive() ? Float.valueOf(sRange.max()) : null,
            sRange.maxInclusive(), FLOAT_COMPARATOR);
}

From source file:com.googlecode.jmxtrans.model.output.StatsDTelegrafWriter.java

private Number computeActualValue(Object value) {
    Object transformedValue = valueTransformer.apply(value);
    if (isNumeric(transformedValue)) {
        return transformedValue instanceof Number ? (Number) transformedValue
                : Float.valueOf(transformedValue.toString());
    }//from  ww w . ja  v a  2  s  .co  m
    throw new IllegalArgumentException(
            "Only numeric values are supported, enable debug log level for more details.");
}

From source file:strat.mining.multipool.stats.builder.CoinshiftStatsBuilder.java

private void updateGlobalStats() {
    try {/*from   w  w  w  .  ja va 2s  .  c o m*/
        USE_LOGGER.debug("Updating coinshift GlobalStats...");

        long start = System.currentTimeMillis();

        strat.mining.multipool.stats.jersey.model.coinshift.GlobalStats rawGlobalStats = coinshiftRestClient
                .getGlobalStats();

        Date refreshDate = new Date();
        GlobalStats globalStats = new GlobalStats();
        globalStats.setMegaHashesPerSeconds(Float.valueOf(rawGlobalStats.getHashrate()));
        globalStats.setRejectedMegaHashesPerSeconds(Float.valueOf(rawGlobalStats.getRejectrate()));

        if (MapUtils.isNotEmpty(rawGlobalStats.getCoins())) {
            for (Entry<String, Coin> entry : rawGlobalStats.getCoins().entrySet()) {
                if ("BTC".equalsIgnoreCase(entry.getKey())) {
                    globalStats.setTotalBalance(Float.valueOf(entry.getValue().getExchanged_balance()));
                    globalStats.setTotalUnexchanged(
                            Float.valueOf(entry.getValue().getEstimated_unexchanged_balance()));
                    break;
                }
            }
        }

        globalStats.setRefreshTime(refreshDate);
        if (globalStats != null) {
            globalStatsDao.insertGlobalStats(globalStats);
            PERF_LOGGER.info("Coinshift globalStats updated in {} ms.", System.currentTimeMillis() - start);
        }
    } catch (Exception e) {
        LOGGER.error("Error during global stats update.", e);
    }
}