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:org.eurekastreams.server.persistence.mappers.LuceneSearchMapper.java

/**
 * Execute the mapper.//from w  ww. j  a v  a 2  s. co  m
 * 
 * @param inRequest
 *            the request.
 * @return the items.
 */
@SuppressWarnings("unchecked")
@Override
public PagedSet<T> execute(final LuceneSearchRequest inRequest) {
    /**
     * Convoluted like this to make testing possible.
     */
    FullTextEntityManager sessionEntityManager = fullTextEntityManager;

    if (sessionEntityManager == null) {
        sessionEntityManager = Search.getFullTextEntityManager(getEntityManager());
    }

    QueryParser parser = queryBuilder.buildQueryParser();

    List<T> results = null;

    PagedSet<T> pagedSet = null;

    try {
        StringBuilder query = new StringBuilder();

        // TODO Escape!!
        for (Entry<String, Float> entry : inRequest.getFields().entrySet()) {
            query.append(entry.getKey());
            query.append(":");
            query.append("(%1$s)^");
            query.append(Float.toString(entry.getValue()));
            query.append(" ");
        }

        String luceneQueryString = String.format(query.toString(), inRequest.getSearchString());
        org.apache.lucene.search.Query luceneQuery = parser.parse(luceneQueryString);

        FullTextQuery fullTextQuery = sessionEntityManager.createFullTextQuery(luceneQuery,
                inRequest.getObjectType());

        fullTextQuery.setFirstResult(inRequest.getFirstResult());
        fullTextQuery.setMaxResults(inRequest.getMaxResults());

        SortField[] fields = new SortField[inRequest.getSortFields().size()];

        for (int i = 0; i < inRequest.getSortFields().size(); i++) {
            fields[i] = new SortField(inRequest.getSortFields().get(i), true);
        }

        Sort sort = new Sort(fields);

        fullTextQuery.setSort(sort);

        results = fullTextQuery.getResultList();

        /**
         * GWT can't serialize EMPTY_LIST.
         */
        if (results.equals(Collections.EMPTY_LIST)) {
            results = new ArrayList<T>();
        }

        pagedSet = new PagedSet<T>(inRequest.getFirstResult(), inRequest.getFirstResult() + results.size() - 1,
                fullTextQuery.getResultSize(), results);
    } catch (ParseException e) {
        log.error(e);
    }

    return pagedSet;
}

From source file:org.apache.ojb.broker.util.logging.LoggerWrapperPrintWriter.java

public void println(float v) {
    if (!filterEverything) {
        logLn(Float.toString(v));
    }
}

From source file:uk.co.jarofgreen.cityoutdoors.API.BaseCall.java

