Example usage for java.lang Float valueOf

List of usage examples for java.lang Float valueOf

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static Float valueOf(float f) 

Source Link

Document

Returns a Float instance representing the specified float value.

Usage

From source file:Main.java

public static Float getFloat(String key, float defVal) {
    return Float.valueOf(sp.getFloat(key, defVal));
}

From source file:Main.java

public static int getInterval(long timeInMillis, long currentTimeInMillis) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTimeInMillis);
    Long timeInMillisInterval = timeInMillis - calendar.getTimeInMillis();
    Float x = Float.valueOf(timeInMillisInterval) / 1000 / 3600 / 24;
    return (int) Math.ceil(x);
}

From source file:Main.java

public static void keep_setFloat(Field field, Object obj, Cursor cursor, int i) {
    try {/* w w  w.j  a  va 2  s .  co  m*/
        if (field.getType().equals(Float.TYPE))
            field.setFloat(obj, cursor.getFloat(i));
        else
            field.set(obj, Float.valueOf(cursor.getFloat(i)));
    } catch (Exception exception) {
        exception.printStackTrace();
    }
}

From source file:Main.java

private static float getVersion(String msg, String sign) {
    float version = -1.0F;
    if ((null != msg) && (!"".equals(msg)) && (null != sign) && (!"".equals(sign))) {
        String ver = msg.substring(msg.indexOf(sign) + 1, msg.length());
        if ((null != ver) && (!"".equals(ver))) {
            version = Float.valueOf(ver).floatValue();
        }/*from w ww. j a  v a  2s.  c o m*/
    }
    return version;
}

From source file:Main.java

public static float asFloat(Object value, float def) {
    if (value instanceof Number) {
        return ((Number) value).floatValue();
    } else {/*from   w w w.j a  v  a  2s . c  o m*/
        try {
            return Float.valueOf(value.toString());
        } catch (NumberFormatException ex) {
            return def;
        }
    }
}

From source file:Main.java

public static float readFloatAttribute(XMLStreamReader reader, String attributeName) {
    return Float.valueOf(reader.getAttributeValue(null, attributeName));
}

From source file:Main.java

/**
 * Gets a float value of the given attribute
 * @param node//from   w w w  .j  a  v  a2 s.  c o m
 * @param attrName
 * @param defaultValue
 * @return
 */
public static float getFloatValue(Node node, String attrName, float defaultValue) {
    String value = getValue(node, attrName, null);

    if (value == null)
        return defaultValue;

    try {
        return Float.valueOf(value);
    } catch (NumberFormatException e) {
        return defaultValue;
    }
}

From source file:Main.java

static final Float convertUnits(String name, XmlPullParser atts, float dpi, float width, float height) {
    String value = getStringAttr(name, atts);
    if (value == null) {
        return null;
    } else if (value.endsWith("px")) {
        return Float.parseFloat(value.substring(0, value.length() - 2));
    } else if (value.endsWith("pt")) {
        return Float.valueOf(value.substring(0, value.length() - 2)) * dpi / 72;
    } else if (value.endsWith("pc")) {
        return Float.valueOf(value.substring(0, value.length() - 2)) * dpi / 6;
    } else if (value.endsWith("cm")) {
        return Float.valueOf(value.substring(0, value.length() - 2)) * dpi / 2.54f;
    } else if (value.endsWith("mm")) {
        return Float.valueOf(value.substring(0, value.length() - 2)) * dpi / 254;
    } else if (value.endsWith("in")) {
        return Float.valueOf(value.substring(0, value.length() - 2)) * dpi;
    } else if (value.endsWith("%")) {
        Float result = Float.valueOf(value.substring(0, value.length() - 1));
        float mult;
        if (name.contains("x") || name.equals("width")) {
            mult = width / 100f;/*from  w  w w . ja v a2 s. c  o  m*/
        } else if (name.contains("y") || name.equals("height")) {
            mult = height / 100f;
        } else {
            mult = (height + width) / 2f;
        }
        return result * mult;
    } else {
        return Float.valueOf(value);
    }
}

From source file:Main.java

/**
 * Get the cursor//from   ww w.  j  a  v  a  2  s . c  om
 * @param cursor Cursor from where read value
 * @param index int to read
 * @return Object read
 */
