List of usage examples for java.lang Math floor
public static double floor(double a)
From source file:MediaControl.java
private static String formatTime(Duration elapsed, Duration duration) { int intElapsed = (int) Math.floor(elapsed.toSeconds()); int elapsedHours = intElapsed / (60 * 60); if (elapsedHours > 0) { intElapsed -= elapsedHours * 60 * 60; }/*from w w w . java 2 s. co m*/ int elapsedMinutes = intElapsed / 60; int elapsedSeconds = intElapsed - elapsedHours * 60 * 60 - elapsedMinutes * 60; if (duration.greaterThan(Duration.ZERO)) { int intDuration = (int) Math.floor(duration.toSeconds()); int durationHours = intDuration / (60 * 60); if (durationHours > 0) { intDuration -= durationHours * 60 * 60; } int durationMinutes = intDuration / 60; int durationSeconds = intDuration - durationHours * 60 * 60 - durationMinutes * 60; if (durationHours > 0) { return String.format("%d:%02d:%02d/%d:%02d:%02d", elapsedHours, elapsedMinutes, elapsedSeconds, durationHours, durationMinutes, durationSeconds); } else { return String.format("%02d:%02d/%02d:%02d", elapsedMinutes, elapsedSeconds, durationMinutes, durationSeconds); } } else { if (elapsedHours > 0) { return String.format("%d:%02d:%02d", elapsedHours, elapsedMinutes, elapsedSeconds); } else { return String.format("%02d:%02d", elapsedMinutes, elapsedSeconds); } } }
From source file:gdsc.smlm.model.StandardFluorophoreSequenceModel.java
private static int nextGeometric(RandomDataGenerator rand, double mean) { // Use a geometric distribution by sampling the floor from the exponential. // Geometric distribution where k { 0, 1, 2, ... } // See: http://en.wikipedia.org/wiki/Geometric_distribution#Related_distributions final double p = 1 / (1 + mean); return (int) Math.floor(Math.log(rand.nextUniform(0, 1, true)) / Math.log(1 - p)); }
From source file:clus.heuristic.FTest.java
public static double calcVarianceReductionHeuristic(double n_tot, double ss_tot, double ss_sum) { double value = ss_tot - ss_sum; if (value < MathUtil.C1E_9) { // Gain too small return Double.NEGATIVE_INFINITY; }/*from w w w. j av a 2 s. co m*/ if (Settings.FTEST_LEVEL == 0) { // No F-test -> just return value return value; } int n_2 = (int) Math.floor(n_tot - 2.0 + 0.5); if (n_2 <= 0) { return Double.NEGATIVE_INFINITY; } else { if (FTest.ftest(Settings.FTEST_LEVEL, ss_tot, ss_sum, n_2)) { return value; } else { return Double.NEGATIVE_INFINITY; } } }
From source file:com.fengduo.bee.commons.util.StringFormatter.java
public static int getWordSizeInt(String str) { return (int) Math.floor(getWordSize(str)); }
From source file:com.itemanalysis.jmetrik.stats.descriptives.DescriptiveAnalysis.java
public void publishHeader() throws IllegalArgumentException { StringBuilder header = new StringBuilder(); Formatter f = new Formatter(header); String s1 = String.format("%1$tB %1$te, %1$tY %tT", Calendar.getInstance()); int len = 21 + Double.valueOf(Math.floor(Double.valueOf(s1.length()).doubleValue() / 2.0)).intValue(); String dString = ""; try {/*from w ww . j a v a 2 s . c o m*/ dString = command.getDataString(); } catch (IllegalArgumentException ex) { throw new IllegalArgumentException(ex); } int len2 = 21 + Double.valueOf(Math.floor(Double.valueOf(dString.length()).doubleValue() / 2.0)).intValue(); f.format("%31s", "DESCRIPTIVE STATISTICS"); f.format("%n"); f.format("%" + len2 + "s", dString); f.format("%n"); f.format("%" + len + "s", s1); f.format("%n"); f.format("%n"); publish(f.toString()); }
From source file:eu.matejkormuth.rpgdavid.starving.listeners.HiddenCommandsListener.java
@EventHandler private void onCommand(final PlayerCommandPreprocessEvent event) { // Command for listing all items. if (event.getMessage().equalsIgnoreCase("/items")) { List<Item> items = Starving.getInstance().getItemManager().getItems(); for (int j = 0; j < items.size(); j++) { Item i = items.get(j);/*from w w w .java 2 s . co m*/ event.getPlayer().sendMessage(j + " - " + i.getName()); } } // Command for giving custom items. else if (event.getMessage().contains("/itemsgive")) { List<Item> items = Starving.getInstance().getItemManager().getItems(); for (int j = 0; j < items.size(); j++) { Item i = items.get(j); if (j == Integer.valueOf(event.getMessage().split(Pattern.quote(" "))[1])) { event.getPlayer().getInventory().addItem(i.toItemStack()); } } } // Command for giving custom chemicals. else if (event.getMessage().contains("/chemical")) { if (!event.getMessage().contains(" ")) { event.getPlayer().sendMessage("args missing!"); } String args = event.getMessage().split(Pattern.quote(" "))[1]; String[] chemicals = args.split(Pattern.quote(",")); ChemicalItem ci = new ChemicalItem("spawnedChemicalItem", new ChemicalCompound()) { @Override public Recipe getRecipe() { return null; } @Override protected void onConsume0(Player player) { } }; for (String chemical : chemicals) { String[] parts = chemical.split(Pattern.quote(":")); String name = parts[0]; String amount = parts[1]; for (Chemical ch : Chemicals.all()) { if (ch.getName().equalsIgnoreCase(name)) { ci.getContents().add(ch, Float.valueOf(amount)); } } } event.getPlayer().getInventory().addItem(ci.toItemStack()); } // Command for setting entities target. else if (event.getMessage().contains("/settarget")) { String[] parts = event.getMessage().split(" "); int entity = Integer.valueOf(parts[1]); int target = Integer.valueOf(parts[2]); for (Entity e : Worlds.first().getEntities()) { if (e.getEntityId() == target) { Starving.getInstance().getZombieManager().get(entity).setFollowTarget(e); } } } // Command for spawning zombie walking the dog. else if (event.getMessage().contains("/zombieeaster")) { ZombieWithDog.spawn(event.getPlayer().getLocation()); } // Command for settings time. else if (event.getMessage().contains("/time set")) { String[] parts = event.getMessage().split(" "); int time = Integer.valueOf(parts[2]); event.getPlayer().sendMessage(ChatColor.YELLOW + "[Starving] Shifting time..."); Starving.getInstance().getRegistered(TimeUpdater.class).vanllaSetMoveTime(time); event.getPlayer().sendMessage(ChatColor.GREEN + "[Starving] Time set!"); } // Command for spawning zombie. else if (event.getMessage().contains("/zombie")) { String[] parts = event.getMessage().split(" "); if (parts.length == 2) { int count = Integer.valueOf(parts[1]); for (int i = 0; i < count; i++) { Starving.getInstance().getZombieManager().spawnAt(event.getPlayer().getLocation() .add((Math.random() - 0.5) * count / 4, 0, (Math.random() - 0.5) * count / 4)); } } else { Starving.getInstance().getZombieManager().spawnAt(event.getPlayer().getLocation()); } } // Command for testing some random things. else if (event.getMessage().contains("/darkness")) { ((CraftPlayer) event.getPlayer()).getHandle().playerConnection .sendPacket(new PacketPlayOutGameStateChange(7, 0.001f)); ((CraftPlayer) event.getPlayer()).getHandle().playerConnection .sendPacket(new PacketPlayOutGameStateChange(8, 160)); } // Command for testing some random things. else if (event.getMessage().contains("/npctest")) { String name = "debilko" + (int) Math.floor(Math.random() * 1000000); NPC npc = Starving.getInstance().getNPCManager().getMainRegistry().createPlayer() .withProfile(UUID.nameUUIDFromBytes(name.getBytes()), name) .withSpawnLocation(event.getPlayer().getLocation()).spawn(); event.getPlayer().teleport(npc.getLocation()); } // Command for generating access key. else if (event.getMessage().contains("/genkey")) { char[] VALID_CHARS = "0123456789abcdefghijklmnopqrstuvwxyz".toCharArray(); int keyLength = 32; char[] key = new char[keyLength]; for (int i = 0; i < keyLength; i++) { key[i] = VALID_CHARS[RandomUtils.nextInt(VALID_CHARS.length - 1)]; } event.getPlayer().sendMessage("Your new accesskey is: " + new String(key)); Data.of(event.getPlayer()).setRemoteAccesKey(new String(key)); event.getPlayer().sendMessage("http://starving.eu/key.php?key=" + new String(key)); } // Command for opening custom items inventory. else if (event.getMessage().contains("/itemsinv")) { ItemManager im = Starving.getInstance().getItemManager(); int size = (im.getItems().size() / 9); Inventory inv = Bukkit.createInventory(null, 9 * (size + 1), ChatColor.GOLD + "Custom items: "); List<Item> sorted = im.getItems(); Collections.sort(sorted, new ItemNameComparator()); for (Item i : sorted) { inv.addItem(i.toItemStack()); } event.getPlayer().openInventory(inv); } // Command for testing some random things. else if (event.getMessage().contains("/itemdropvehicle")) { org.bukkit.entity.Item i = ItemDrops.drop(event.getPlayer().getLocation(), Items.of(Material.APPLE)); i.setVelocity(event.getPlayer().getEyeLocation().getDirection().multiply(3)); i.setPassenger(event.getPlayer()); i.setPickupDelay(20 * 15); } // Command for testing some random things. else if (event.getMessage().contains("/peadd")) { // FIXME: Please, remove this soon. Only for testing. ParticleEmitter pe = new ParticleEmitter(new Location(Bukkit.getWorld("Beta"), 571.5, 68, -235.5), 1f, 40, ParticleEffect.SMOKE_LARGE); pe.setOffsets(0.5f, 0.1f, 0.5f); pe.setDirection(new Vector(0.1f, 0, 0.15f)); Starving.getInstance().getParticleEmmiters().add(pe); ParticleEmitter pe2 = new ParticleEmitter(new Location(Bukkit.getWorld("Beta"), 571.5, 68, -235.5), 1f, 80, ParticleEffect.REDSTONE); pe2.setOffsets(0.5f, 0.1f, 0.5f); pe2.setColor(new ParticleEffect.OrdinaryColor(255, 0, 255)); //pe2.setDirection(new Vector(0.1f, 0, 0.15f)); Starving.getInstance().getParticleEmmiters().add(pe2); } // Command for testing some random things. else if (event.getMessage().contains("/peclear")) { Starving.getInstance().getParticleEmmiters().clear(); } // Command for testing some random things. else if (event.getMessage().contains("/ason")) { Starving.getInstance().getAmbientSoundManager().addPlayer(event.getPlayer()); } // Command for testing some random things. else if (event.getMessage().contains("/asoff")) { Starving.getInstance().getAmbientSoundManager().removePlayer(event.getPlayer()); } }
From source file:edu.csun.ecs.cs.multitouchj.application.whiteboard.ui.InteractiveCanvas.java
protected void drawPoints() { synchronized (previousPoints) { synchronized (resizableBufferedImage) { // clear points for pen if it's been long since last changed long currentTime = new Date().getTime(); for (int id : pens.keySet()) { if (previousTimes.containsKey(id)) { long time = previousTimes.get(id); if ((currentTime - time) > POINT_CLEAR_DURATION) { previousPoints.remove(id); previousTimes.remove(id); }//from w ww.j av a2s.co m } } DisplayMode displayMode = getWindowManager().getDisplayManager().getCurrentDisplayMode(); BufferedImage bufferedImage = resizableBufferedImage.getBufferedImage(); Graphics2D graphics = bufferedImage.createGraphics(); for (int id : pens.keySet()) { Pen pen = pens.get(id); LinkedList<Point> points = previousPoints.get(id); if ((pen != null) && (points != null) && (points.size() > 1)) { log.debug("id: " + id + ", points: " + points.size()); Point previousPoint = points.removeFirst(); Iterator<Point> iterator = points.iterator(); while (iterator.hasNext()) { Point point = iterator.next(); if (iterator.hasNext()) { iterator.remove(); } graphics.setStroke(pen.getStroke()); graphics.setPaint(pen.getPaint()); graphics.drawLine((int) Math.floor(previousPoint.getX()), (displayMode.getHeight() - (int) Math.floor(previousPoint.getY())), (int) Math.floor(point.getX()), (displayMode.getHeight() - (int) Math.floor(point.getY()))); previousPoint = point; } setDirty(true); } } graphics.dispose(); } } }
From source file:gov.nih.nci.caintegrator.common.Cai2Util.java
/** * Used by classes to create a palette of unique colors. * @param totalNumberOfUniqueColors - total number of unique colors to be created in the palette. *///from w ww . j av a2 s .c o m public static void setColorPalette(int totalNumberOfUniqueColors) { for (int i = 0; i < MAX_ANGLE_CONSTANT; i += MAX_ANGLE_CONSTANT / totalNumberOfUniqueColors) { double colorNumberAsAngle = i * GOLDEN_ANGLE; double hue = colorNumberAsAngle - Math.floor(colorNumberAsAngle); COLOR_PALETTE.add(Color.getHSBColor((float) hue, (float) COLOR_SATURATION, (float) COLOR_BRIGHTNESS)); } }
From source file:azkaban.metric.inmemoryemitter.InMemoryMetricEmitter.java
/** * filter snapshots by evenly selecting points across the interval * @param selectedLists list of snapshots */// w ww .j a v a 2 s . c o m private void generalSelectMetricHistory(final LinkedList<InMemoryHistoryNode> selectedLists) { logger.debug("selecting snapshots evenly from across the time interval"); if (selectedLists.size() > numInstances) { double step = (double) selectedLists.size() / numInstances; long nextIndex = 0, currentIndex = 0, numSelectedInstances = 1; Iterator<InMemoryHistoryNode> ite = selectedLists.iterator(); while (ite.hasNext()) { ite.next(); if (currentIndex == nextIndex) { nextIndex = (long) Math.floor(numSelectedInstances * step + 0.5); numSelectedInstances++; } else { ite.remove(); } currentIndex++; } } }
From source file:projects.hip.exec.HrDiagram.java
/** * Update the {@link HrDiagram#hrDiagPanel}. *//*from ww w .j a va 2 s. com*/ private void updateChart() { XYSeries series = new XYSeries("Hipparcos HR diagram"); // Build a histogram of distance // Number of bins int bins = (int) Math.ceil((d_max - d_min) / d_step); // Histogram data double[] d_hist = new double[bins]; // Count the stars int n = 0; for (HipStar hipStar : hipStars) { // Get the Hipparcos magnitude and colour indices double h = hipStar.Hpmag; double bv = hipStar.bv; // double vi = hipStar.vi; // Use the parallax to correct the apparent magnitude to absolute magnitude. // Extract the parallax and error to use double p = hipStar.Plx; double sigma_p = hipStar.e_Plx; // Filter on the fractional parallax error double f = sigma_p / Math.abs(p); if (f > fMax) { continue; } // Filter out objects with no B-V index if (bv == 0.0) { continue; } // Correct to arcseconds p /= 1000; sigma_p /= 1000; // Get the distance double d = DistanceFromParallax.getDistance(p, sigma_p, method); // Filter & convert to absolute magnitude if (d > 0 && !Double.isInfinite(d)) { n++; double H = MagnitudeUtils.getAbsoluteMagnitude(d, h); series.add(bv, H); // Add to distance histogram if (d > d_min && d < d_max) { int bin = (int) Math.floor((d - d_min) / d_step); d_hist[bin]++; } } } logger.log(Level.INFO, "Plotting " + n + " Hipparcos stars."); JFreeChart hrChart = getHrChart(series); if (hrDiagPanel == null) { // Branch is used on initialisation hrDiagPanel = new ChartPanel(hrChart); } else { hrDiagPanel.setChart(hrChart); } JFreeChart dChart = getDistanceChart(d_hist); if (dDistPanel == null) { // Branch is used on initialisation dDistPanel = new ChartPanel(dChart); } else { dDistPanel.setChart(dChart); } }