protected void addDataToCall(String key, Float value) {
    if (value != null) {
        try {/* w  ww.jav a 2  s  .  c o m*/
            multipartEntity.addPart(key, new StringBody(Float.toString(value)));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.laex.cg2d.model.joints.BEMouseJoint.java

@Override
public Object getPropertyValue(Object id) {
    if (isMaxForceProp(id)) {
        return Float.toString(mouseJointDef.maxForce);
    }//from  ww  w.  j a  v  a  2  s  . com
    if (isFrequencyProp(id)) {
        return Float.toString(mouseJointDef.frequencyHz);
    }
    if (isDampingRatioProp(id)) {
        return Float.toString(mouseJointDef.dampingRatio);
    }

    return super.getPropertyValue(id);
}

From source file:com.facebook.litho.ComponentsStethoManagerImpl.java

private static void storeYogaValue(StyleAccumulator accumulator, SimpleArrayMap<String, String> overrides,
        String key, YogaValue value) {
    if (overrides.containsKey(key)) {
        accumulator.store(key, overrides.get(key), false);
    } else {/*from  www  . j a v a2s  . c om*/
        final String valueString;
        switch (value.unit) {
        case UNDEFINED:
            valueString = "undefined";
            break;
        case POINT:
            valueString = Float.toString(value.value);
            break;
        case PERCENT:
            valueString = value.value + "%";
            break;
        case AUTO:
            valueString = "auto";
            break;
        default:
            throw new IllegalStateException();
        }
        accumulator.store(key, valueString, false);
    }
}

From source file:gmgen.plugin.PlayerCharacterOutput.java

/**
 * TODO Much of this code is repeated in CRToken, Race, Combatant and PlayerCharacterOutput
 *  /* www.ja v  a2s . co  m*/
 * @return An output version of the CR
 */
public String getCR() {
    Integer calcCR = display.calcCR();
    float cr = (calcCR == null) ? -1 : calcCR;
    String retString = "";

    // If the CR is a fractional CR then we convert to a 1/x format
    if ((cr > 0) && (cr < 1)) {
        Fraction fraction = Fraction.getFraction(cr); // new Fraction(CR);
        int denominator = fraction.getDenominator();
        int numerator = fraction.getNumerator();
        retString = numerator + "/" + denominator;
    } else if ((cr >= 1) || (cr == 0)) {
        int newCr = -99;
        String crAsString = Float.toString(cr);
        String decimalPlaceValue = crAsString.substring(crAsString.length() - 2);
        if (decimalPlaceValue.equals(".0")) {
            newCr = (int) cr;
        }

        retString += ((newCr > -99) ? newCr : cr);
    }
    return retString;
}

From source file:com.github.egonw.ops4j.Structures.java

public String tanimotoSimilarity(String smiles, float treshold, Object... objects)
        throws ClientProtocolException, IOException, HttpException {
    Map<String, String> params = new HashMap<String, String>();
    params.put("searchOptions.Molecule", smiles);
    params.put("searchOptions.SimilarityType", "0"); // Tanimoto
    params.put("searchOptions.Threshold", Float.toString(treshold));
    return runRequest(server + "structure/similarity", params, objects);
}

From source file:com.igormaznitsa.ideamindmap.facet.InMemoryPreferenceNode.java

@Override
public void putFloat(String key, float value) {
    this.put(key, Float.toString(value));
}

From source file:com.hp.hpl.jena.sparql.util.Utils.java

static public String stringForm(float f) {
    // No SPARQL short form.
    return Float.toString(f);
}

From source file:blue.soundObject.Note.java

private void noteInit(String input, Note previousNote) throws Exception {
    // If for any reason there should be an exception
    // let it bubble up and the note factory method will
    // return null

    int i = 0;//  w w w.j a  v  a  2s. c om
    ArrayList buffer = new ArrayList();
    int size = input.length();

    int start = 0;

    // the following code might be better off using
    // regular expressions, but should wait until
    // Java 1.4 is available on all platforms

    // PARSES PFIELDS FROM STRING
    while (i < size) {
        if (input.charAt(i) == '\"') {
            start = i++;

            while (i < size && input.charAt(i) != '\"') {
                i++;
            }

            buffer.add(input.substring(start, ++i));
            // i++;
        } else if (input.charAt(i) == '[') {
            start = ++i;
            while (i < size && input.charAt(i) != ']') {
                i++;
            }

            float val = ScoreExpressionParser.eval(input.substring(start, i));

            i++;

            buffer.add(Float.toString(val));
        } else if (Character.isWhitespace(input.charAt(i))) {
            while (i < size && Character.isWhitespace(input.charAt(i))) {
                i++; // eat up empty spaces or tabs
            }
        } else {
            start = i;
            while (i < size && !(Character.isWhitespace(input.charAt(i)))) {
                i++;
            }
            buffer.add(input.substring(start, i));
        }
    }

    if (previousNote != null) {
        boolean performCarry = buffer.get(0).equals(previousNote.getPField(1));

        if (!performCarry) {
            try {
                int instr1 = (int) (Float.parseFloat((String) buffer.get(0)));
                int instr2 = (int) (Float.parseFloat(previousNote.getPField(1)));

                if (instr1 == instr2) {
                    performCarry = true;
                }
            } catch (NumberFormatException nfe) {
                performCarry = false;
            }
        }

        if (performCarry) {
            int numFieldsToCopy = previousNote.getPCount() - buffer.size();
            if (numFieldsToCopy > 0) {
                for (i = previousNote.getPCount() - numFieldsToCopy; i < previousNote.getPCount(); i++) {
                    buffer.add(previousNote.getPField(i + 1));
                }
            }
        }
    }

    // INITIALIZES PFIELD ARRAY
    fields = (String[]) buffer.toArray(new String[buffer.size()]);

    if (previousNote != null) {

        // SWAP PERIODS WITH VALUE FROM PREVIOUS NOTE
        for (i = 0; i < fields.length; i++) {
            if (fields[i].equals(".")) {
                fields[i] = previousNote.getPField(i + 1);
            }
        }
    }

    float dur = Float.parseFloat(fields[2]);

    setSubjectiveDuration(dur);
    setTied(dur < 0.0f);
}