List of usage examples for java.lang Math floor
public static double floor(double a)
From source file:net.solarnetwork.node.job.RandomizedCronTriggerBean.java
@Override public void setCronExpression(String cronExpression) throws ParseException { this.baseCronExpression = cronExpression; if (randomSecond) { int seconds = (int) Math.floor(Math.random() * 60); String newExpression = cronExpression.replaceAll("^\\s*\\d+(\\s+)", String.valueOf(seconds) + "$1"); if (!newExpression.equals(cronExpression)) { log.debug("Randomized seconds of cron expression set to {}", seconds); cronExpression = newExpression; }/*from w w w .j av a 2 s . c o m*/ } super.setCronExpression(cronExpression); }
From source file:edu.csun.ecs.cs.multitouchj.ui.control.Canvas.java
protected Size getAdjustedSize() { Size size = getSize();//w w w . ja v a2 s . c o m size.set((int) Math.floor(size.getWidth()), (int) Math.floor(size.getHeight())); return size; }
From source file:ddf.metrics.reporting.internal.rrd4j.RrdDumper.java
private static void dumpData(ConsolFun consolFun, String dataType, RrdDb rrdDb, String dsType, long startTime, long endTime) throws Exception { FetchRequest fetchRequest = rrdDb.createFetchRequest(consolFun, startTime, endTime); FetchData fetchData = fetchRequest.fetchData(); System.out.println("************ " + dsType + ": " + dataType + " **************"); // System.out.println(fetchData.dump()); int rrdStep = 60; // in seconds long[] timestamps = fetchData.getTimestamps(); double[] values = fetchData.getValues(0); double[] adjustedValues = new double[values.length]; for (int i = 0; i < values.length; i++) { double adjustedValue = values[i] * rrdStep; adjustedValues[i] = adjustedValue; System.out.println(getCalendarTime(timestamps[i]) + ": " + values[i] + " (adjusted value = " + adjustedValue + ", floor = " + Math.floor(adjustedValue) + ", round = " + Math.round(adjustedValue) + ")"); }//from w ww. ja va 2s .c o m System.out.println("adjustedValues.length = " + adjustedValues.length); for (int i = 0; i < adjustedValues.length; i++) { // System.out.println("adjustedValue[" + i + "] = " + adjustedValues[i]); if (adjustedValues[i] > METRICS_MAX_THRESHOLD) { System.out.println("Value [" + adjustedValues[i] + "] is an OUTLIER"); } } System.out.println("******* RRDB dump **********"); System.out.println(rrdDb.dump()); }
From source file:com.jennifer.ui.util.MathUtil.java
public static JSONArray nice(double min, double max, double ticks, boolean isNice) { double _max;/* ww w .j ava 2s .co m*/ double _min; if (min > max) { _max = min; _min = max; } else { _min = min; _max = max; } double _ticks = ticks; double _tickSpacing = 0; double _range; double _niceMin; double _niceMax; _range = (isNice) ? niceNum(_max - _min, false) : _max - _min; _tickSpacing = (isNice) ? niceNum(_range / _ticks, true) : _range / _ticks; _niceMin = (isNice) ? Math.floor(_min / _tickSpacing) * _tickSpacing : _min; _niceMax = (isNice) ? Math.floor(_max / _tickSpacing) * _tickSpacing : _max; return new JSONArray().put(_niceMin).put(_niceMax).put(_range).put(_tickSpacing); }
From source file:org.adempiere.webui.apps.graph.jfreegraph.PerformanceGraphBuilder.java
public JFreeChart createIndicatorChart(IndicatorModel model) { JFreeChart chart = null;/* w ww . j a v a 2 s.co m*/ DefaultValueDataset data = new DefaultValueDataset((float) model.goalModel.getPercent()); MeterPlot plot = new MeterPlot(data); MColorSchema colorSchema = model.goalModel.getColorSchema(); int rangeLo = 0; int rangeHi = 0; Point2D start = new Point2D.Float(0, 0); Point2D end = new Point2D.Float(50, 50); float[] dist = { 0.0f, 0.2f, 0.45f, 0.75f, 1.0f }; for (int i = 1; i <= 4; i++) { switch (i) { case 1: rangeHi = colorSchema.getMark1Percent(); break; case 2: rangeHi = colorSchema.getMark2Percent(); break; case 3: rangeHi = colorSchema.getMark3Percent(); break; case 4: rangeHi = colorSchema.getMark4Percent(); break; } if (rangeHi == 9999) rangeHi = (int) Math.floor(rangeLo * 1.5); if (rangeLo < rangeHi) { Color[] colors = { colorSchema.getColor(rangeHi).brighter().brighter(), colorSchema.getColor(rangeHi).brighter(), colorSchema.getColor(rangeHi), colorSchema.getColor(rangeHi).darker(), colorSchema.getColor(rangeHi).darker().darker() }; LinearGradientPaint p = new LinearGradientPaint(start, end, dist, colors); plot.addInterval(new MeterInterval("Normal", //label new Range(rangeLo, rangeHi), //range p, new BasicStroke(7.0f), model.dialBackground)); rangeLo = rangeHi; } } plot.setRange(new Range(0, rangeLo)); plot.setDialBackgroundPaint(model.dialBackground); plot.setUnits(""); plot.setDialShape(DialShape.CHORD); plot.setNeedlePaint(model.needleColor); plot.setTickSize(2000); plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 8)); plot.setValueFont(new Font("SansSerif", Font.BOLD, 8)); plot.setNoDataMessageFont(new Font("SansSerif", Font.BOLD, 8)); plot.setTickLabelPaint(model.tickColor); plot.setValuePaint(new Color(0.0f, 0.0f, 0.0f, 0.0f)); plot.setTickPaint(model.tickColor); // chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 9), plot, false); return chart; }
From source file:name.martingeisse.stackd.common.geometry.SectionId.java
/** * Constructor for scaling a cube-unit (x, y, z) position to cluster-size units. * @param position the cube position//from w ww.j a va 2s . com * @param clusterSize the cluster size */ public SectionId(ReadableVector3d position, ClusterSize clusterSize) { int shift = clusterSize.getShiftBits(); this.x = (int) Math.floor(position.getX()) >> shift; this.y = (int) Math.floor(position.getY()) >> shift; this.z = (int) Math.floor(position.getZ()) >> shift; }
From source file:geogebra.kernel.AlgoBinomial.java
private double Binom(double n, double r) { double INFINITY = Double.POSITIVE_INFINITY; try {/* w ww . j a v a 2s . c o m*/ if (n == 0d && r == 0d) return 1d; if (r > n / 2) r = n - r; if (n < 1d || r < 0d || n < r) return 0d; if (Math.floor(n) != n || Math.floor(r) != r) return 0d; double ncr = BinomLog(n, r); if (ncr == INFINITY) return INFINITY; // check to stop needless slow calculations // BinomLog is not exact for some values // (determined by trial and error) if (n <= 37) return ncr; //if (r<2.8+Math.exp((250-n)/100) && n<59000) return ncr; // BinomBig is more accurate but slower // (but cannot be exact if the answer has more than about 16 significant digits) return BinomBig(n, r); } catch (Exception e) { return INFINITY; } }
From source file:com.bodybuilding.argos.discovery.HystrixCommandMetrics.java
@JsonCreator HystrixCommandMetrics(@JsonProperty("name") String name, @JsonProperty("reportingHosts") Integer reportingHosts, @JsonProperty("rollingCountTimeout") Integer timedOut, @JsonProperty("rollingCountFailure") Integer failed, @JsonProperty("rollingCountSuccess") Integer success, @JsonProperty("rollingCountShortCircuited") Integer shortCircuited, @JsonProperty("rollingCountThreadPoolRejected") Integer threadPoolRejected, @JsonProperty("rollingCountSemaphoreRejected") Integer semaphoreRejected, @JsonProperty("propertyValue_metricsRollingStatisticalWindowInMilliseconds") Double rollingWindowMs) { this.name = name; this.reportingHosts = reportingHosts; this.timedOut = timedOut; this.failed = failed; this.success = success; this.shortCircuited = shortCircuited; this.rejected = threadPoolRejected; this.rejected += semaphoreRejected; // see https://github.com/Netflix/Hystrix/blob/master/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommandMetrics.java this.requests = this.failed + this.success + this.timedOut + this.rejected + this.shortCircuited; long errorCount = this.failed + this.timedOut + this.rejected + this.shortCircuited; if (this.requests > 0) { this.errorPercentage = (double) errorCount / this.requests * 100; }/*w w w. j a v a 2s. co m*/ double numberSeconds = Math.floor(rollingWindowMs / this.reportingHosts) / 1000; if (numberSeconds > 0) { this.requestRate = this.requests / numberSeconds; } if (!Double.isFinite(this.requestRate)) { this.requestRate = 0D; } if (!Double.isFinite(this.errorPercentage)) { this.errorPercentage = 0D; } }
From source file:com.galenframework.ide.model.SizeVariation.java
public List<Dimension> generateVariations() { if (end == null || iterations < 2) { return asList(start.toSeleniumDimension()); } else {//from ww w . j ava 2 s. c om List<Dimension> sizes = new LinkedList<>(); int deltaWidth = end.getWidth() - start.getWidth(); int deltaHeight = end.getHeight() - start.getHeight(); int maxDistance = Math.max(Math.abs(deltaWidth), Math.abs(deltaHeight)); int amount = Math.min(maxDistance, iterations); if (amount > 0) { int randomWidthDelta = 0; int randomHeightDelta = 0; for (int i = 0; i < amount; i++) { if (random) { randomWidthDelta = (int) (Math.random() * deltaWidth / amount); randomHeightDelta = (int) (Math.random() * deltaHeight / amount); } int w = (int) Math.floor(start.getWidth() + deltaWidth * i / amount + randomWidthDelta); int h = (int) Math.floor(start.getHeight() + deltaHeight * i / amount + randomHeightDelta); sizes.add(new Dimension(w, h)); } } else { sizes.add(new Dimension(start.getWidth(), start.getHeight())); } return sizes; } }
From source file:com.dianping.imcaptcha.strategy.WaveFilter.java
public BufferedImage filter(BufferedImage src, BufferedImage dst) { int width = src.getWidth(); int height = src.getHeight(); int type = src.getType(); WritableRaster srcRaster = src.getRaster(); originalSpace = new Rectangle(0, 0, width, height); transformedSpace = new Rectangle(0, 0, width, height); transformSpace(transformedSpace);/*from ww w . j av a 2 s . com*/ if (dst == null) { ColorModel dstCM = src.getColorModel(); dst = new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster(transformedSpace.width, transformedSpace.height), dstCM.isAlphaPremultiplied(), null); } WritableRaster dstRaster = dst.getRaster(); int[] inPixels = getRGB(src, 0, 0, width, height, null); if (interpolation == NEAREST_NEIGHBOUR) return filterPixelsNN(dst, width, height, inPixels, transformedSpace); int srcWidth = width; int srcHeight = height; int srcWidth1 = width - 1; int srcHeight1 = height - 1; int outWidth = transformedSpace.width; int outHeight = transformedSpace.height; int outX, outY; int index = 0; int[] outPixels = new int[outWidth]; float radius = srcHeight * 1.0f / 2 / (float) Math.PI; outX = transformedSpace.x; outY = transformedSpace.y; float[] out = new float[2]; for (int y = 0; y < outHeight; y++) { for (int x = 0; x < outWidth; x++) { transformInverse(outX + x, outY + y, out, radius); int srcX = (int) Math.floor(out[0]); int srcY = (int) Math.floor(out[1]); float xWeight = out[0] - srcX; float yWeight = out[1] - srcY; int nw, ne, sw, se; if (srcX >= 0 && srcX < srcWidth1 && srcY >= 0 && srcY < srcHeight1) { // Easy case, all corners are in the image int i = srcWidth * srcY + srcX; nw = inPixels[i]; ne = inPixels[i + 1]; sw = inPixels[i + srcWidth]; se = inPixels[i + srcWidth + 1]; } else { // Some of the corners are off the image nw = getPixel(inPixels, srcX, srcY, srcWidth, srcHeight); ne = getPixel(inPixels, srcX + 1, srcY, srcWidth, srcHeight); sw = getPixel(inPixels, srcX, srcY + 1, srcWidth, srcHeight); se = getPixel(inPixels, srcX + 1, srcY + 1, srcWidth, srcHeight); } outPixels[x] = ImageMath.bilinearInterpolate(xWeight, yWeight, nw, ne, sw, se); } setRGB(dst, 0, y, transformedSpace.width, 1, outPixels); } return dst; }