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.phonegap.accelerometer.Accelerometer.java

public PluginResult execute(String action, JSONArray args, String calbackId) {

    PluginResult result = null;//from w  ww .ja v  a2  s  .co m

    if (!AccelerometerSensor.isSupported()) {
        result = new PluginResult(PluginResult.Status.ILLEGALACCESSEXCEPTION,
                "Accelerometer sensor not supported");
    } else if (ACTION_GET_ACCELERATION.equals(action)) {
        JSONObject accel = new JSONObject();
        try {
            AccelerometerData accelData = getCurrentAcceleration();
            accel.put("x", (int) accelData.getLastXAcceleration());
            accel.put("y", (int) accelData.getLastYAcceleration());
            accel.put("z", (int) accelData.getLastZAcceleration());
            accel.put("timestamp", accelData.getLastTimestamp());
        } catch (JSONException e) {
            return new PluginResult(PluginResult.Status.JSONEXCEPTION, "JSONException:" + e.getMessage());
        }
        result = new PluginResult(PluginResult.Status.OK, accel);
    } else if (ACTION_GET_TIMEOUT.equals(action)) {
        float f = this.getTimeout();
        return new PluginResult(PluginResult.Status.OK, Float.toString(f));
    } else if (ACTION_SET_TIMEOUT.equals(action)) {
        try {
            float t = Float.parseFloat(args.getString(0));
            this.setTimeout(t);
            return new PluginResult(PluginResult.Status.OK, "");
        } catch (NumberFormatException e) {
            return new PluginResult(PluginResult.Status.ERROR, e.getMessage());
        } catch (JSONException e) {
            return new PluginResult(PluginResult.Status.JSONEXCEPTION, e.getMessage());
        }
    } else if (ACTION_STOP.equals(action)) {
        this.stop();
        return new PluginResult(PluginResult.Status.OK, "");
    } else {
        result = new PluginResult(PluginResult.Status.INVALIDACTION, "Accelerometer: Invalid action:" + action);
    }

    return result;
}

From source file:org.owasp.benchmark.testcode.BenchmarkTest02680.java

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html");

    String queryString = request.getQueryString();
    String paramval = "vector" + "=";
    int paramLoc = -1;
    if (queryString != null)
        paramLoc = queryString.indexOf(paramval);
    if (paramLoc == -1) {
        response.getWriter().println(/*from w ww .j a  va  2  s.c  om*/
                "getQueryString() couldn't find expected parameter '" + "vector" + "' in query string.");
        return;
    }

    String param = queryString.substring(paramLoc + paramval.length()); // 1st assume "vector" param is last parameter in query string.
    // And then check to see if its in the middle of the query string and if so, trim off what comes after.
    int ampersandLoc = queryString.indexOf("&", paramLoc);
    if (ampersandLoc != -1) {
        param = queryString.substring(paramLoc + paramval.length(), ampersandLoc);
    }
    param = java.net.URLDecoder.decode(param, "UTF-8");

    String bar = doSomething(param);

    try {
        float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat();
        String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front.

        String user = "SafeFloyd";
        String fullClassName = this.getClass().getName();
        String testCaseNumber = fullClassName
                .substring(fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length());
        user += testCaseNumber;

        String cookieName = "rememberMe" + testCaseNumber;

        boolean foundUser = false;
        javax.servlet.http.Cookie[] cookies = request.getCookies();
        for (int i = 0; cookies != null && ++i < cookies.length && !foundUser;) {
            javax.servlet.http.Cookie cookie = cookies[i];
            if (cookieName.equals(cookie.getName())) {
                if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) {
                    foundUser = true;
                }
            }
        }

        if (foundUser) {
            response.getWriter().println("Welcome back: " + user + "<br/>");
        } else {
            javax.servlet.http.Cookie rememberMe = new javax.servlet.http.Cookie(cookieName, rememberMeKey);
            rememberMe.setSecure(true);
            request.getSession().setAttribute(cookieName, rememberMeKey);
            response.addCookie(rememberMe);
            response.getWriter().println(user + " has been remembered with cookie: " + rememberMe.getName()
                    + " whose value is: " + rememberMe.getValue() + "<br/>");
        }

    } catch (java.security.NoSuchAlgorithmException e) {
        System.out.println("Problem executing SecureRandom.nextFloat() - TestCase");
        throw new ServletException(e);
    }
    response.getWriter().println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed");
}

