Example usage for java.lang Float toString

List of usage examples for java.lang Float toString

Introduction

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

Prototype

public static String toString(float f) 

Source Link

Document

Returns a string representation of the float argument.

Usage

From source file:com.variable.demo.api.fragment.MotionFragment.java

@Override
public void onAccelerometerUpdate(MotionSensor sensor, MotionReading reading) {
    DateFormat formatter = new SimpleDateFormat("MM-dd-yyyy hh:mm.ss");

    // Log.d(TAG, "TimeStamp Source: " + reading.getTimeStampSource());
    // Log.d(TAG," Time:" + formatter.format(reading.getTimeStamp()));

    Message m = mHandler.obtainMessage(MessageConstants.MESSAGE_ACCELEROMETER_READING);
    Bundle b = m.getData();//ww w.ja v  a  2 s . c  o  m
    b.putFloat(MessageConstants.X_VALUE_KEY, (reading.getX() + 16) * DECIMAL_PRECISION);
    b.putFloat(MessageConstants.Y_VALUE_KEY, (reading.getY() + 16) * DECIMAL_PRECISION);
    b.putFloat(MessageConstants.Z_VALUE_KEY, (reading.getZ() + 16) * DECIMAL_PRECISION);

    //For this demo we are streaming all time stamp from the node device.
    b.putLong(MessageConstants.TIME_STAMP, reading.getTimeStamp().getTime());
    b.putInt(MessageConstants.TIME_SOURCE, reading.getTimeStampSource());

    final Context thiscontext = this.getActivity();
    final String serialnumOne = sensor.getSerialNumber();
    final String serialnum = serialnumOne.replaceAll("[^\\u0000-\\uFFFF]", "");
    final String scanX = Float.toString((reading.getX() + 16) * DECIMAL_PRECISION);
    final String scanY = Float.toString((reading.getY() + 16) * DECIMAL_PRECISION);
    final String scanZ = Float.toString((reading.getZ() + 16) * DECIMAL_PRECISION);
    String json = "accelerometer;" + serialnum + ";" + scanX + "," + scanY + "," + scanZ;

    // POST to variable dashboard
    Ion.getDefault(thiscontext).getConscryptMiddleware().enable(false);
    Ion.with(thiscontext).load(
            "https://datadipity.com/clickslide/fleetplusdata.json?PHPSESSID=gae519f8k5humje0jqb195nob6&update&postparam[payload]="
                    + json)
            .setLogging("MyLogs", Log.DEBUG).asString().withResponse()
            .setCallback(new FutureCallback<Response<String>>() {
                @Override
                public void onCompleted(Exception e, Response<String> result) {
                    if (e == null) {
                        Log.i(TAG, "ION SENT MESSAGE WITH RESULT CODE: " + result.toString());
                    } else {
                        Log.i(TAG, "ION SENT MESSAGE WITH EXCEPTION");
                        e.printStackTrace();
                    }
                }
            });

    m.sendToTarget();
}

From source file:com.prey.actions.location.LocationUtil.java

public static HttpDataService convertData(PreyLocation lastLocation) {
    if (lastLocation == null)
        return null;
    HttpDataService data = new HttpDataService("location");
    data.setList(true);// w w w.  jav a  2  s .co m
    HashMap<String, String> parametersMap = new HashMap<String, String>();
    parametersMap.put(LAT, Double.toString(lastLocation.getLat()));
    parametersMap.put(LNG, Double.toString(lastLocation.getLng()));
    parametersMap.put(ACC, Float.toString(lastLocation.getAccuracy()));
    parametersMap.put(METHOD, lastLocation.getMethod());
    data.addDataListAll(parametersMap);
    return data;
}

From source file:com.linkedin.pinot.core.predicate.NoDictionaryInPredicateEvaluatorTest.java

