List of usage examples for java.lang Float parseFloat
public static float parseFloat(String s) throws NumberFormatException
From source file:Main.java
public static void main(String[] args) { Float floatObject2 = Float.parseFloat("1.1F"); System.out.println(floatObject2); }
From source file:Main.java
public static void main(String[] argv) throws Exception { float f = Float.parseFloat("123.4"); System.out.println(f);//from ww w .j a va 2s .c o m }
From source file:Main.java
public static void main(String[] args) { Float fObj1 = new Float("10.64"); System.out.println(fObj1);//from ww w . ja va2s . co m Float fObj2 = Float.valueOf("10.76"); System.out.println(fObj2); float f = Float.parseFloat("7.39"); System.out.println(f); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String age = "1"; String height = "1.5"; String weight = "5.9"; int theAge = Integer.parseInt(age); float theHeight = Float.parseFloat(height); double theWeight = Double.parseDouble(weight); System.out.println("Age: " + theAge); System.out.println("Height: " + theHeight); System.out.println("Weight: " + theWeight); }
From source file:de.tum.i13.ConvertCsvToProtobuf.java
public static void main(String args[]) { try {//from ww w.ja v a 2 s .c o m LineIterator it = FileUtils.lineIterator(new File("/Users/manit/Projects/sdcbenchmark/Dataset/debscsv"), "UTF-8"); FileOutputStream out = new FileOutputStream("/Users/manit/Projects/sdcbenchmark/Dataset/debsprotobuf", true); while (it.hasNext()) { String csvLine = (String) it.next(); byte[] csvLineBytes = csvLine.getBytes(); String line = new String(csvLineBytes, StandardCharsets.UTF_8); Debs2015Protos.Taxitrip.Builder builder = Debs2015Protos.Taxitrip.newBuilder(); String[] splitted = line.split(","); builder.setMedallion(splitted[0]); builder.setHackLicense(splitted[1]); builder.setPickupDatetime(splitted[2]); builder.setDropoffDatetime(splitted[3]); builder.setTripTimeInSecs(Integer.parseInt(splitted[4])); builder.setTripDistance(Float.parseFloat(splitted[5])); builder.setPickupLongitude(Float.parseFloat(splitted[6])); builder.setPickupLatitude(Float.parseFloat(splitted[7])); builder.setDropoffLongitude(Float.parseFloat(splitted[8])); builder.setDropoffLatitude(Float.parseFloat(splitted[9])); builder.setPaymentType(splitted[10]); builder.setFareAmount(Float.parseFloat(splitted[11])); builder.setSurcharge(Float.parseFloat(splitted[12])); builder.setMtaTax(Float.parseFloat(splitted[13])); builder.setTipAmount(Float.parseFloat(splitted[14])); builder.setTollsAmount(Float.parseFloat(splitted[15])); builder.setTotalAmount(Float.parseFloat(splitted[16])); builder.build().writeDelimitedTo(out); } out.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.alibaba.simpleimage.ScaleSpeedTest.java
public static void main(String[] args) throws Exception { String method = "CSubSample"; String imgName = "large"; int times = 1000; float scale = 0.5f; String imgDir = "/src/test/resources/conf.test/simpleimage/scale"; File rootDir = null;//from w ww .j av a2 s . c o m if (args.length > 0) { rootDir = new File(args[0].trim() + imgDir); } if (args.length > 1) { method = args[1]; } if (args.length > 2) { imgName = args[2]; } if (args.length > 3) { scale = Float.parseFloat(args[3]); } if (args.length > 4) { times = Integer.parseInt(args[4]); } ScaleSpeedTest instance = new ScaleSpeedTest(); if ("JSubSample".equalsIgnoreCase(method)) { instance.doScale(rootDir, imgName, instance.new JSubSampleScaler(), times, scale); } else if ("CSubSample".equalsIgnoreCase(method)) { instance.doScale(rootDir, imgName, instance.new CSubSampleScaler(), times, scale); } else if ("Bicurbe".equalsIgnoreCase(method)) { instance.doScale(rootDir, imgName, instance.new BicurbeScaler(), times, scale); } else if ("Bicurbe2".equalsIgnoreCase(method)) { instance.doScale(rootDir, imgName, instance.new Bicube2Scaler(), times, scale); } else if ("lanczos".equalsIgnoreCase(method)) { instance.doScale(rootDir, imgName, instance.new LanczosScaler(), times, scale); } else { throw new IllegalArgumentException("Unknown alg"); } }
From source file:de.longri.cachebox3.DesktopLauncher.java
public static void main(String[] args) { System.setProperty("org.lwjgl.util.NoChecks", "false"); CommandLine cmd = getCommandLine(args); //initialize platform bitmap factory AwtGraphics.init();/*ww w . j a va2s . c o m*/ //initialize platform connector PlatformConnector.init(new DesktopPlatformConnector()); LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); config.resizable = false; config.useHDPI = true; config.samples = 10; config.width = 223; config.height = 397; config.title = "Cachebox 3.0"; config.stencil = 8; config.foregroundFPS = 30; config.backgroundFPS = 10; if (cmd.hasOption("note")) { //force note 4 layout config.width = 323; config.height = 574; } if (cmd.hasOption("scale")) { String value = cmd.getOptionValue("scale"); float scale = Float.parseFloat(value); CB.setGlobalScale(scale); config.width *= scale; config.height *= scale; } if (cmd.hasOption("gps")) { JFrame f; try { f = SimulatorMain.createFrame(); f.pack(); f.setResizable(false); f.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } initVtm(); // Don't change this LogLevel // Cachebox use the slf4j implematation for LibGdx as Log engine. // so set LogLevel on CB.class if you wont (USED_LOG_LEVEL) new LwjglApplication(new CacheboxMain(), config).setLogLevel(LwjglApplication.LOG_DEBUG); }
From source file:ktdiedrich.imagek.SegmentationCMD.java
/** * @author ktdiedrich@gmail.com/*from w w w. ja va2s.co m*/ * @param ags: [file path] [Median filter size] [imageId] * Command line segmentation * @throws org.apache.commons.cli.ParseException */ public static void main(String[] args) throws org.apache.commons.cli.ParseException { int imageIds[] = null; int medianFilterSize = 0; float seed = Extractor3D.SEED_HIST_THRES; String paths[] = null; Options options = new Options(); options.addOption("p", true, "path name to file including filename"); options.addOption("m", true, "median filter size, m*2+1"); options.addOption("i", true, "image ID"); options.addOption("f", true, "Image ID from"); options.addOption("t", true, "Image ID to, (inclusive)"); options.addOption("s", true, "Seed threshold default " + seed); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("s")) { seed = Float.parseFloat(cmd.getOptionValue("s")); } if (cmd.hasOption("i")) { imageIds = new int[1]; imageIds[0] = Integer.parseInt(cmd.getOptionValue("i")); paths = new String[1]; paths[0] = getImageIdPath(imageIds[0]); // TODO get path to image ID from database and properties file. } if (cmd.hasOption("f") && cmd.hasOption("t")) { int from = Integer.parseInt(cmd.getOptionValue("f")); int to = Integer.parseInt(cmd.getOptionValue("t")); int range = to - from + 1; paths = new String[range]; imageIds = new int[range]; for (int i = 0, imId = from; i < range; i++, imId++) { imageIds[i] = imId; paths[i] = getImageIdPath(imId); } } if (paths == null && cmd.hasOption("p")) { paths = new String[1]; paths[0] = cmd.getOptionValue("p"); } if (cmd.hasOption("m")) { medianFilterSize = Integer.parseInt(cmd.getOptionValue("m")); } // System.out.println("ImageID: "+imageId+" Path: "+paths+" Median filter: "+medianFilterSize); if (paths != null) { int i = 0; for (String path : paths) { String p[] = parseDirectoryFileName(path); String dirPath = p[0]; ImagePlus segImage = segment(path, medianFilterSize, imageIds[i], seed); String title = segImage.getShortTitle(); if (title.contains(File.separator)) ; { title = parseDirectoryFileName(title)[1]; } String outputPath = null; if (!dirPath.endsWith(File.separator)) dirPath = dirPath + File.separator; outputPath = dirPath + title + ".zip"; FileSaver fs = new FileSaver(segImage); fs.saveAsZip(outputPath); System.out.println("Saved: " + outputPath); ImagePlus mipYim = MIP.createShortMIP(segImage, MIP.Y_AXIS); fs = new FileSaver(mipYim); title = mipYim.getShortTitle(); if (title.contains(File.separator)) ; { title = parseDirectoryFileName(title)[1]; } outputPath = dirPath + title + ".png"; fs.saveAsPng(outputPath); System.out.println("Saved: " + outputPath + "\n"); i++; } } }
From source file:net.forkwait.imageautomator.ImageAutomator.java
public static void main(String[] args) throws IOException { String inputImage = ""; Options options = new Options(); options.addOption("o", true, "output file name (e.g. thumb.jpg), default thumbnail.filename.ext"); options.addOption("q", true, "jpeg quality (e.g. 0.9, max 1.0), default 0.97"); options.addOption("s", true, "output max side length in px (e.g. 800), default 1200"); options.addOption("w", true, "watermark image file"); options.addOption("wt", true, "watermark transparency (e.g. 0.5, max 1.0), default 1.0"); options.addOption("wp", true, "watermark position (e.g. 0.9, max 1.0), default BOTTOM_RIGHT"); /*/*from w ww.java 2 s. c o m*/ TOP_LEFT TOP_CENTER TOP_RIGHT CENTER_LEFT CENTER CENTER_RIGHT BOTTOM_LEFT BOTTOM_CENTER BOTTOM_RIGHT */ CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); if (cmd.getArgs().length < 1) { throw new ParseException("Too few arguments"); } else if (cmd.getArgs().length > 1) { throw new ParseException("Too many arguments"); } inputImage = cmd.getArgs()[0]; } catch (ParseException e) { showHelp(options, e.getLocalizedMessage()); System.exit(-1); } Thumbnails.Builder<File> st = Thumbnails.of(inputImage); if (cmd.hasOption("q")) { st.outputQuality(Double.parseDouble(cmd.getOptionValue("q"))); } else { st.outputQuality(0.97f); } if (cmd.hasOption("s")) { st.size(Integer.parseInt(cmd.getOptionValue("s")), Integer.parseInt(cmd.getOptionValue("s"))); } else { st.size(1200, 1200); } if (cmd.hasOption("w")) { Positions position = Positions.BOTTOM_RIGHT; float trans = 0.5f; if (cmd.hasOption("wp")) { position = Positions.valueOf(cmd.getOptionValue("wp")); } if (cmd.hasOption("wt")) { trans = Float.parseFloat(cmd.getOptionValue("wt")); } st.watermark(position, ImageIO.read(new File(cmd.getOptionValue("w"))), trans); } if (cmd.hasOption("o")) { st.toFile(new File(cmd.getOptionValue("o"))); } else { st.toFiles(Rename.PREFIX_DOT_THUMBNAIL); } //.outputFormat("jpg") System.exit(0); }
From source file:SequentialPageRank.java
@SuppressWarnings({ "static-access" })
public static void main(String[] args) throws IOException {
Options options = new Options();
options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT));
options.addOption(/*from w w w.j a va 2 s . co m*/
OptionBuilder.withArgName("val").hasArg().withDescription("random jump factor").create(JUMP));
CommandLine cmdline = null;
CommandLineParser parser = new GnuParser();
try {
cmdline = parser.parse(options, args);
} catch (ParseException exp) {
System.err.println("Error parsing command line: " + exp.getMessage());
System.exit(-1);
}
if (!cmdline.hasOption(INPUT)) {
System.out.println("args: " + Arrays.toString(args));
HelpFormatter formatter = new HelpFormatter();
formatter.setWidth(120);
formatter.printHelp(SequentialPageRank.class.getName(), options);
ToolRunner.printGenericCommandUsage(System.out);
System.exit(-1);
}
String infile = cmdline.getOptionValue(INPUT);
float alpha = cmdline.hasOption(JUMP) ? Float.parseFloat(cmdline.getOptionValue(JUMP)) : 0.15f;
int edgeCnt = 0;
DirectedSparseGraph<String, Integer> graph = new DirectedSparseGraph<String, Integer>();
BufferedReader data = new BufferedReader(new InputStreamReader(new FileInputStream(infile)));
String line;
while ((line = data.readLine()) != null) {
line.trim();
String[] arr = line.split("\\t");
for (int i = 1; i < arr.length; i++) {
graph.addEdge(new Integer(edgeCnt++), arr[0], arr[i]);
}
}
data.close();
WeakComponentClusterer<String, Integer> clusterer = new WeakComponentClusterer<String, Integer>();
Set<Set<String>> components = clusterer.transform(graph);
int numComponents = components.size();
System.out.println("Number of components: " + numComponents);
System.out.println("Number of edges: " + graph.getEdgeCount());
System.out.println("Number of nodes: " + graph.getVertexCount());
System.out.println("Random jump factor: " + alpha);
// Compute PageRank.
PageRank<String, Integer> ranker = new PageRank<String, Integer>(graph, alpha);
ranker.evaluate();
// Use priority queue to sort vertices by PageRank values.
PriorityQueue<Ranking<String>> q = new PriorityQueue<Ranking<String>>();
int i = 0;
for (String pmid : graph.getVertices()) {
q.add(new Ranking<String>(i++, ranker.getVertexScore(pmid), pmid));
}
// Print PageRank values.
System.out.println("\nPageRank of nodes, in descending order:");
Ranking<String> r = null;
while ((r = q.poll()) != null) {
System.out.println(r.rankScore + "\t" + r.getRanked());
}
}