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.mobilewallet.services.LoginService.java

@GET
@Produces(MediaType.APPLICATION_JSON)/*from  w  w  w.  j  av a2 s . c om*/
public Object login(@QueryParam("email") String email, @QueryParam("pwd") String password) {

    if (email != null && password != null) {

        String salt = Config.PWD_SALT + password;
        String md5PWD = org.apache.commons.codec.digest.DigestUtils.md5Hex(password + salt);
        User user = LoginBO.login(email.toLowerCase(), md5PWD);
        log.info(" Email : " + email + ", PWD : " + password);
        if (user != null) {
            log.info("Amount : " + user.getAmount() + ", Email : " + email);
            String userEID = MobileWalletID
                    .getEncryptedUserId(Config.USER_ENCRYPTED_EXTENSION + user.getUserId());
            JSONObject obj = new JSONObject();
            try {
                obj.put("userId", userEID);
                obj.put("name", user.getName());
                obj.put("amount", Float.toString(user.getAmount()));
                obj.put("mycode", user.getMyRefCode());
                log.info("JSON Amount : " + obj.getString("amount"));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            return obj.toString();
        }
    }

    JSONObject obj = new JSONObject();
    try {
        obj.put("invalid", "Y");
    } catch (Exception ex) {

    }
    return obj.toString();
}

From source file:org.pdfsam.pdf.DefaultPDFBoxLoader.java

public void accept(PDDocument document, PdfDocumentDescriptor descriptor) {
    descriptor.pages(document.getNumberOfPages());
    descriptor.setVersion(getVersion(Float.toString(document.getVersion())));
    PDDocumentInformation info = document.getDocumentInformation();
    descriptor.putInformation(PdfMetadataKey.TITLE.getKey(), info.getTitle());
    descriptor.putInformation(PdfMetadataKey.AUTHOR.getKey(), info.getAuthor());
    descriptor.putInformation(PdfMetadataKey.CREATOR.getKey(), info.getCreator());
    descriptor.putInformation(PdfMetadataKey.SUBJECT.getKey(), info.getSubject());
    descriptor.putInformation(PdfMetadataKey.KEYWORDS.getKey(), info.getKeywords());
    descriptor.putInformation("Producer", info.getProducer());
    Optional.ofNullable(info.getCreationDate()).map(FORMATTER::format)
            .ifPresent(c -> descriptor.putInformation("FormattedCreationDate", c));
}

From source file:org.etudes.mneme.impl.AccessSubmissionsQuestionScoresDelegate.java

/**
 * Format a score to 2 decimal places, trimming ".0" if present.
 * /* w  w  w. jav a  2 s  .  c o m*/
 * @param score
 *        The score to format.
 * @return The formatted score
 */
protected static String formatScore(Context context, Float score) {
    String earnedStr = context.getMessages().getFormattedMessage("format-score-earned", null);
    if (score == null)
        return "- " + earnedStr;

    // round to two places
    String rv = Float.toString(Math.round(score * 100.0f) / 100.0f);

    // get rid of ".00"
    if (rv.endsWith(".00")) {
        rv = rv.substring(0, rv.length() - 3);
    }

    // get rid of ".0"
    if (rv.endsWith(".0")) {
        rv = rv.substring(0, rv.length() - 2);
    }

    return rv + earnedStr;
}

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

public Element saveAsXML() {
    Element retVal = new Element("linePoint");

    retVal.setAttribute("x", Float.toString(getX()));
    retVal.setAttribute("y", Float.toString(getY()));

    return retVal;
}

From source file:org.apache.nutch.indexer.solr.segment.SegmentSolrIndexUtil.java

/**
 * Index a webpage.//www.jav  a 2  s  .  c o  m
 * 
 * @param key
 *            The key of the page (reversed url).
 * @param page
 *            The webpage.
 * @return The indexed document, or null if skipped by index filters.
 */
public static NutchDocument index(String key, WebPageSegment page) {
    NutchDocument doc = new NutchDocument();
    String url = TableUtil.unreverseUrl(key);
    if (page.getTitle() == null || page.getConfigUrl() == null)
        return null;
    doc.add("rowkey", key);
    float boost = page.getScore();
    if (boost < 0.1)
        boost = 1.0f;
    doc.setScore(boost);
    // store boost for use by explain and dedup
    doc.add("boost", Float.toString(boost));
    doc.add("rootSite", page.getRootSiteId() + "");
    doc.add("mdType", page.getMediaTypeId() + "");
    doc.add("mdLevel", page.getMediaLevelId() + "");
    doc.add("topic", page.getTopicTypeId() + "");
    doc.add("polictic", page.getPolicticTypeId() + "");
    doc.add("areaId", page.getAreaId() + "");

    String host = null;
    try {
        URL u = new URL(url);
        host = u.getHost();
    } catch (MalformedURLException e) {
        LOG.warn("Error indexing " + key + ": " + e);
        return null;
    }
    if (host != null) {
        // add host as un-stored, indexed and tokenized
        doc.add("host", host);
        // add site as un-stored, indexed and un-tokenized
        doc.add("site", host);
    }
    // url is both stored and indexed, so it's both searchable and returned
    doc.add("url", url);
    doc.add("cfgurl", page.getConfigUrl().toString());
    String tstamp = DateUtil.getThreadLocalDateFormat().format(new Date(page.getFetchTime()));
    doc.add("fetchTime", tstamp);
    doc.add("fTime", tstamp);
    tstamp = DateUtil.getThreadLocalDateFormat().format(new Date(page.getParseTime()));
    doc.add("parseTime", tstamp);
    doc.add("pTime", tstamp);
    tstamp = DateUtil.getThreadLocalDateFormat().format(new Date(page.getDataTime()));
    doc.add("dataTime", tstamp);
    doc.add("dTime", tstamp);
    doc.add("title", page.getTitle().toString());

    Map<Utf8, Utf8> segCnt = page.getSegMentCnt();
    // doc.add("keywords", segCnt.get(WebPageSegment.keyworksColName).toString());
    // doc.add("description", segCnt.get(WebPageSegment.descriptionColName).toString());
    for (Utf8 cntkey : segCnt.keySet()) {
        String colName = cntkey.toString();
        if (colName.endsWith("list")) {//
            continue;
        }
        Utf8 v = segCnt.get(cntkey);
        if (v == null)
            continue;
        String val = v.toString();
        if (colName.endsWith("time")) {
            try {
                tstamp = DateUtil.getThreadLocalDateFormat().format(df.parse(val));
                doc.add("cnt_" + colName.replace("time", "_time"), tstamp);
            } catch (Exception e) {
                doc.add("cnt_" + colName, val);
            }
        } else {
            if (cntkey.equals(WebPageSegment.keyworksColName)) {
                doc.add("keywords", val);
            } else if (cntkey.equals(WebPageSegment.descriptionColName)) {
                doc.add("description", val);
            } else {
                doc.add("cnt_" + colName, val.replaceAll("(?i)(<p>|</p>)", ""));
            }
        }
    }
    Map<Utf8, Utf8> segExInfo = page.getExtendInfoAttrs();
    for (Utf8 exInfokey : segExInfo.keySet()) {
        String colName = exInfokey.toString();
        Utf8 v = segExInfo.get(exInfokey);
        if (v == null)
            continue;
        String val = v.toString();
        doc.add("exinfo_" + colName, val);
    }
    // segmeng_col-segmeng_attr_col:value
    Map<Utf8, Utf8> segMentAttr = page.getSegMentAttr();
    for (Utf8 exInfokey : segMentAttr.keySet()) {
        String colName = exInfokey.toString();
        Utf8 v = segMentAttr.get(exInfokey);
        if (v == null)
            continue;
        String val = v.toString();
        doc.add("cntattr_" + colName, val);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Indexing URL: " + url);
    }
    return doc;
}

From source file:marytts.signalproc.effects.VocalTractLinearScalerEffect.java

public VocalTractLinearScalerEffect(int samplingRate) {
    super(samplingRate);

    setExampleParameters("amount" + chParamEquals + Float.toString(DEFAULT_AMOUNT) + chParamSeparator);

    strHelpText = getHelpText();//from   ww w.  j a  v  a2  s  .c  o m
}

From source file:com.spaceprogram.simplejpa.util.AmazonSimpleDBUtil.java

/**
 * Encodes positive float value into a string by zero-padding number up to the specified number of digits
 *
 * @param   number positive float value to be encoded
 * @param   maxNumDigits   maximum number of digits preceding the decimal point in the largest value in the data set
 * @return string representation of the zero-padded float value
 *///from ww  w . ja  v  a2 s  . c o m
public static String encodeZeroPadding(float number, int maxNumDigits) {
    String floatString = Float.toString(number);
    int numBeforeDecimal = floatString.indexOf('.');
    numBeforeDecimal = (numBeforeDecimal >= 0 ? numBeforeDecimal : floatString.length());
    int numZeroes = maxNumDigits - numBeforeDecimal;
    StringBuffer strBuffer = new StringBuffer(numZeroes + floatString.length());
    for (int i = 0; i < numZeroes; i++) {
        strBuffer.insert(i, '0');
    }
    strBuffer.append(floatString);
    return strBuffer.toString();
}

From source file:edgeserver.Publicacao.java

public void publica(String urlLogin, String urlInsertDado) throws Exception {
    // make sure cookies is turn on
    CookieHandler.setDefault(new CookieManager());

    Date datapublicacao = new Date();

    HTTPClient http = new HTTPClient();

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

    http.sendPost(urlLogin, postp);/* w  ww. j  av a2 s  . c  o m*/

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

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

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

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

    java.util.Map<String, String[]> map = request.getParameterMap();
    String param = "";
    if (!map.isEmpty()) {
        String[] values = map.get("BenchmarkTest01355");
        if (values != null)
            param = values[0];// w  w  w.  j ava2s  .  c om
    }

    String bar = new Test().doSomething(request, param);

    float rand = new java.util.Random().nextFloat();
    String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front.

    String user = "Floyd";
    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();
    if (cookies != null) {
        for (int i = 0; !foundUser && i < cookies.length; i++) {
            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);
        //         rememberMe.setPath("/benchmark/" + this.getClass().getSimpleName());
        rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet 
        // e.g., /benchmark/sql-01/BenchmarkTest01001
        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/>");

    }

    response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed");
}

From source file:lux.query.TermPQuery.java

@Override
public String toQueryString(String field, IndexConfiguration config) {

    StringBuilder buf = new StringBuilder();

    if (StringUtils.isBlank(term.field())) {
        buf.append(field);/*from  w  w w.j  av a  2 s.co m*/
    } else {
        buf.append(term.field());
    }
    buf.append(':');

    buf.append(LuxQueryParser.escapeQParser(term.text()));

    if (boost != 1.0f) {
        buf.append('^').append(Float.toString(boost));
    }

    return buf.toString();
}