List of usage examples for java.lang Float valueOf
@HotSpotIntrinsicCandidate public static Float valueOf(float f)
From source file:Main.java
public static float asFloat(Object node, String key, float def) { Object value;/*from w w w. j a v a 2s . c o m*/ if ((node instanceof HashMap<?, ?>) && ((value = ((HashMap<?, ?>) node).get(key)) != null)) { if (value instanceof Number) { return ((Number) value).floatValue(); } else { try { return Float.valueOf(value.toString()); } catch (NumberFormatException ex) { return def; } } } else { return def; } }
From source file:DIA_Umpire_SE.DIA_Umpire_SE.java
/** * @param args the command line arguments DIA_Umpire parameterfile *//* w w w . j a v a2 s.c om*/ public static void main(String[] args) throws InterruptedException, FileNotFoundException, ExecutionException, IOException, ParserConfigurationException, DataFormatException, SAXException, Exception { System.out.println( "================================================================================================="); System.out.println( "DIA-Umpire singal extraction analysis (version: " + UmpireInfo.GetInstance().Version + ")"); if (args.length < 2 || args.length > 3) { System.out.println( "command format error, the correct format is: java -jar -Xmx8G DIA_Umpire_SE.jar mzMXL_file diaumpire_se.params"); System.out.println( "To fix DIA setting, use : java -jar -Xmx8G DIA_Umpire_SE.jar mzMXL_file diaumpire_se.params -f"); return; } try { //Define logger level for console ConsoleLogger.SetConsoleLogger(Level.INFO); //Define logger level and file path for text log file ConsoleLogger.SetFileLogger(Level.DEBUG, FilenameUtils.getFullPath(args[0]) + "diaumpire_se.log"); } catch (Exception e) { } boolean Fix = false; boolean Resume = false; if (args.length == 3 && args[2].equals("-f")) { Fix = true; } String parameterfile = args[1]; String MSFilePath = args[0]; Logger.getRootLogger().info("Version: " + UmpireInfo.GetInstance().Version); Logger.getRootLogger().info("Parameter file:" + parameterfile); Logger.getRootLogger().info("Spectra file:" + MSFilePath); BufferedReader reader = new BufferedReader(new FileReader(parameterfile)); String line = ""; InstrumentParameter param = new InstrumentParameter(InstrumentParameter.InstrumentType.TOF5600); param.DetermineBGByID = false; param.EstimateBG = true; int NoCPUs = 2; SpectralDataType.DataType dataType = SpectralDataType.DataType.DIA_F_Window; String WindowType = ""; int WindowSize = 25; ArrayList<XYData> WindowList = new ArrayList<>(); boolean ExportPrecursorPeak = false; boolean ExportFragmentPeak = false; //<editor-fold defaultstate="collapsed" desc="Read parameter file"> while ((line = reader.readLine()) != null) { Logger.getRootLogger().info(line); if (!"".equals(line) && !line.startsWith("#")) { //System.out.println(line); if (line.equals("==window setting begin")) { while (!(line = reader.readLine()).equals("==window setting end")) { if (!"".equals(line)) { WindowList.add(new XYData(Float.parseFloat(line.split("\t")[0]), Float.parseFloat(line.split("\t")[1]))); } } continue; } if (line.split("=").length < 2) { continue; } String type = line.split("=")[0].trim(); if (type.startsWith("para.")) { type = type.replace("para.", "SE."); } String value = line.split("=")[1].trim(); switch (type) { case "Thread": { NoCPUs = Integer.parseInt(value); break; } case "ExportPrecursorPeak": { ExportPrecursorPeak = Boolean.parseBoolean(value); break; } case "ExportFragmentPeak": { ExportFragmentPeak = Boolean.parseBoolean(value); break; } //<editor-fold defaultstate="collapsed" desc="instrument parameters"> case "RPmax": { param.PrecursorRank = Integer.parseInt(value); break; } case "RFmax": { param.FragmentRank = Integer.parseInt(value); break; } case "CorrThreshold": { param.CorrThreshold = Float.parseFloat(value); break; } case "DeltaApex": { param.ApexDelta = Float.parseFloat(value); break; } case "RTOverlap": { param.RTOverlapThreshold = Float.parseFloat(value); break; } case "BoostComplementaryIon": { param.BoostComplementaryIon = Boolean.parseBoolean(value); break; } case "AdjustFragIntensity": { param.AdjustFragIntensity = Boolean.parseBoolean(value); break; } case "SE.MS1PPM": { param.MS1PPM = Float.parseFloat(value); break; } case "SE.MS2PPM": { param.MS2PPM = Float.parseFloat(value); break; } case "SE.SN": { param.SNThreshold = Float.parseFloat(value); break; } case "SE.MS2SN": { param.MS2SNThreshold = Float.parseFloat(value); break; } case "SE.MinMSIntensity": { param.MinMSIntensity = Float.parseFloat(value); break; } case "SE.MinMSMSIntensity": { param.MinMSMSIntensity = Float.parseFloat(value); break; } case "SE.MinRTRange": { param.MinRTRange = Float.parseFloat(value); break; } case "SE.MaxNoPeakCluster": { param.MaxNoPeakCluster = Integer.parseInt(value); param.MaxMS2NoPeakCluster = Integer.parseInt(value); break; } case "SE.MinNoPeakCluster": { param.MinNoPeakCluster = Integer.parseInt(value); param.MinMS2NoPeakCluster = Integer.parseInt(value); break; } case "SE.MinMS2NoPeakCluster": { param.MinMS2NoPeakCluster = Integer.parseInt(value); break; } case "SE.MaxCurveRTRange": { param.MaxCurveRTRange = Float.parseFloat(value); break; } case "SE.Resolution": { param.Resolution = Integer.parseInt(value); break; } case "SE.RTtol": { param.RTtol = Float.parseFloat(value); break; } case "SE.NoPeakPerMin": { param.NoPeakPerMin = Integer.parseInt(value); break; } case "SE.StartCharge": { param.StartCharge = Integer.parseInt(value); break; } case "SE.EndCharge": { param.EndCharge = Integer.parseInt(value); break; } case "SE.MS2StartCharge": { param.MS2StartCharge = Integer.parseInt(value); break; } case "SE.MS2EndCharge": { param.MS2EndCharge = Integer.parseInt(value); break; } case "SE.NoMissedScan": { param.NoMissedScan = Integer.parseInt(value); break; } case "SE.Denoise": { param.Denoise = Boolean.valueOf(value); break; } case "SE.EstimateBG": { param.EstimateBG = Boolean.valueOf(value); break; } case "SE.RemoveGroupedPeaks": { param.RemoveGroupedPeaks = Boolean.valueOf(value); break; } case "SE.MinFrag": { param.MinFrag = Integer.parseInt(value); break; } case "SE.IsoPattern": { param.IsoPattern = Float.valueOf(value); break; } case "SE.StartRT": { param.startRT = Float.valueOf(value); break; } case "SE.EndRT": { param.endRT = Float.valueOf(value); break; } case "SE.RemoveGroupedPeaksRTOverlap": { param.RemoveGroupedPeaksRTOverlap = Float.valueOf(value); break; } case "SE.RemoveGroupedPeaksCorr": { param.RemoveGroupedPeaksCorr = Float.valueOf(value); break; } case "SE.MinMZ": { param.MinMZ = Float.valueOf(value); break; } case "SE.MinPrecursorMass": { param.MinPrecursorMass = Float.valueOf(value); break; } case "SE.MaxPrecursorMass": { param.MaxPrecursorMass = Float.valueOf(value); break; } case "SE.IsoCorrThreshold": { param.IsoCorrThreshold = Float.valueOf(value); break; } case "SE.MassDefectFilter": { param.MassDefectFilter = Boolean.parseBoolean(value); break; } case "SE.MassDefectOffset": { param.MassDefectOffset = Float.valueOf(value); break; } //</editor-fold>//</editor-fold> case "WindowType": { WindowType = value; switch (WindowType) { case "SWATH": { dataType = SpectralDataType.DataType.DIA_F_Window; break; } case "V_SWATH": { dataType = SpectralDataType.DataType.DIA_V_Window; break; } case "MSX": { dataType = SpectralDataType.DataType.MSX; break; } case "MSE": { dataType = SpectralDataType.DataType.MSe; break; } } break; } case "WindowSize": { WindowSize = Integer.parseInt(value); break; } } } } //</editor-fold> try { File MSFile = new File(MSFilePath); if (MSFile.exists()) { long time = System.currentTimeMillis(); Logger.getRootLogger().info( "================================================================================================="); Logger.getRootLogger().info("Processing " + MSFilePath + "...."); //Initialize a DIA file data structure DIAPack DiaFile = new DIAPack(MSFile.getAbsolutePath(), NoCPUs); DiaFile.Resume = Resume; DiaFile.SetDataType(dataType); DiaFile.SetParameter(param); //Set DIA isolation window setting if (dataType == SpectralDataType.DataType.DIA_F_Window) { DiaFile.SetWindowSize(WindowSize); } else if (dataType == SpectralDataType.DataType.DIA_V_Window) { for (XYData window : WindowList) { DiaFile.AddVariableWindow(window); } } DiaFile.SaveDIASetting(); DiaFile.SaveParams(); if (Fix) { DiaFile.FixScanidx(); return; } DiaFile.ExportPrecursorPeak = ExportPrecursorPeak; DiaFile.ExportFragmentPeak = ExportFragmentPeak; Logger.getRootLogger().info("Module A: Signal extraction"); //Start DIA signal extraction process to generate pseudo MS/MS files DiaFile.process(); time = System.currentTimeMillis() - time; Logger.getRootLogger().info(MSFilePath + " processed time:" + String.format("%d hour, %d min, %d sec", TimeUnit.MILLISECONDS.toHours(time), TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)), TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time)))); } else { throw new RuntimeException("file: " + MSFile + "? does not exist!"); } Logger.getRootLogger().info("Job complete"); Logger.getRootLogger().info( "================================================================================================="); } catch (Exception e) { Logger.getRootLogger().error(ExceptionUtils.getStackTrace(e)); throw e; } }
From source file:Main.java
private static Object readThisPrimitiveValueXml(XmlPullParser parser, String tagName) throws XmlPullParserException { try {/* ww w . j a v a 2 s . c o m*/ switch (tagName) { case "int": return Integer.parseInt(parser.getAttributeValue(null, "value")); case "long": return Long.valueOf(parser.getAttributeValue(null, "value")); case "float": return Float.valueOf(parser.getAttributeValue(null, "value")); case "double": return Double.valueOf(parser.getAttributeValue(null, "value")); case "boolean": return Boolean.valueOf(parser.getAttributeValue(null, "value")); default: return null; } } catch (NullPointerException e) { throw new XmlPullParserException("Need value attribute in <" + tagName + ">"); } catch (NumberFormatException e) { throw new XmlPullParserException("Not a number in value attribute in <" + tagName + ">"); } }
From source file:Main.java
public static Object typeConversion(Class<?> cls, String str) { Object obj = null;//from w w w . ja v a 2 s. co m String nameType = cls.getSimpleName(); if ("Integer".equals(nameType)) { obj = Integer.valueOf(str); } if ("String".equals(nameType)) { obj = str; } if ("Float".equals(nameType)) { obj = Float.valueOf(str); } if ("Double".equals(nameType)) { obj = Double.valueOf(str); } if ("Boolean".equals(nameType)) { obj = Boolean.valueOf(str); } if ("Long".equals(nameType)) { obj = Long.valueOf(str); } if ("Short".equals(nameType)) { obj = Short.valueOf(str); } if ("Character".equals(nameType)) { obj = str.charAt(1); } return obj; }
From source file:PrimitiveUtils.java
public static Object read(String value, Class type) { Object ret = value;/* w w w . ja v a 2 s .c o m*/ if (Integer.TYPE.equals(type)) { ret = Integer.valueOf(value); } if (Byte.TYPE.equals(type)) { ret = Byte.valueOf(value); } if (Short.TYPE.equals(type)) { ret = Short.valueOf(value); } if (Long.TYPE.equals(type)) { ret = Long.valueOf(value); } if (Float.TYPE.equals(type)) { ret = Float.valueOf(value); } if (Double.TYPE.equals(type)) { ret = Double.valueOf(value); } if (Boolean.TYPE.equals(type)) { ret = Boolean.valueOf(value); } if (Character.TYPE.equals(type)) { ret = value.charAt(0); } // TODO others. return ret; }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T parse(Class<T> type, String stringValue) throws IllegalArgumentException { if (type.equals(String.class)) { return (T) stringValue; }/*w w w .jav a 2s . c o m*/ if (type.equals(Boolean.class) || type.equals(boolean.class)) { return (T) Boolean.valueOf(stringValue); } try { if (type.equals(Integer.class) || type.equals(int.class)) { return (T) Integer.valueOf(stringValue); } if (type.equals(Long.class) || type.equals(long.class)) { return (T) Long.valueOf(stringValue); } if (type.equals(Short.class) || type.equals(short.class)) { return (T) Short.valueOf(stringValue); } if (type.equals(Byte.class) || type.equals(byte.class)) { return (T) Byte.valueOf(stringValue); } if (type.equals(Double.class) || type.equals(double.class)) { return (T) Double.valueOf(stringValue); } if (type.equals(Float.class) || type.equals(float.class)) { return (T) Float.valueOf(stringValue); } if (type.equals(File.class)) { return (T) new File(stringValue); } } catch (final NumberFormatException e) { throw new IllegalArgumentException(e.getMessage(), e); } if (type.isEnum()) { @SuppressWarnings("rawtypes") final Class enumType = type; return (T) Enum.valueOf(enumType, stringValue); } throw new IllegalArgumentException("Can't handle type " + type); }
From source file:Main.java
public static int compareAsDouble(String str1, String str2) { float v1 = Float.valueOf(str1); float v2 = Float.valueOf(str2); if (v1 > v2) { return 1; } else if (v1 < v2) { return -1; } else//w w w. j a v a 2 s . c o m return 0; }
From source file:ImageUtil.java
public static ByteArrayOutputStream fit(ByteArrayInputStream bais, int width, int height) throws IOException { BufferedImage src = ImageIO.read(bais); int newWidth; int newHeight; Float scale;//from w w w .ja v a 2 s .c o m if (src.getWidth() > src.getHeight()) { scale = Float.valueOf(width) / Float.valueOf(src.getWidth()); } else { scale = Float.valueOf(height) / Float.valueOf(src.getHeight()); } newWidth = Float.valueOf(src.getWidth() * scale).intValue(); newHeight = Float.valueOf(src.getHeight() * scale).intValue(); // System.out.println("--- " + src.getWidth() + " - " + width); // System.out.println("--- " + src.getHeight() + " - " + height); // System.out.println("--- " + scale + " -- " + Float.valueOf(src.getWidth() * scale).intValue() + " -- " + Float.valueOf(src.getHeight() * scale).intValue()); BufferedImage temp = scale(src, newWidth, newHeight); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(temp, "JPG", baos); return baos; }
From source file:FileUtils.java
/** * Returns a human-readable version of the file size, where the input * represents a specific number of bytes. * //w w w .ja va2 s. c o m * @param size * the number of bytes * @return a human-readable display value (includes units in binary powers) * http://en.wikipedia.org/wiki/MiB */ public static String byteCountToDisplaySize(long size) { String displaySize; if (size / ONE_GB > 0) { float value = Float.valueOf(size).floatValue() / Float.valueOf(ONE_GB).floatValue(); displaySize = String.valueOf(Round(value, 2)) + " GiB"; } else if (size / ONE_MB > 0) { float value = Float.valueOf(size).floatValue() / Float.valueOf(ONE_MB).floatValue(); displaySize = String.valueOf(Round(value, 2)) + " MiB"; } else if (size / ONE_KB > 0) { float value = Float.valueOf(size).floatValue() / Float.valueOf(ONE_KB).floatValue(); displaySize = String.valueOf(Round(value, 2)) + " KiB"; } else { displaySize = String.valueOf(size) + " bytes"; } return displaySize; }
From source file:Main.java
/** * Decodes a String into an object of the specified type. If the object * type is not supported, null will be returned. * * @param type the type of the property. * @param value the encode String value to decode. * @return the String value decoded into the specified type. * @throws Exception If decoding failed due to an error. *//* w w w . ja v a 2 s. co m*/ private static Object decode(Class type, String value) throws Exception { if (type.getName().equals("java.lang.String")) { return value; } if (type.getName().equals("boolean")) { return Boolean.valueOf(value); } if (type.getName().equals("int")) { return Integer.valueOf(value); } if (type.getName().equals("long")) { return Long.valueOf(value); } if (type.getName().equals("float")) { return Float.valueOf(value); } if (type.getName().equals("double")) { return Double.valueOf(value); } if (type.getName().equals("java.lang.Class")) { return Class.forName(value); } return null; }