@Test
public void testFloatPredicateEvaluators() {
    String[] stringValues = new String[NUM_PREDICATE_VALUES];
    FloatSet valueSet = new FloatOpenHashSet();

    for (int i = 0; i < 100; i++) {
        float value = _random.nextFloat();
        stringValues[i] = Float.toString(value);
        valueSet.add(value);/*from  w ww.j av a 2 s .  co  m*/
    }

    InPredicate inPredicate = new InPredicate(COLUMN_NAME,
            Collections.singletonList(StringUtil.join(InPredicate.DELIMITER, stringValues)));
    PredicateEvaluator inPredicateEvaluator = InPredicateEvaluatorFactory
            .newNoDictionaryBasedEvaluator(inPredicate, FieldSpec.DataType.FLOAT);

    NotInPredicate notInPredicate = new NotInPredicate(COLUMN_NAME,
            Collections.singletonList(StringUtil.join(InPredicate.DELIMITER, stringValues)));
    PredicateEvaluator notInPredicateEvaluator = NotInPredicateEvaluatorFactory
            .newNoDictionaryBasedEvaluator(notInPredicate, FieldSpec.DataType.FLOAT);

    for (float value : valueSet) {
        Assert.assertTrue(inPredicateEvaluator.apply(value));
        Assert.assertFalse(notInPredicateEvaluator.apply(value));
    }

    for (int i = 0; i < 100; i++) {
        float value = _random.nextFloat();
        Assert.assertEquals(inPredicateEvaluator.apply(value), valueSet.contains(value));
        Assert.assertEquals(notInPredicateEvaluator.apply(value), !valueSet.contains(value));
    }

    float[] multiValues = new float[NUM_MULTI_VALUES];
    PredicateEvaluatorTestUtils.fillRandom(multiValues);
    multiValues[_random.nextInt(multiValues.length)] = Float
            .parseFloat(stringValues[_random.nextInt(stringValues.length)]);

    Assert.assertTrue(inPredicateEvaluator.apply(multiValues));
    Assert.assertFalse(notInPredicateEvaluator.apply(multiValues));
}

From source file:com.koda.integ.hbase.test.BlockStoragePersistenceTest.java

public void testCacheLoad() {
    CacheManager.getInstance().clearCaches();

    Configuration conf = TEST_UTIL.getConfiguration();
    conf.set(OffHeapBlockCache.BLOCK_CACHE_MEMORY_SIZE, Long.toString(cacheSize));
    conf.set(OffHeapBlockCache.BLOCK_CACHE_IMPL, cacheImplClass);
    conf.set(OffHeapBlockCache.BLOCK_CACHE_YOUNG_GEN_FACTOR, Float.toString(youngGenFactor));
    conf.set(OffHeapBlockCache.BLOCK_CACHE_COMPRESSION, cacheCompression);
    conf.set("io.storefile.bloom.block.size", Integer.toString(BLOOM_BLOCK_SIZE));
    conf.set("hfile.block.cache.size", "0.5");

    // Enable File Storage
    conf.set(FileExtStorage.FILE_STORAGE_FILE_SIZE_LIMIT, Integer.toString((int) fileSizeLimit));
    conf.set(FileExtStorage.FILE_STORAGE_MAX_SIZE, Long.toString(fileStoreSize));
    conf.set(OffHeapBlockCache.BLOCK_CACHE_OVERFLOW_TO_EXT_STORAGE_ENABLED, Boolean.toString(true));
    conf.set(OffHeapBlockCache.BLOCK_CACHE_EXT_STORAGE_IMPL, FileExtStorage.class.getName());
    conf.set(FileExtStorage.FILE_STORAGE_BASE_DIR, dataDir);
    conf.set(OffHeapBlockCache.BLOCK_CACHE_TEST_MODE, Boolean.toString(true));
    conf.set(OffHeapBlockCache.BLOCK_CACHE_EXT_STORAGE_MEMORY_SIZE, Long.toString(extRefCacheSize));

    // Enable persistence
    conf.set(OffHeapBlockCache.BLOCK_CACHE_DATA_ROOTS, cacheDataDir);
    conf.set(OffHeapBlockCache.BLOCK_CACHE_PERSISTENT, Boolean.toString(true));

    LOG.info("Loading new cache ...");
    long startTime = System.currentTimeMillis();
    OffHeapBlockCache newCache = new OffHeapBlockCache(conf);
    LOG.info("Loading new cache done in " + (System.currentTimeMillis() - startTime) + "ms");

    assertEquals(blockCacheSize, newCache.getExtStorageCache().size());

}