From source file:org.apache.nutch.indexer.field.boost.BoostFieldFilter.java

public Document filter(String url, Document doc, List<FieldWritable> fields) throws IndexingException {

    List<String> comps = new ArrayList<String>();
    float boost = 0.0f;

    for (FieldWritable field : fields) {

        // save the boost factor as unindexed fields, to show different scoring
        FieldType type = field.getType();
        if (type == FieldType.BOOST) {
            float fieldBoost = field.getBoost();
            boost += fieldBoost;//from w  ww  .j av  a 2s. c  o  m
            doc.add(new Field(Fields.BOOSTFACTOR, field.getValue() + ": " + fieldBoost, Field.Store.YES,
                    Field.Index.NO));
        } else if (type == FieldType.COMPUTATION) {
            comps.add(field.getValue());
        }
    }

    // set the boost for the document and save it in the index
    doc.setBoost(boost);
    doc.add(new Field(Fields.BOOST, Float.toString(boost), Field.Store.YES, Field.Index.NO));

    return doc;
}

From source file:AtomicFloat.java

public String toString() {
    return Float.toString(get());
}

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

@Override
public void onThermoCoupleReading(ThermocoupleSensor sensor, SensorReading<Float> reading) {
    Message m = mHandler.obtainMessage(MessageConstants.MESSAGE_THERMA_TEMPERATURE);
    m.getData().putFloat(MessageConstants.FLOAT_VALUE_KEY, reading.getValue());
    final Context thiscontext = this.getActivity();
    final String serialnumOne = sensor.getSerialNumber();
    final String serialnum = serialnumOne.replaceAll("[^\\u0000-\\uFFFF]", "");
    final String scan = Float.toString(reading.getValue());
    String json = "thermocouple;" + serialnum + ";" + scan;

    // POST to variable dashboard
    Ion.getDefault(thiscontext).getConscryptMiddleware().enable(false);
    Ion.with(thiscontext).load(//from   w w w . j  a  v a2  s.  com
            "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.koda.integ.hbase.test.BlockCacheSimpleTest.java

@Override
protected void setUp() throws Exception {
    if (cache != null)
        return;//from   w  w  w . j av  a2 s .c o  m
    conf = HBaseConfiguration.create();

    // Cache configuration
    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(OffHeapBlockCache.BLOCK_CACHE_OVERFLOW_TO_EXT_STORAGE_ENABLED,
            Boolean.toString(cacheOverflowEnabled));
    conf.set(OffHeapBlockCache.BLOCK_CACHE_EVICTION, cacheEviction);
    conf.set(OffHeapBlockCache.HEAP_BLOCK_CACHE_MEMORY_RATIO, onHeapRatio);
}

From source file:no.abmu.finances.domain.PostValidator.java

protected String[] getErrorMessageArguments(float value) {
    return new String[] { Float.toString(value) };
}

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

@Override
public void onOxaUpdate(OxaSensor sensor, SensorReading<Float> reading) {
    Message m = mHandler.obtainMessage(MessageConstants.MESSAGE_OXA_READING);
    m.getData().putFloat(MessageConstants.FLOAT_VALUE_KEY, reading.getValue());
    final Context thiscontext = this.getActivity();
    final String serialnumOne = sensor.getSerialNumber();
    final String serialnum = serialnumOne.replaceAll("[^\\u0000-\\uFFFF]", "");
    final String scan = Float.toString(reading.getValue());
    String json = "oxygen;" + serialnum + ";" + scan;

    // POST to variable dashboard
    Ion.getDefault(thiscontext).getConscryptMiddleware().enable(false);
    Ion.with(thiscontext).load(//from  ww  w .  j  av  a 2s.  com
            "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:fredboat.audio.MusicPersistenceHandler.java

public static void handlePreShutdown(int code) {
    File dir = new File("music_persistence");
    if (!dir.exists()) {
        dir.mkdir();/*from   w ww .ja v  a2s. c  om*/
    }
    HashMap<String, GuildPlayer> reg = PlayerRegistry.getRegistry();

    boolean isUpdate = code == ExitCodes.EXIT_CODE_UPDATE;
    boolean isRestart = code == ExitCodes.EXIT_CODE_RESTART;

    for (String gId : reg.keySet()) {
        try {
            GuildPlayer player = reg.get(gId);

            if (!player.isPlaying()) {
                continue;//Nothing to see here
            }

            String msg;

            if (isUpdate) {
                msg = I18n.get(player.getGuild()).getString("shutdownUpdating");
            } else if (isRestart) {
                msg = I18n.get(player.getGuild()).getString("shutdownRestarting");
            } else {
                msg = I18n.get(player.getGuild()).getString("shutdownIndef");
            }

            player.getActiveTextChannel().sendMessage(msg).queue();

            JSONObject data = new JSONObject();
            data.put("vc", player.getUserCurrentVoiceChannel(player.getGuild().getSelfMember()).getId());
            data.put("tc", player.getActiveTextChannel().getId());
            data.put("isPaused", player.isPaused());
            data.put("volume", Float.toString(player.getVolume()));
            data.put("repeatMode", player.getRepeatMode());
            data.put("shuffle", player.isShuffle());

            if (player.getPlayingTrack() != null) {
                data.put("position", player.getPlayingTrack().getEffectivePosition());
            }

            ArrayList<JSONObject> identifiers = new ArrayList<>();

            for (AudioTrackContext atc : player.getRemainingTracks()) {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                AbstractPlayer.getPlayerManager().encodeTrack(new MessageOutput(baos), atc.getTrack());

                JSONObject ident = new JSONObject()
                        .put("message", Base64.encodeBase64String(baos.toByteArray()))
                        .put("user", atc.getMember().getUser().getId());

                if (atc instanceof SplitAudioTrackContext) {
                    JSONObject split = new JSONObject();
                    SplitAudioTrackContext c = (SplitAudioTrackContext) atc;
                    split.put("title", c.getEffectiveTitle()).put("startPos", c.getStartPosition())
                            .put("endPos", c.getStartPosition() + c.getEffectiveDuration());

                    ident.put("split", split);
                }

                identifiers.add(ident);
            }

            data.put("sources", identifiers);

            try {
                FileUtils.writeStringToFile(new File(dir, gId), data.toString(), Charset.forName("UTF-8"));
            } catch (IOException ex) {
                player.getActiveTextChannel()
                        .sendMessage(MessageFormat.format(
                                I18n.get(player.getGuild()).getString("shutdownPersistenceFail"),
                                ex.getMessage()))
                        .queue();
            }
        } catch (Exception ex) {
            log.error("Error when saving persistence file", ex);
        }
    }
}

From source file:com.magizdev.babyoneday.profilewizard.BirthDataFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(com.magizdev.babyoneday.R.layout.fragment_profilewizard_birthdata,
            container, false);/* w  w w  .j  a v a 2  s  .  c o  m*/
    ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());

    mHeightView = ((TextView) rootView.findViewById(com.magizdev.babyoneday.R.id.profile_height_edittext));
    mHeightView.setText(Float.toString(mPage.getData().getFloat(Profile.HEIGHT)));

    mWeightView = (TextView) rootView.findViewById(com.magizdev.babyoneday.R.id.profile_weight_edittext);
    mWeightView.setText(Float.toString(mPage.getData().getFloat(Profile.WEIGHT)));

    mBirthday = (TextView) rootView.findViewById(R.id.profile_birthday);
    mBirthdayBtn = (ImageButton) rootView.findViewById(com.magizdev.babyoneday.R.id.profile_birthday_set);
    int intBirthday = mPage.getData().getInt(Profile.BIRTHDAY);
    calendar = DayUtil.toCalendar(intBirthday);

    mBirthday.setText(birthdayString + ":" + DayUtil.formatCalendar(calendar));

    mBirthdayBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            DatePickerDialog dialog = new DatePickerDialog(getActivity(), BirthDataFragment.this,
                    calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                    calendar.get(Calendar.DAY_OF_MONTH));
            dialog.show();
        }
    });
    birthdayString = getActivity().getResources().getString(com.magizdev.babyoneday.R.string.profile_birthday);

    return rootView;
}