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.google.sampling.experiential.server.MapServiceImpl.java

/**
 * @param experimentId//from www.  j a  v  a2 s .com
 * @param justUser 
 * @return
 */
private void getDailyResponseRateFor(Long experimentId, ExperimentStatsDAO accum, boolean justUser) {
    Map<DateMidnight, DateStat> dateStatsMap = Maps.newHashMap();
    Map<DateMidnight, Set<String>> sevenDayMap = Maps.newHashMap();

    int missedSignals = 0;
    long totalMillisToRespond = 0;
    String queryString = "";
    if (justUser) {
        queryString = "who=" + getWho() + ":";
    }
    List<EventDAO> events = getEventsForQuery(queryString + "experimentId=" + experimentId);
    for (EventDAO event : events) {
        if (event.isJoinEvent()) {
            continue;
        }
        if (event.isMissedSignal()) {
            missedSignals++;
            continue;
        }
        totalMillisToRespond += event.responseTime();
        Date date = event.getResponseTime();
        if (date == null) {
            date = event.getWhen();
        }
        DateMidnight dateMidnight = new DateMidnight(date);

        // Daily response count
        DateStat currentStat = dateStatsMap.get(dateMidnight);
        if (currentStat == null) {
            currentStat = new DateStat(dateMidnight.toDate());
            currentStat.addValue(new Double(1));
            dateStatsMap.put(dateMidnight, currentStat);
        } else {
            List<Double> values = currentStat.getValues();
            values.set(0, values.get(0) + 1);
        }

        // 7 day counts
        DateMidnight beginningOfWeekDateMidnight = getBeginningOfWeek(dateMidnight);
        Set<String> current7Day = sevenDayMap.get(beginningOfWeekDateMidnight);
        if (current7Day == null) {
            current7Day = Sets.newHashSet();
            sevenDayMap.put(beginningOfWeekDateMidnight, current7Day);
        }
        current7Day.add(event.getWho());
    }
    // daily response
    ArrayList<DateStat> dateStats = Lists.newArrayList(dateStatsMap.values());
    Collections.sort(dateStats);
    for (DateStat dateStat : dateStats) {
        dateStat.computeStats();
    }
    // 7 day count
    ArrayList<DateStat> sevenDayDateStats = Lists.newArrayList();
    for (DateMidnight dateKey : sevenDayMap.keySet()) {
        int count = sevenDayMap.get(dateKey).size();
        DateStat dateStat = new DateStat(dateKey.toDate());
        dateStat.addValue(new Double(count));
        sevenDayDateStats.add(dateStat);
        dateStat.computeStats();
    }
    Collections.sort(sevenDayDateStats);

    DateStat[] dsArray = new DateStat[dateStats.size()];
    accum.setDailyResponseRate(dateStats.toArray(dsArray));
    dsArray = new DateStat[sevenDayDateStats.size()];
    accum.setSevenDayDateStats(sevenDayDateStats.toArray(dsArray));

    String responseRateStr = "0%";
    int respondedSignals = events.size() - missedSignals;
    if (events.size() > 0) {
        float responseRate = ((float) respondedSignals / (float) events.size()) * 100;
        responseRateStr = Float.toString(responseRate) + "%";
    }
    accum.setResponseRate(responseRateStr);
    float avgResponseTime = (float) totalMillisToRespond / (float) respondedSignals / 60000;
    accum.setResponseTime(Float.toString(Math.round(avgResponseTime)));
}

From source file:com.createtank.payments.coinbase.CoinbaseApi.java

/**
 * Sell bitcoin and receive a credit to the user's U.S. bank account.
 * @param qty the number of bitcoins to sell
 * @return A Transfer object containing information about the sale.
 * @throws IOException//from w  w  w  .  java  2s  .  c  om
 */
public Transfer sellBitcoin(float qty) throws IOException {
    Map<String, String> params = new HashMap<String, String>();
    if (apiKey != null)
        params.put("api_key", apiKey);
    params.put("qty", Float.toString(qty));
    params.put("agree_btc_amount_varies", Boolean.toString(true));

    JsonObject response = RequestClient.post(this, "sells", params, accessToken);
    boolean success = response.get("success").getAsBoolean();

    return success ? Transfer.fromJson(response.getAsJsonObject("transfer")) : null;
}

From source file:com.duinopeak.balanbot.BalanbotActivity.java