From source file:blue.components.lines.Line.java

public Element saveAsXML() {
    Element retVal = null;//from  w  ww.  ja va  2  s  .  c  o  m

    if (isZak) {
        retVal = new Element("zakline");
        retVal.setAttribute("channel", Integer.toString(this.channel));
    } else {
        retVal = new Element("line");
        retVal.setAttribute("name", this.varName);
    }
    retVal.setAttribute("version", "2");
    retVal.setAttribute("max", Float.toString(max));
    retVal.setAttribute("min", Float.toString(min));
    retVal.setAttribute("resolution", Float.toString(resolution));
    retVal.setAttribute("color", Integer.toString(color.getRGB()));
    retVal.setAttribute("rightBound", Boolean.toString(rightBound));
    retVal.setAttribute("endPointsLinked", Boolean.toString(endPointsLinked));

    for (LinePoint point : points) {
        retVal.addElement(point.saveAsXML());
    }

    return retVal;
}

From source file:ly.apps.android.rest.client.example.activities.MainActivity.java

private void setInfo(Response<ForecastResponse> response) {

    WeatherResponse weatherResponse;//from   w  w w  .  j  a v a 2s  .c  om
    MainResponse mainResponse;

    if (!response.getResult().getWeather().isEmpty()) {
        weatherResponse = response.getResult().getWeather().get(0);
        mainResponse = response.getResult().getMain();

        textViewDescription.setText(capitalize(weatherResponse.getDescription()));
        imageViewIcon.setImageResource(icons.get(weatherResponse.getIcon()));
        textViewTemp.setText(String.format("%d", kelvinToFahrenheitRounded(mainResponse.getTemp())));
        textViewWind.setText(String.format("%s %s", Float.toString(response.getResult().getWind().getSpeed()),
                getString(R.string.wind_speed)));
        textViewHumidity.setText(String.format("%d%%", mainResponse.getHumidity()));
        textViewTempMax.setText(String.format("%d", kelvinToFahrenheitRounded(mainResponse.getTemp_max())));
        textViewTempMin.setText(String.format("%d", kelvinToFahrenheitRounded(mainResponse.getTemp_min())));
        textViewCity.setText(response.getResult().getName());

        contentProgressBar.setVisibility(View.GONE);
        linearLayoutContent.setVisibility(View.VISIBLE);

        animateContent();
    } else {
        failMessage();
    }

}

From source file:com.cloudera.oryx.als.computation.LoadRunner.java

