List of usage examples for java.lang Math min
@HotSpotIntrinsicCandidate public static double min(double a, double b)
From source file:TableWithPageSize.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new RowLayout(SWT.VERTICAL)); final Table table = new Table(shell, SWT.VIRTUAL | SWT.BORDER); table.addListener(SWT.SetData, new Listener() { public void handleEvent(Event event) { TableItem item = (TableItem) event.item; int index = table.indexOf(item); int start = index / PAGE_SIZE * PAGE_SIZE; int end = Math.min(start + PAGE_SIZE, table.getItemCount()); for (int i = start; i < end; i++) { item = table.getItem(i); item.setText("Item " + i); }//from w ww . j a v a 2 s .c o m } }); table.setLayoutData(new RowData(200, 200)); long t1 = System.currentTimeMillis(); table.setItemCount(COUNT); long t2 = System.currentTimeMillis(); System.out.println("Items: " + COUNT + ", Time: " + (t2 - t1) + " (ms) [page=" + PAGE_SIZE + "]"); shell.layout(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet9.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.H_SCROLL | SWT.V_SCROLL); final Composite composite = new Composite(shell, SWT.BORDER); composite.setSize(200, 400);//from ww w . j a v a 2s.com final ScrollBar hBar = shell.getHorizontalBar(); hBar.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { Point location = composite.getLocation(); location.x = -hBar.getSelection(); composite.setLocation(location); } }); final ScrollBar vBar = shell.getVerticalBar(); vBar.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { Point location = composite.getLocation(); location.y = -vBar.getSelection(); composite.setLocation(location); } }); shell.addListener(SWT.Resize, new Listener() { public void handleEvent(Event e) { Point size = composite.getSize(); Rectangle rect = shell.getClientArea(); hBar.setMaximum(size.x); vBar.setMaximum(size.y); hBar.setThumb(Math.min(size.x, rect.width)); vBar.setThumb(Math.min(size.y, rect.height)); int hPage = size.x - rect.width; int vPage = size.y - rect.height; int hSelection = hBar.getSelection(); int vSelection = vBar.getSelection(); Point location = composite.getLocation(); if (hSelection >= hPage) { if (hPage <= 0) hSelection = 0; location.x = -hSelection; } if (vSelection >= vPage) { if (vPage <= 0) vSelection = 0; location.y = -vSelection; } composite.setLocation(location); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:MinDemo.java
public static void main(String[] args) { double enrollmentPrice = 45.875; double closingPrice = 54.375; System.out.println("Your purchase price is: $" + Math.min(enrollmentPrice, closingPrice)); }
From source file:edu.berkeley.compbio.phyloutils.NearestNodeFinder.java
public static void main(String[] argv) throws IOException, NoSuchNodeException { //service.setGreengenesRawFilename(argv[0]); service.setHugenholtzFilename(argv[0]); //service.setSynonymService(NcbiTaxonomyClient.getInstance()); service.init();// w w w . j a va2s . com final int[] targetIds = IntArrayReader.read(argv[1]); int[] queryIds = IntArrayReader.read(argv[2]); final double minDistance = Double.parseDouble(argv[3]); // implement leave-one-out at any level Map<Integer, Double> results = Parallel.map(new ArrayIterator(queryIds), new Function<Integer, Double>() { public Double apply(Integer queryId) { try { double best = Double.MAX_VALUE; for (int targetId : targetIds) { double d = service.minDistanceBetween(queryId, targetId); if (d >= minDistance) { best = Math.min(best, d); } } return best; } catch (NoSuchNodeException e) { throw new Error(e); } } }); String outfileName = argv[4]; PrintWriter out = new PrintWriter(outfileName); out.println("id\tdist"); for (Map.Entry<Integer, Double> entry : results.entrySet()) { out.println(entry.getKey() + "\t" + entry.getValue()); } out.close(); }
From source file:edu.cuhk.hccl.SequenceFileWriter.java
public static void main(String[] args) throws IOException { // Check parameters if (args.length < 3) { System.out.print("Please specify three parameters!"); System.exit(-1);/*from ww w. j a va 2 s . co m*/ } File filesDir = new File(args[0]); String targetDir = args[1]; final int NUM_SPLITS = Integer.parseInt(args[2]); // Remove old target directory first FileUtils.deleteQuietly(new File(targetDir)); File[] dataFiles = filesDir.listFiles(); int total = dataFiles.length; int range = (int) Math.round(total / NUM_SPLITS + 0.5); System.out.printf("[INFO] The number of total files is %d \n.", total); for (int i = 1; i <= NUM_SPLITS; i++) { int start = (i - 1) * range; int end = Math.min(start + range, total); File[] subFiles = Arrays.copyOfRange(dataFiles, start, end); createSeqFile(subFiles, FilenameUtils.normalize(targetDir + "/" + i + ".seq")); } System.out.println("[INFO] All files have been successfully processed!"); }
From source file:Snippet107.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); Button button1 = new Button(shell, SWT.PUSH); button1.setText("Button 1"); final Sash sash = new Sash(shell, SWT.VERTICAL); Button button2 = new Button(shell, SWT.PUSH); button2.setText("Button 2"); final FormLayout form = new FormLayout(); shell.setLayout(form);//from w ww. ja v a 2 s . com FormData button1Data = new FormData(); button1Data.left = new FormAttachment(0, 0); button1Data.right = new FormAttachment(sash, 0); button1Data.top = new FormAttachment(0, 0); button1Data.bottom = new FormAttachment(100, 0); button1.setLayoutData(button1Data); final int limit = 20, percent = 50; final FormData sashData = new FormData(); sashData.left = new FormAttachment(percent, 0); sashData.top = new FormAttachment(0, 0); sashData.bottom = new FormAttachment(100, 0); sash.setLayoutData(sashData); sash.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { Rectangle sashRect = sash.getBounds(); Rectangle shellRect = shell.getClientArea(); int right = shellRect.width - sashRect.width - limit; e.x = Math.max(Math.min(e.x, right), limit); if (e.x != sashRect.x) { sashData.left = new FormAttachment(0, e.x); shell.layout(); } } }); FormData button2Data = new FormData(); button2Data.left = new FormAttachment(sash, 0); button2Data.right = new FormAttachment(100, 0); button2Data.top = new FormAttachment(0, 0); button2Data.bottom = new FormAttachment(100, 0); button2.setLayoutData(button2Data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet9.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.H_SCROLL | SWT.V_SCROLL); shell.setText("Snippet 9"); final Composite composite = new Composite(shell, SWT.BORDER); composite.setSize(700, 600);/*w w w . ja va 2s . com*/ final Color red = display.getSystemColor(SWT.COLOR_RED); composite.addPaintListener(e -> { e.gc.setBackground(red); e.gc.fillOval(5, 5, 690, 590); }); final ScrollBar hBar = shell.getHorizontalBar(); hBar.addListener(SWT.Selection, e -> { Point location = composite.getLocation(); location.x = -hBar.getSelection(); composite.setLocation(location); }); final ScrollBar vBar = shell.getVerticalBar(); vBar.addListener(SWT.Selection, e -> { Point location = composite.getLocation(); location.y = -vBar.getSelection(); composite.setLocation(location); }); shell.addListener(SWT.Resize, e -> { Point size = composite.getSize(); Rectangle rect = shell.getClientArea(); hBar.setMaximum(size.x); vBar.setMaximum(size.y); hBar.setThumb(Math.min(size.x, rect.width)); vBar.setThumb(Math.min(size.y, rect.height)); int hPage = size.x - rect.width; int vPage = size.y - rect.height; int hSelection = hBar.getSelection(); int vSelection = vBar.getSelection(); Point location = composite.getLocation(); if (hSelection >= hPage) { if (hPage <= 0) hSelection = 0; location.x = -hSelection; } if (vSelection >= vPage) { if (vPage <= 0) vSelection = 0; location.y = -vSelection; } composite.setLocation(location); }); shell.setSize(600, 500); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet372.java
public static void main(String[] args) { int maximumWidth = 200; int maximumHeight = 2000; String html = "<HTML><HEAD><TITLE>HTML Test</TITLE></HEAD><BODY>"; for (int i = 0; i < 15; i++) html += "<P>This is line " + i + "</P>"; html += "</BODY></HTML>"; Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 372"); shell.setLayout(new FillLayout()); Browser browser;/*from www. j ava 2 s . c o m*/ try { browser = new Browser(shell, SWT.NONE); } catch (SWTError e) { System.out.println("Could not instantiate Browser: " + e.getMessage()); display.dispose(); return; } browser.setText(html); browser.addProgressListener(ProgressListener.completedAdapter(event -> { // Set the display to something known to be smaller than the content shell.setSize(50, 50); browser.execute("document.getElementsByTagName(\"html\")[0].style.whiteSpace = \"nowrap\""); //$NON-NLS-1$ // Save the width to either be a decided maximum or the browser's content width plus the margin Double width = Math.min(maximumWidth, 10 + (Double) browser.evaluate("return document.body.scrollWidth;")); //$NON-NLS-1$ shell.setSize(width.intValue(), 0); browser.execute("document.getElementsByTagName(\"html\")[0].style.whiteSpace = \"normal\""); //$NON-NLS-1$ shell.layout(); // Set the height to either be a decided maximum or the browser's content height plus the margin Double height = Math.min(maximumHeight, 5 + (Double) browser.evaluate("return document.body.scrollHeight;")); //$NON-NLS-1$ shell.setSize(width.intValue(), height.intValue()); })); shell.open(); while (!shell.isDisposed()) { shell.layout(); if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet107.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 107"); Button button1 = new Button(shell, SWT.PUSH); button1.setText("Button 1"); final Sash sash = new Sash(shell, SWT.VERTICAL); Button button2 = new Button(shell, SWT.PUSH); button2.setText("Button 2"); final FormLayout form = new FormLayout(); shell.setLayout(form);/*from ww w. j a va 2s . c om*/ FormData button1Data = new FormData(); button1Data.left = new FormAttachment(0, 0); button1Data.right = new FormAttachment(sash, 0); button1Data.top = new FormAttachment(0, 0); button1Data.bottom = new FormAttachment(100, 0); button1.setLayoutData(button1Data); final int limit = 20, percent = 50; final FormData sashData = new FormData(); sashData.left = new FormAttachment(percent, 0); sashData.top = new FormAttachment(0, 0); sashData.bottom = new FormAttachment(100, 0); sash.setLayoutData(sashData); sash.addListener(SWT.Selection, e -> { Rectangle sashRect = sash.getBounds(); Rectangle shellRect = shell.getClientArea(); int right = shellRect.width - sashRect.width - limit; e.x = Math.max(Math.min(e.x, right), limit); if (e.x != sashRect.x) { sashData.left = new FormAttachment(0, e.x); shell.layout(); } }); FormData button2Data = new FormData(); button2Data.left = new FormAttachment(sash, 0); button2Data.right = new FormAttachment(100, 0); button2Data.top = new FormAttachment(0, 0); button2Data.bottom = new FormAttachment(100, 0); button2.setLayoutData(button2Data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:com.workfront.StreamClientSample.java
public static void main(String[] args) { StreamClient client = new StreamClient("http://localhost:8080/attask/api"); try {/*from w w w.ja va 2s . c om*/ // Login System.out.print("Logging in..."); JSONObject session = client.login("admin@user.attask", "user"); System.out.println("done"); // Get user System.out.print("Retrieving user..."); JSONObject user = client.get("user", session.getString("userID"), new String[] { "ID", "homeGroupID", "emailAddr" }); System.out.println("done"); // Search projects System.out.print("Searching projects..."); Map<String, Object> map = new HashMap<String, Object>(); map.put("groupID", user.getString("homeGroupID")); JSONArray results = client.search("proj", map, new String[] { "ID", "name" }); System.out.println("done"); for (int i = 0; i < Math.min(10, results.length()); i++) { System.out.println(" - " + results.getJSONObject(i).getString("name")); } // Create project System.out.print("Creating project..."); map.clear(); map.put("name", "My Project"); map.put("groupID", user.getString("homeGroupID")); JSONObject proj = client.post("proj", map); System.out.println("done"); // Get project System.out.print("Retrieving project..."); proj = client.get("proj", proj.getString("ID")); System.out.println("done"); // Edit project System.out.print("Editing project..."); map.clear(); map.put("name", "Your Project"); proj = client.put("proj", proj.getString("ID"), map); System.out.println("done"); // Delete project System.out.print("Deleting project..."); client.delete("proj", proj.getString("ID")); System.out.println("done"); // Logout System.out.print("Logging out..."); client.logout(); System.out.println("done"); } catch (StreamClientException e) { System.out.println(e.getMessage()); } catch (JSONException e) { System.out.println(e.getMessage()); } }