@Override
public void onStop() {
    super.onStop();
    if (D)/*w ww.  j  a  v a2 s  .c om*/
        Log.d(TAG, "-- ON STOP --");
    // unregister sensor listeners to prevent the activity from draining the
    // device's battery.
    mSensorFusion.unregisterListeners();

    // Store the value for FILTER_COEFFICIENT and max angle at shutdown
    Editor edit = PreferenceManager.getDefaultSharedPreferences(this).edit();
    edit.putString("filterCoefficient", Float.toString(mSensorFusion.filter_coefficient));
    edit.putBoolean("backToSpot", backToSpot);
    edit.putInt("maxAngle", maxAngle);
    edit.putInt("maxTurning", maxTurning);
    edit.commit();
}

From source file:com.iverson.toby.rhealth.MainActivity.java

public void FillPlace() {
    setContentView(R.layout.item_selected);

    TextView itemName = (TextView) findViewById(R.id.item_name);
    TextView itemVicinity = (TextView) findViewById(R.id.item_vicinity);
    TextView itemVRating = (TextView) findViewById(R.id.item_vrating);
    TextView itemRating = (TextView) findViewById(R.id.item_rating);
    TextView itemNegative = (TextView) findViewById(R.id.item_negative);

    itemRating.setText(Float.toString(CurrentPlace.place.getRating()) + "/5 Google Rating");
    itemName.setText(CurrentPlace.place.getName());
    itemVicinity.setText(CurrentPlace.place.getVicinity());
    itemVRating.setText(Integer.toString(CurrentPlace.place.getVRating()) + "/100 Health Score");
    if (CurrentPlace.place.getVRating() < 0) {
        itemNegative.setText("Yes negative numbers are bad");
    }//from   www .j  av a 2 s.  co  m

    Button clickButton = (Button) findViewById(R.id.violations_button);
    clickButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            setContentView(R.layout.violation_layout);
            ViolationAdapter violationAdapter = new ViolationAdapter(MainActivity.this, R.layout.activity_main,
                    CurrentViolations.all());
            violationView = (ListView) findViewById(R.id.violation_listview);
            violationView.setAdapter(violationAdapter);
            Button returnButton = (Button) findViewById(R.id.back_button);
            returnButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    FillPlace();
                }
            });

        };
    });
    //opens map
    Button mapButton = (Button) findViewById(R.id.map_button);
    mapButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            float[] geometry = CurrentPlace.place.getGeometry();

            String uri = String.format(Locale.ENGLISH,
                    "geo:" + Float.toString(geometry[0]) + "," + Float.toString(geometry[1]));
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
            startActivity(intent);

            Toast.makeText(getApplicationContext(), "loading map " + uri, Toast.LENGTH_LONG).show();

        }
    });

    Button returnButton = (Button) findViewById(R.id.list_button);
    returnButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            setContentView(R.layout.httptestlist);
            FilLStoreList();
        }
    });

}

From source file:net.myrrix.client.ClientRecommender.java

private void doSetOrRemove(String path, long unnormalizedID, float value, boolean set) throws TasteException {
    boolean sendValue = value != 1.0f;
    Map<String, String> requestProperties;
    byte[] bytes;
    if (sendValue) {
        requestProperties = Maps.newHashMapWithExpectedSize(2);
        bytes = Float.toString(value).getBytes(Charsets.UTF_8);
        requestProperties.put(HttpHeaders.CONTENT_TYPE, MediaType.PLAIN_TEXT_UTF_8.toString());
        requestProperties.put(HttpHeaders.CONTENT_LENGTH, Integer.toString(bytes.length));
    } else {/*from   ww w.j a  v  a2  s  .  c  om*/
        requestProperties = null;
        bytes = null;
    }

    TasteException savedException = null;
    for (HostAndPort replica : choosePartitionAndReplicas(unnormalizedID)) {
        HttpURLConnection connection = null;
        try {
            connection = buildConnectionToReplica(replica, path, set ? "POST" : "DELETE", sendValue, false,
                    requestProperties);
            if (sendValue) {
                OutputStream out = connection.getOutputStream();
                out.write(bytes);
                out.close();
            }
            // Should not be able to return Not Available status
            if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
                throw new TasteException(connection.getResponseCode() + " " + connection.getResponseMessage());
            }
            return;
        } catch (TasteException te) {
            log.info("Can't access {} at {}: ({})", path, replica, te.toString());
            savedException = te;
        } catch (IOException ioe) {
            log.info("Can't access {} at {}: ({})", path, replica, ioe.toString());
            savedException = new TasteException(ioe);
        } finally {
            if (connection != null) {
                connection.disconnect();
            }
        }
    }
    throw savedException;
}