private static Object getCursorValue(Cursor cursor, int index) {
    switch (cursor.getType(index)) {
    case Cursor.FIELD_TYPE_INTEGER:
        return Integer.valueOf(cursor.getInt(index));
    case Cursor.FIELD_TYPE_FLOAT:
        return Float.valueOf(cursor.getFloat(index));
    case Cursor.FIELD_TYPE_STRING:
        return cursor.getString(index);
    case Cursor.FIELD_TYPE_BLOB:
        return cursor.getBlob(index);
    default:
        return null;
    }
}

From source file:edu.msu.cme.rdp.multicompare.Main.java

public static void main(String[] args) throws Exception {
    PrintStream hier_out = null;//w  ww .j a v  a 2s  .c  om
    PrintWriter assign_out = new PrintWriter(new NullWriter());
    PrintStream bootstrap_out = null;
    File hier_out_filename = null;
    String propFile = null;
    File biomFile = null;
    File metadataFile = null;
    PrintWriter shortseq_out = null;
    List<MCSample> samples = new ArrayList();
    ClassificationResultFormatter.FORMAT format = ClassificationResultFormatter.FORMAT.allRank;
    float conf = CmdOptions.DEFAULT_CONF;
    String gene = null;
    int min_bootstrap_words = Classifier.MIN_BOOTSTRSP_WORDS;

    try {
        CommandLine line = new PosixParser().parse(options, args);

        if (line.hasOption(CmdOptions.OUTFILE_SHORT_OPT)) {
            assign_out = new PrintWriter(line.getOptionValue(CmdOptions.OUTFILE_SHORT_OPT));
        } else {
            throw new IllegalArgumentException("Require the output file for classification assignment");
        }
        if (line.hasOption(CmdOptions.HIER_OUTFILE_SHORT_OPT)) {
            hier_out_filename = new File(line.getOptionValue(CmdOptions.HIER_OUTFILE_SHORT_OPT));
            hier_out = new PrintStream(hier_out_filename);
        }
        if (line.hasOption(CmdOptions.BIOMFILE_SHORT_OPT)) {
            biomFile = new File(line.getOptionValue(CmdOptions.BIOMFILE_SHORT_OPT));
        }
        if (line.hasOption(CmdOptions.METADATA_SHORT_OPT)) {
            metadataFile = new File(line.getOptionValue(CmdOptions.METADATA_SHORT_OPT));
        }

        if (line.hasOption(CmdOptions.TRAINPROPFILE_SHORT_OPT)) {
            if (gene != null) {
                throw new IllegalArgumentException(
                        "Already specified the gene from the default location. Can not specify train_propfile");
            } else {
                propFile = line.getOptionValue(CmdOptions.TRAINPROPFILE_SHORT_OPT);
            }
        }
        if (line.hasOption(CmdOptions.FORMAT_SHORT_OPT)) {
            String f = line.getOptionValue(CmdOptions.FORMAT_SHORT_OPT);
            if (f.equalsIgnoreCase("allrank")) {
                format = ClassificationResultFormatter.FORMAT.allRank;
            } else if (f.equalsIgnoreCase("fixrank")) {
                format = ClassificationResultFormatter.FORMAT.fixRank;
            } else if (f.equalsIgnoreCase("filterbyconf")) {
                format = ClassificationResultFormatter.FORMAT.filterbyconf;
            } else if (f.equalsIgnoreCase("db")) {
                format = ClassificationResultFormatter.FORMAT.dbformat;
            } else if (f.equalsIgnoreCase("biom")) {
                format = ClassificationResultFormatter.FORMAT.biom;
            } else {
                throw new IllegalArgumentException(
                        "Not an valid output format, only allrank, fixrank, biom, filterbyconf and db allowed");
            }
        }
        if (line.hasOption(CmdOptions.GENE_SHORT_OPT)) {
            if (propFile != null) {
                throw new IllegalArgumentException(
                        "Already specified train_propfile. Can not specify gene any more");
            }
            gene = line.getOptionValue(CmdOptions.GENE_SHORT_OPT).toLowerCase();

            if (!gene.equals(ClassifierFactory.RRNA_16S_GENE) && !gene.equals(ClassifierFactory.FUNGALLSU_GENE)
                    && !gene.equals(ClassifierFactory.FUNGALITS_warcup_GENE)
                    && !gene.equals(ClassifierFactory.FUNGALITS_unite_GENE)) {
                throw new IllegalArgumentException(gene + " not found, choose from"
                        + ClassifierFactory.RRNA_16S_GENE + ", " + ClassifierFactory.FUNGALLSU_GENE + ", "
                        + ClassifierFactory.FUNGALITS_warcup_GENE + ", "
                        + ClassifierFactory.FUNGALITS_unite_GENE);
            }
        }
        if (line.hasOption(CmdOptions.MIN_BOOTSTRAP_WORDS_SHORT_OPT)) {
            min_bootstrap_words = Integer
                    .parseInt(line.getOptionValue(CmdOptions.MIN_BOOTSTRAP_WORDS_SHORT_OPT));
            if (min_bootstrap_words < Classifier.MIN_BOOTSTRSP_WORDS) {
                throw new IllegalArgumentException(CmdOptions.MIN_BOOTSTRAP_WORDS_LONG_OPT
                        + " must be at least " + Classifier.MIN_BOOTSTRSP_WORDS);
            }
        }
        if (line.hasOption(CmdOptions.BOOTSTRAP_SHORT_OPT)) {
            String confString = line.getOptionValue(CmdOptions.BOOTSTRAP_SHORT_OPT);
            try {
                conf = Float.valueOf(confString);
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("Confidence must be a decimal number");
            }

            if (conf < 0 || conf > 1) {
                throw new IllegalArgumentException("Confidence must be in the range [0,1]");
            }
        }
        if (line.hasOption(CmdOptions.SHORTSEQ_OUTFILE_SHORT_OPT)) {
            shortseq_out = new PrintWriter(line.getOptionValue(CmdOptions.SHORTSEQ_OUTFILE_SHORT_OPT));
        }
        if (line.hasOption(CmdOptions.BOOTSTRAP_OUTFILE_SHORT_OPT)) {
            bootstrap_out = new PrintStream(line.getOptionValue(CmdOptions.BOOTSTRAP_OUTFILE_SHORT_OPT));
        }

        if (format.equals(ClassificationResultFormatter.FORMAT.biom) && biomFile == null) {
            throw new IllegalArgumentException("biom format requires an input biom file");
        }
        if (biomFile != null) { // if input biom file provided, use biom format
            format = ClassificationResultFormatter.FORMAT.biom;
        }

        args = line.getArgs();
        for (String arg : args) {
            String[] inFileNames = arg.split(",");
            File inputFile = new File(inFileNames[0]);
            File idmappingFile = null;
            if (!inputFile.exists()) {
                throw new IllegalArgumentException("Failed to find input file \"" + inFileNames[0] + "\"");
            }
            if (inFileNames.length == 2) {
                idmappingFile = new File(inFileNames[1]);
                if (!idmappingFile.exists()) {
                    throw new IllegalArgumentException("Failed to find input file \"" + inFileNames[1] + "\"");
                }
            }

            MCSample nextSample = new MCSample(inputFile, idmappingFile);
            samples.add(nextSample);
        }
        if (propFile == null && gene == null) {
            gene = CmdOptions.DEFAULT_GENE;
        }
        if (samples.size() < 1) {
            throw new IllegalArgumentException("Require at least one sample files");
        }
    } catch (Exception e) {
        System.out.println("Command Error: " + e.getMessage());
        new HelpFormatter().printHelp(80, " [options] <samplefile>[,idmappingfile] ...", "", options, "");
        return;
    }

    MultiClassifier multiClassifier = new MultiClassifier(propFile, gene, biomFile, metadataFile);
    MultiClassifierResult result = multiClassifier.multiCompare(samples, conf, assign_out, format,
            min_bootstrap_words);
    assign_out.close();
    if (hier_out != null) {
        DefaultPrintVisitor printVisitor = new DefaultPrintVisitor(hier_out, samples);
        result.getRoot().topDownVisit(printVisitor);
        hier_out.close();
        if (multiClassifier.hasCopyNumber()) {
            // print copy number corrected counts
            File cn_corrected_s = new File(hier_out_filename.getParentFile(),
                    "cnadjusted_" + hier_out_filename.getName());
            PrintStream cn_corrected_hier_out = new PrintStream(cn_corrected_s);
            printVisitor = new DefaultPrintVisitor(cn_corrected_hier_out, samples, true);
            result.getRoot().topDownVisit(printVisitor);
            cn_corrected_hier_out.close();
        }
    }

    if (bootstrap_out != null) {
        for (MCSample sample : samples) {
            MCSamplePrintUtil.printBootstrapCountTable(bootstrap_out, sample);
        }
        bootstrap_out.close();
    }

    if (shortseq_out != null) {
        for (String id : result.getBadSequences()) {
            shortseq_out.write(id + "\n");
        }
        shortseq_out.close();
    }

}