List of usage examples for java.lang Float valueOf
@HotSpotIntrinsicCandidate public static Float valueOf(float f)
From source file:Main.java
public static float readOptionalFloatAttribute(XMLStreamReader reader, String attributeName) { String attributeValue = reader.getAttributeValue(null, attributeName); return attributeValue != null ? Float.valueOf(attributeValue) : Float.NaN; }
From source file:Main.java
public synchronized static float[] parseFloatList(String list) { if (list == null) return null; fpMatch.reset(list);//from w ww .j av a2s.c om LinkedList<Float> floatList = new LinkedList<Float>(); while (fpMatch.find()) { String val = fpMatch.group(1); floatList.add(Float.valueOf(val)); } float[] retArr = new float[floatList.size()]; Iterator<Float> it = floatList.iterator(); int idx = 0; while (it.hasNext()) { retArr[idx++] = ((Float) it.next()).floatValue(); } return retArr; }
From source file:Main.java
/** * Takes a string of the form [HH:]MM:SS[.mmm] and converts it to * milliseconds./*ww w .j av a 2 s . c om*/ */ public static long parseTimeString(final String time) { String[] parts = time.split(":"); long result = 0; int idx = 0; if (parts.length == 3) { // string has hours result += Integer.valueOf(parts[idx]) * 3600000; idx++; } result += Integer.valueOf(parts[idx]) * 60000; idx++; result += (Float.valueOf(parts[idx])) * 1000; return result; }
From source file:Main.java
/** * Takes a string of the form [HH:]MM:SS[.mmm] and converts it to * milliseconds.//from w ww . ja v a 2 s . c o m */ public static long parseTimeString(final String time) { String[] parts = time.split(":"); long result = 0; int idx = 0; if (parts.length == 3) { // string has hours result += Integer.valueOf(parts[idx]) * 3600000L; idx++; } result += Integer.valueOf(parts[idx]) * 60000L; idx++; result += (Float.valueOf(parts[idx])) * 1000L; return result; }
From source file:Main.java
/** * Helper method used to get default value for wrappers used for primitive types * (0 for Integer etc)//from w w w. j a v a2 s . com */ public static Object defaultValue(Class<?> cls) { if (cls == Integer.TYPE) { return Integer.valueOf(0); } if (cls == Long.TYPE) { return Long.valueOf(0L); } if (cls == Boolean.TYPE) { return Boolean.FALSE; } if (cls == Double.TYPE) { return Double.valueOf(0.0); } if (cls == Float.TYPE) { return Float.valueOf(0.0f); } if (cls == Byte.TYPE) { return Byte.valueOf((byte) 0); } if (cls == Short.TYPE) { return Short.valueOf((short) 0); } if (cls == Character.TYPE) { return '\0'; } throw new IllegalArgumentException("Class " + cls.getName() + " is not a primitive type"); }
From source file:Main.java
public static <T> T getData(Context context, String fileName, String key, Class T) { SharedPreferences sharedPreferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE); T result;//from ww w.ja v a 2 s . c o m if (String.class.isAssignableFrom(T)) { result = (T) sharedPreferences.getString(key, ""); } else if (Integer.class.isAssignableFrom(T)) { result = (T) Integer.valueOf(sharedPreferences.getInt(key, 0)); } else if (Float.class.isAssignableFrom(T)) { result = (T) Float.valueOf(sharedPreferences.getFloat(key, 0)); } else if (Long.class.isAssignableFrom(T)) { result = (T) Long.valueOf(sharedPreferences.getLong(key, 0)); } else { result = (T) Boolean.valueOf(sharedPreferences.getBoolean(key, false)); } return result; }
From source file:Main.java
public static float parseJsonMovesApiCall(String jsonString, String fieldName) { float result = 0; try {/*from ww w .j av a 2 s. com*/ JSONObject data; data = new JSONObject(jsonString).getJSONObject("data"); JSONArray items = data.getJSONArray("items"); for (int i = 0; i < items.length(); i++) { JSONObject details = ((JSONObject) items.get(i)).getJSONObject("details"); String fieldContent = details.getString(fieldName); result = Float.valueOf(fieldContent) + result; } } catch (JSONException e) { e.printStackTrace(); } return result; }
From source file:Main.java
/** * <p>Extract decimal values from an array of strings into an array of float.</p> * * <p>Exceptions in the format of the string are trapped and 0 value(s) returned.</p> * * @param src an array of strings, each of which should be a decimal numeric value * @return an array of float/*from www.j a v a 2s. co m*/ */ static public float[] copyStringToFloatArray(String[] src) { if (src == null) return null; int n = src.length; float[] dst = new float[n]; for (int j = 0; j < n; ++j) { float value = 0; try { value = Float.valueOf(src[j]).floatValue(); } catch (NumberFormatException e) { } catch (NullPointerException e) { } dst[j] = value; } return dst; }
From source file:edu.msu.cme.rdp.readseq.utils.SequenceTrimmer.java
public static void main(String[] args) throws IOException { Options options = new Options(); options.addOption("r", "ref-seq", true, "Trim points are given as positions in a reference sequence from this file"); options.addOption("i", "inclusive", false, "Trim points are inclusive"); options.addOption("l", "length", true, "Minimum length of sequence after trimming"); options.addOption("f", "filled-ratio", true, "Minimum ratio of filled model positions of sequence after trimming"); options.addOption("o", "out", true, "Write sequences to directory (default=cwd)"); options.addOption("s", "stats", true, "Write stats to file"); PrintWriter statsOut = new PrintWriter(new NullWriter()); boolean inclusive = false; int minLength = 0; int minTrimmedLength = 0; int maxNs = 0; int maxTrimNs = 0; int trimStart = 0; int trimStop = 0; Sequence refSeq = null;// w ww.j ava 2 s.co m float minFilledRatio = 0; int expectedModelPos = -1; String[] inputFiles = null; File outdir = new File("."); try { CommandLine line = new PosixParser().parse(options, args); if (line.hasOption("ref-seq")) { refSeq = readRefSeq(new File(line.getOptionValue("ref-seq"))); } if (line.hasOption("inclusive")) { inclusive = true; } if (line.hasOption("length")) { minLength = Integer.valueOf(line.getOptionValue("length")); } if (line.hasOption("filled-ratio")) { minFilledRatio = Float.valueOf(line.getOptionValue("filled-ratio")); } if (line.hasOption("out")) { outdir = new File(line.getOptionValue("out")); if (!outdir.isDirectory()) { outdir = outdir.getParentFile(); System.err.println("Output option is not a directory, using " + outdir + " instead"); } } if (line.hasOption("stats")) { statsOut = new PrintWriter(line.getOptionValue("stats")); } args = line.getArgs(); if (args.length < 3) { throw new Exception("Unexpected number of arguments"); } trimStart = Integer.parseInt(args[0]); trimStop = Integer.parseInt(args[1]); inputFiles = Arrays.copyOfRange(args, 2, args.length); if (refSeq != null) { expectedModelPos = SeqUtils.getMaskedBySeqString(refSeq.getSeqString()).length(); trimStart = translateCoord(trimStart, refSeq, CoordType.seq, CoordType.model); trimStop = translateCoord(trimStop, refSeq, CoordType.seq, CoordType.model); } } catch (Exception e) { new HelpFormatter().printHelp("SequenceTrimmer <trim start> <trim stop> <aligned file> ...", options); System.err.println("Error: " + e.getMessage()); } System.err.println("Starting sequence trimmer"); System.err.println("* Input files: " + Arrays.asList(inputFiles)); System.err.println("* Minimum Length: " + minLength); System.err.println("* Trim point inclusive?: " + inclusive); System.err.println("* Trim points: " + trimStart + "-" + trimStop); System.err.println("* Min filled ratio: " + minFilledRatio); System.err.println("* refSeq: " + ((refSeq == null) ? "model" : refSeq.getSeqName() + " " + refSeq.getDesc())); Sequence seq; SeqReader reader; TrimStats stats; writeStatsHeader(statsOut); FastaWriter seqWriter; File in; for (String infile : inputFiles) { in = new File(infile); reader = new SequenceReader(in); seqWriter = new FastaWriter(new File(outdir, "trimmed_" + in.getName())); while ((seq = reader.readNextSequence()) != null) { if (seq.getSeqName().startsWith("#")) { seqWriter.writeSeq(seq.getSeqName(), "", trimMetaSeq(seq.getSeqString(), trimStart, trimStop)); continue; } stats = getStats(seq, trimStart, trimStop); boolean passed = didSeqPass(stats, minLength, minTrimmedLength, maxNs, maxTrimNs, minFilledRatio); writeStats(statsOut, seq.getSeqName(), stats, passed); if (passed) { seqWriter.writeSeq(seq.getSeqName(), seq.getDesc(), new String(stats.trimmedBases)); } } reader.close(); seqWriter.close(); } statsOut.close(); }
From source file:Main.java
public static Bitmap resizeImage(Bitmap image, int maxWidth, int maxHeight) { Log.d(TAG, "[AirImagePickerUtils] Entering resizeImage: " + String.valueOf(maxWidth) + " x " + String.valueOf(maxHeight)); Bitmap result = image;/*from ww w . jav a2 s . c o m*/ // make sure that the image has the correct height if (image.getWidth() > maxWidth || image.getHeight() > maxHeight && maxWidth != -1 && maxHeight != -1) { float reductionFactor = Math.max(Float.valueOf(image.getWidth()) / maxWidth, Float.valueOf(image.getHeight()) / maxHeight); result = Bitmap.createScaledBitmap(image, (int) (image.getWidth() / reductionFactor), (int) (image.getHeight() / reductionFactor), true); Log.d(TAG, "[AirImagePickerUtils] resized image to: " + String.valueOf(result.getWidth()) + " x " + String.valueOf(result.getHeight())); } Log.d(TAG, "[AirImagePickerUtils] Exiting resizeImage"); return result; }