From source file:com.skratchdot.electribe.model.esx.provider.SongItemProvider.java

/**
 * This returns the column text for the adapted class.
 * <!-- begin-user-doc -->/*from  w  ww.j  av  a2  s. co m*/
 * <!-- end-user-doc -->
 */
@Override
public String getColumnText(Object object, int columnIndex) {
    switch (columnIndex) {
    // Esx#
    case 0:
        return ((Song) object).getSongNumberCurrent().toString();
    // Orig#
    case 1:
        return ((Song) object).getSongNumberOriginal().toString();
    // Name
    case 2:
        return ((Song) object).getName();
    // Tempo
    case 3:
        return Float.toString(((Song) object).getTempo().getValue());
    // TempoLock
    case 4:
        return ((Song) object).getTempoLock().getLiteral();
    // Length
    case 5:
        return ((Song) object).getSongLength().getLiteral();
    // MuteHold
    case 6:
        return ((Song) object).getMuteHold().getLiteral();
    // NextSong
    case 7:
        return ((Song) object).getNextSongNumber().getLiteral();
    // NumOfEvents
    case 8:
        return Short.toString(((Song) object).getNumberOfSongEventsCurrent());
    default:
        return getText(object);
    }
}

From source file:eu.itesla_project.dymola.DymolaImpactAnalysis.java

private void fillMetrics(List<Contingency> contingencies, ExecutionReport report, Map<String, String> metrics) {
    float successPercent = 100f * (1 - ((float) report.getErrors().size()) / contingencies.size());
    metrics.put("successPercent", Float.toString(successPercent));
    DymolaUtil.putBadExitCode(report, metrics);
}

From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDao.java

/**
 * convenience method//from w  w w  .j  a va  2 s .co m
 */
protected void addPropertyFloatValue(Resource res, Property dataprop, Float value, Model model) {
    if (dataprop != null && value != null) {
        model.add(res, dataprop, Float.toString(value), XSDDatatype.XSDfloat);
    }
}

From source file:com.apm4all.tracy.TracyTest.java

@Test
public void testGetEvents_floatAnnotation() throws InterruptedException {
    final String FLOAT_NAME = "floatName";
    float floatValue = Float.MAX_VALUE;
    Tracy.setContext(TASK_ID_VALUE, PARENT_OPT_ID_VALUE, COMPONENT_VALUE);
    Tracy.before(L1_LABEL_NAME);//from w w w  .jav  a 2  s .c  o m
    Tracy.annotate(FLOAT_NAME, floatValue);
    Tracy.after(L1_LABEL_NAME);
    List<TracyEvent> events = Tracy.getEvents();
    assertEquals(1, events.size());
    TracyEvent event = events.get(0);
    assertEquals(TASK_ID_VALUE, event.getTaskId());
    assertEquals(PARENT_OPT_ID_VALUE, event.getParentOptId());
    assertEquals(L1_LABEL_NAME, event.getLabel());
    assertEquals(event.getAnnotation(FLOAT_NAME), new Float(floatValue));
    assertEquals(new Float(floatValue), Tracy.getEventsAsMaps().get(0).get(FLOAT_NAME));
    String jsonEvent = Tracy.getEventsAsJson().get(0);
    assertTrue(jsonEvent.contains("\"" + FLOAT_NAME + "\":" + Float.toString(floatValue)));
    Tracy.clearContext();
}

From source file:org.apache.vxquery.runtime.functions.cast.CastToStringOperation.java

public void convertFloatCanonical(FloatPointable floatp, DataOutput dOut) throws SystemException, IOException {
    abvsInner.reset();//from   ww  w .  j  a  v  a2 s.c om
    float value = floatp.getFloat();

    if (Float.isInfinite(value)) {
        if (value == Float.NEGATIVE_INFINITY) {
            FunctionHelper.writeCharSequence("-", dOutInner);
        }
        FunctionHelper.writeCharSequence("INF", dOutInner);
    } else if (Float.isNaN(value)) {
        FunctionHelper.writeCharSequence("NaN", dOutInner);
    } else {
        dOut.write(returnTag);
        dOut.writeUTF(Float.toString(value));
        return;
    }
    sendStringDataOutput(dOut);
}