public void runLoad() throws InterruptedException {

    final StorelessUnivariateStatistic recommendedBecause = new Mean();
    final StorelessUnivariateStatistic setPreference = new Mean();
    final StorelessUnivariateStatistic removePreference = new Mean();
    final StorelessUnivariateStatistic ingest = new Mean();
    final StorelessUnivariateStatistic refresh = new Mean();
    final StorelessUnivariateStatistic estimatePreference = new Mean();
    final StorelessUnivariateStatistic mostSimilarItems = new Mean();
    final StorelessUnivariateStatistic similarityToItem = new Mean();
    final StorelessUnivariateStatistic mostPopularItems = new Mean();
    final StorelessUnivariateStatistic recommendToMany = new Mean();
    final StorelessUnivariateStatistic recommend = new Mean();
    final RandomGenerator random = RandomManager.getRandom();

    int numCores = Runtime.getRuntime().availableProcessors();
    final int stepsPerWorker = steps / numCores;
    Collection<Callable<Object>> workers = Lists.newArrayListWithCapacity(numCores);
    for (int i = 0; i < numCores; i++) {
        workers.add(new Callable<Object>() {
            @Override/*ww  w.  j  a  va  2 s  . c  o  m*/
            public Void call() throws Exception {
                for (int i = 0; i < stepsPerWorker; i++) {
                    double r;
                    String userID;
                    String itemID;
                    String itemID2;
                    float value;
                    synchronized (random) {
                        r = random.nextDouble();
                        userID = uniqueUserIDs[random.nextInt(uniqueUserIDs.length)];
                        itemID = uniqueItemIDs[random.nextInt(uniqueItemIDs.length)];
                        itemID2 = uniqueItemIDs[random.nextInt(uniqueItemIDs.length)];
                        value = random.nextInt(10);
                    }
                    long stepStart = System.currentTimeMillis();
                    if (r < 0.05) {
                        client.recommendedBecause(userID, itemID, 10);
                        recommendedBecause.increment(System.currentTimeMillis() - stepStart);
                    } else if (r < 0.07) {
                        client.setPreference(userID, itemID);
                        setPreference.increment(System.currentTimeMillis() - stepStart);
                    } else if (r < 0.08) {
                        client.setPreference(userID, itemID, value);
                        setPreference.increment(System.currentTimeMillis() - stepStart);
                    } else if (r < 0.11) {
                        client.removePreference(userID, itemID);
                        removePreference.increment(System.currentTimeMillis() - stepStart);
                    } else if (r < 0.12) {
                        Reader reader = new StringReader(
                                DelimitedDataUtils.encode(userID, itemID, Float.toString(value)) + '\n');
                        client.ingest(reader);
                        ingest.increment(System.currentTimeMillis() - stepStart);
                    } else if (r < 0.13) {
                        client.refresh();
                        refresh.increment(System.currentTimeMillis() - stepStart);
                    } else if (r < 0.14) {
                        client.similarityToItem(itemID, itemID2);
                        similarityToItem.increment(System.currentTimeMillis() - stepStart);
                    } else if (r < 0.15) {
                        client.mostPopularItems(10);
                        mostPopularItems.increment(System.currentTimeMillis() - stepStart);
                    } else if (r < 0.19) {
                        client.estimatePreference(userID, itemID);
                        estimatePreference.increment(System.currentTimeMillis() - stepStart);
                    } else if (r < 0.20) {
                        client.estimateForAnonymous(itemID, new String[] { itemID2 });
                        estimatePreference.increment(System.currentTimeMillis() - stepStart);
                    } else if (r < 0.25) {
                        client.mostSimilarItems(new String[] { itemID }, 10);
                        mostSimilarItems.increment(System.currentTimeMillis() - stepStart);
                    } else if (r < 0.30) {
                        client.recommendToMany(new String[] { userID, userID }, 10, true, null);
                        recommendToMany.increment(System.currentTimeMillis() - stepStart);
                    } else {
                        client.recommend(userID, 10);
                        recommend.increment(System.currentTimeMillis() - stepStart);
                    }
                }
                return null;
            }
        });
    }

    log.info("Starting load test...");

    long start = System.currentTimeMillis();
    ExecutorService executor = Executors.newFixedThreadPool(numCores);
    Iterable<Future<Object>> futures;
    try {
        futures = executor.invokeAll(workers);
    } finally {
        ExecutorUtils.shutdownNowAndAwait(executor);
    }
    long end = System.currentTimeMillis();

    ExecutorUtils.checkExceptions(futures);

    log.info("Finished {} steps in {}ms", steps, end - start);

    log.info("recommendedBecause: {}", recommendedBecause.getResult());
    log.info("setPreference: {}", setPreference.getResult());
    log.info("removePreference: {}", removePreference.getResult());
    log.info("ingest: {}", ingest.getResult());
    log.info("refresh: {}", refresh.getResult());
    log.info("estimatePreference: {}", estimatePreference.getResult());
    log.info("mostSimilarItems: {}", mostSimilarItems.getResult());
    log.info("similarityToItem: {}", similarityToItem.getResult());
    log.info("mostPopularItems: {}", mostPopularItems.getResult());
    log.info("recommendToMany: {}", recommendToMany.getResult());
    log.info("recommend: {}", recommend.getResult());
}

From source file:edgeserver.Publicador.java

private void publicaDado(Sensor sensor) throws Exception {
    // make sure cookies is turn on
    CookieHandler.setDefault(new CookieManager());

    HTTPClient http = new HTTPClient();

    List<NameValuePair> postp = new ArrayList<>();
    postp.add(new BasicNameValuePair("login", "huberto"));
    postp.add(new BasicNameValuePair("password", "99766330"));

    http.sendPost(this.urlLogin, postp);

    sensor.updateDado();/* w  w w .  j ava  2s .  co  m*/

    List<NameValuePair> GatewayParams = new ArrayList<>();
    GatewayParams
            .add(new BasicNameValuePair("publicacao_servidorborda", Integer.toString(this.ServidorBordaID)));
    GatewayParams.add(new BasicNameValuePair("publicacao_sensor", Integer.toString(sensor.getId())));
    GatewayParams.add(new BasicNameValuePair("publicacao_datacoleta",
            new Timestamp(this.datapublicacao.getTime()).toString()));
    GatewayParams.add(new BasicNameValuePair("publicacao_datapublicacao",
            new Timestamp(this.datapublicacao.getTime()).toString()));
    GatewayParams.add(new BasicNameValuePair("publicacao_valorcoletado", Float.toString(sensor.getDado())));

    String result = http.GetPageContent(this.urlInsertDado, GatewayParams);
}

From source file:org.mrgeo.cmd.MrGeo.java

/**
 * {@inheritDoc}/*from w  w w .  j ava2  s .  c  o m*/
 *
 * @see org.apache.hadoop.util.Tool#run(String[])
 */
@Override
public int run(String[] args) throws IOException {
    if (commands == null) {
        loadCommands();
    }

    if (args.length == 0) {
        usage();
        return -1;
    }

    Options options = createOptions();

    CommandLine line;
    try {
        CommandLineParser parser = new ExtendedGnuParser(true);
        line = parser.parse(options, args);
    } catch (ParseException e) {
        usage();
        return -1;
    }

    if (line == null) {
        usage();
        return 0;
    } else {
        if (line.hasOption("d")) {
            LoggingUtils.setDefaultLogLevel(LoggingUtils.DEBUG);
        } else if (line.hasOption("v")) {
            LoggingUtils.setDefaultLogLevel(LoggingUtils.INFO);
        } else {
            LoggingUtils.setDefaultLogLevel(LoggingUtils.WARN);
            HadoopUtils.adjustLogging();
        }
    }

    if (line.hasOption("l")) {
        System.out.println("Using local runner");
        HadoopUtils.setupLocalRunner(getConf());
    }

    if (line.hasOption("mm")) {
        float mult = Float.parseFloat(line.getOptionValue("mm"));
        MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_FORCE_MEMORYINTENSIVE, "true");
        MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_MEMORYINTENSIVE_MULTIPLIER,
                Float.toString(mult));
    }

    if (line.hasOption("mem")) {
        MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_MAX_PROCESSING_MEM,
                line.getOptionValue("mem"));
    }

    if (line.hasOption("sf")) {
        MrGeoProperties.getInstance().setProperty(MrGeoConstants.MRGEO_SHUFFLE_FRACTION,
                line.getOptionValue("sf"));
    }

    String cmdStr = args[0];

    if (!commands.containsKey(cmdStr)) {
        int ret = 0;
        if (!line.hasOption("h")) {
            System.out.println("Command not found: " + cmdStr);
            System.out.println();
            ret = -1;
        }

        usage();
        return ret;
    }

    CommandSpi spi = commands.get(cmdStr);
    try {
        Command cmd = spi.getCommandClass().newInstance();

        // strip the 1st argument (the command name) and pass the rest to the command
        ProviderProperties providerProperties = new ProviderProperties();
        return cmd.run(Arrays.copyOfRange(args, 1, args.length), getConf(), providerProperties);
    } catch (Exception e) {
        return -1;
    }

}

From source file:blue.soundObject.Note.java

public void setStartTime(float yo) {
    fields[1] = Float.toString(yo);
}