List of usage examples for org.apache.commons.lang.math NumberUtils min
public static float min(float[] array)
Returns the minimum value in an array.
From source file:edu.scripps.fl.curves.plot.GCurvePlot.java
protected static XYLine sampleFunctionToLine(Curve curve, FitFunction f, double start, double end, int samples) { double yValues[] = new double[samples]; double xValues[] = new double[samples]; double step = (end - start) / (double) (samples - 1); for (int i = 0; i < samples; i++) { double x = start + step * (double) i; xValues[i] = x;//from w w w.j av a 2 s. c o m double y = f.getResponse(curve, Math.pow(10, x)); yValues[i] = y; } Data xData = DataUtil.scaleWithinRange(NumberUtils.min(xValues), NumberUtils.max(xValues), xValues); Data yData = DataUtil.scaleWithinRange(NumberUtils.min(yValues), NumberUtils.max(yValues), yValues); return Plots.newXYLine(xData, yData, Color.GREEN, ""); }
From source file:com.haulmont.cuba.gui.data.aggregation.NumberAggregationHelper.java
@Nullable public Double min() { if (items.isEmpty()) { return null; }// w w w .j av a2s . c o m return NumberUtils.min(ArrayUtils.toPrimitive(items.toArray(new Double[items.size()]))); }
From source file:edu.scripps.fl.curves.plot.GCurvePlot.java
public void addCurve(Curve curve, FitFunction function) { double[] yValues = (double[]) ConvertUtils.convert(curve.getResponses(), double[].class); double curveMinY = NumberUtils.min(yValues); double curveMaxY = NumberUtils.max(yValues); this.minY = Math.min(minY, curveMinY); this.maxY = Math.min(maxY, curveMaxY); Data yData = DataUtil.scaleWithinRange(curveMinY, curveMaxY, yValues); double[] xValues = (double[]) ConvertUtils.convert(curve.getConcentrations(), double[].class); for (int ii = 0; ii < xValues.length; ii++) { double x = Math.log10(xValues[ii]); xValues[ii] = x;//from ww w . jav a 2 s .co m } double curveMinX = NumberUtils.min(xValues); double curveMaxX = NumberUtils.max(xValues); this.minX = Math.min(minX, curveMinX); this.maxX = Math.min(maxX, curveMaxX); Data xData = DataUtil.scaleWithinRange(NumberUtils.min(xValues), NumberUtils.max(xValues), xValues); String hexColor = Integer .toHexString(((java.awt.Color) drawingSupplier.getNextPaint()).getRGB() & 0x00ffffff); StringBuffer sb = new StringBuffer(); sb.append(hexColor); while (sb.length() < 6) sb.insert(0, "0"); Color color = Color.newColor(sb.toString()); XYLine line1 = Plots.newXYLine(xData, yData, getBackgroundColor(), ""); // line1.setLineStyle(LineStyle.newLineStyle(3, 1, 0)); line1.addShapeMarkers(Shape.CIRCLE, color, 5); XYLine fittedLine = sampleFunctionToLine(curve, function, curveMinX, curveMaxX, 100); // fittedLine.setLineStyle(LineStyle.newLineStyle(3, 1, 0)); fittedLine.setColor(color); lines.add(line1); lines.add(fittedLine); }
From source file:org.apache.accumulo.test.functional.BalanceInPresenceOfOfflineTableIT.java
@Test public void test() throws Exception { log.info("Test that balancing is not stopped by an offline table with outstanding migrations."); log.debug("starting test ingestion"); TestIngest.Opts opts = new TestIngest.Opts(); VerifyIngest.Opts vopts = new VerifyIngest.Opts(); ClientConfiguration conf = cluster.getClientConfig(); if (conf.getBoolean(ClientProperty.INSTANCE_RPC_SASL_ENABLED.getKey(), false)) { opts.updateKerberosCredentials(cluster.getClientConfig()); vopts.updateKerberosCredentials(cluster.getClientConfig()); } else {//from w w w . j a v a 2s . c om opts.setPrincipal("root"); vopts.setPrincipal("root"); } vopts.rows = opts.rows = 200000; opts.setTableName(TEST_TABLE); TestIngest.ingest(connector, opts, new BatchWriterOpts()); connector.tableOperations().flush(TEST_TABLE, null, null, true); vopts.setTableName(TEST_TABLE); VerifyIngest.verifyIngest(connector, vopts, new ScannerOpts()); log.debug("waiting for balancing, up to ~5 minutes to allow for migration cleanup."); final long startTime = System.currentTimeMillis(); long currentWait = 10 * 1000; boolean balancingWorked = false; Credentials creds = new Credentials(getAdminPrincipal(), getAdminToken()); while (!balancingWorked && (System.currentTimeMillis() - startTime) < ((5 * 60 + 15) * 1000)) { Thread.sleep(currentWait); currentWait *= 2; log.debug("fetch the list of tablets assigned to each tserver."); MasterClientService.Iface client = null; MasterMonitorInfo stats = null; try { Instance instance = new ZooKeeperInstance(cluster.getClientConfig()); client = MasterClient .getConnectionWithRetry(new ClientContext(instance, creds, cluster.getClientConfig())); stats = client.getMasterStats(Tracer.traceInfo(), creds.toThrift(instance)); } catch (ThriftSecurityException exception) { throw new AccumuloSecurityException(exception); } catch (TException exception) { throw new AccumuloException(exception); } finally { if (client != null) { MasterClient.close(client); } } if (stats.getTServerInfoSize() < 2) { log.debug("we need >= 2 servers. sleeping for " + currentWait + "ms"); continue; } if (stats.getUnassignedTablets() != 0) { log.debug("We shouldn't have unassigned tablets. sleeping for " + currentWait + "ms"); continue; } long[] tabletsPerServer = new long[stats.getTServerInfoSize()]; Arrays.fill(tabletsPerServer, 0l); for (int i = 0; i < stats.getTServerInfoSize(); i++) { for (Map.Entry<String, TableInfo> entry : stats.getTServerInfo().get(i).getTableMap().entrySet()) { tabletsPerServer[i] += entry.getValue().getTablets(); } } if (tabletsPerServer[0] <= 10) { log.debug("We should have > 10 tablets. sleeping for " + currentWait + "ms"); continue; } long min = NumberUtils.min(tabletsPerServer), max = NumberUtils.max(tabletsPerServer); log.debug("Min=" + min + ", Max=" + max); if ((min / ((double) max)) < 0.5) { log.debug("ratio of min to max tablets per server should be roughly even. sleeping for " + currentWait + "ms"); continue; } balancingWorked = true; } Assert.assertTrue("did not properly balance", balancingWorked); }
From source file:org.apache.ojb.performance.PerfMain.java
private PerfResult[] prepareTestResults() { List tmp = new ArrayList(resultMap.values()); Collections.sort(tmp, new Comparator() { public int compare(Object o1, Object o2) { PerfResult r1 = (PerfResult) o1; PerfResult r2 = (PerfResult) o2; return new Long(r1.getTotalTime()).compareTo(new Long(r2.getTotalTime())); }//from w w w . j a v a 2 s. c om }); PerfResult[] results = (PerfResult[]) tmp.toArray(new PerfResult[tmp.size()]); long[][] calibration = new long[6][results.length]; for (int k = 0; k < 6; k++) { for (int i = 0; i < results.length; i++) { PerfResult result = results[i]; if (k == TEST_INSERT) calibration[TEST_INSERT][i] = result.getInsertPeriod(); if (k == TEST_FETCH) calibration[TEST_FETCH][i] = result.getFetchPeriod(); if (k == TEST_FETCH_2) calibration[TEST_FETCH_2][i] = result.getFetchSecondPeriod(); if (k == TEST_BY_IDENTITY) calibration[TEST_BY_IDENTITY][i] = result.getByIdentityPeriod(); if (k == TEST_UPDATE) calibration[TEST_UPDATE][i] = result.getUpdatePeriod(); if (k == TEST_DELETE) calibration[TEST_DELETE][i] = result.getDeletePeriod(); } } for (int k = 0; k < 6; k++) { if (k == TEST_INSERT) { long[] resultArray = calibration[TEST_INSERT]; long minimum = NumberUtils.min(resultArray); for (int i = 0; i < results.length; i++) { results[i].setInsertMinimun(minimum); } } if (k == TEST_FETCH) { long[] resultArray = calibration[TEST_FETCH]; long minimum = NumberUtils.min(resultArray); for (int i = 0; i < results.length; i++) { results[i].setFetchMinimun(minimum); } } if (k == TEST_FETCH_2) { long[] resultArray = calibration[TEST_FETCH_2]; long minimum = NumberUtils.min(resultArray); for (int i = 0; i < results.length; i++) { results[i].setFetchSecondMinimun(minimum); } } if (k == TEST_BY_IDENTITY) { long[] resultArray = calibration[TEST_BY_IDENTITY]; long minimum = NumberUtils.min(resultArray); for (int i = 0; i < results.length; i++) { results[i].setByIdentityMinimun(minimum); } } if (k == TEST_UPDATE) { long[] resultArray = calibration[TEST_UPDATE]; long minimum = NumberUtils.min(resultArray); for (int i = 0; i < results.length; i++) { results[i].setUpdateMinimun(minimum); } } if (k == TEST_DELETE) { long[] resultArray = calibration[TEST_DELETE]; long minimum = NumberUtils.min(resultArray); for (int i = 0; i < results.length; i++) { results[i].setDeleteMinimun(minimum); } } } return results; }
From source file:org.epochx.stats.StatsUtilsTest.java
/** * Tests that the value returned from minIndex is the index for the largest * value./*from ww w . jav a2 s. co m*/ */ public void testMinIndexDouble() { final double[] values = { 0.1, 0.2, 0.3, 0.4 }; assertEquals("minimum index not for the minimum value", NumberUtils.min(values), values[StatsUtils.minIndex(values)]); }
From source file:org.epochx.stats.StatsUtilsTest.java
/** * Tests that the value returned from minIndex is the index for the largest * value./*from w w w . jav a 2 s . c o m*/ */ public void testMinIndexInt() { final int[] values = { 1, 2, 3, 4 }; assertEquals("minimum index not for the minimum value", NumberUtils.min(values), values[StatsUtils.minIndex(values)]); }
From source file:org.kuali.student.enrollment.class2.acal.service.impl.AcademicCalendarViewHelperServiceImpl.java
/** * Validates the term at the given index * * @param termWrapper list of terms in an academic calendar * @param beforeSortingIndex index of the term before sorting for terms happens. * @param afterSortingIndex index of the term after sorting for terms happens. * @param acal ACal dto needed to compare the start and end date */// w ww . java 2 s .co m public void validateTerm(List<AcademicTermWrapper> termWrapper, int beforeSortingIndex, int afterSortingIndex, AcademicCalendarInfo acal) { AcademicTermWrapper termWrapperToValidate = termWrapper.get(beforeSortingIndex); String termSectionName = "term_section_line" + afterSortingIndex; String keyDateGroupSectionName = "acal-term-keydatesgroup_line" + afterSortingIndex; int index2 = 0; //Validate duplicate term name for (AcademicTermWrapper wrapper : termWrapper) { index2++; if (wrapper != termWrapperToValidate) { if (StringUtils.equalsIgnoreCase(wrapper.getName(), termWrapperToValidate.getName())) { GlobalVariables.getMessageMap().putErrorForSectionId(termSectionName, CalendarConstants.MessageKeys.ERROR_DUPLICATE_TERM_NAME, "" + NumberUtils.min(new int[] { afterSortingIndex, index2 }), "" + NumberUtils.max(new int[] { afterSortingIndex, index2 })); } } } if (!AcalCommonUtils.isValidDateRange(termWrapperToValidate.getStartDate(), termWrapperToValidate.getEndDate())) { GlobalVariables.getMessageMap().putErrorForSectionId(termSectionName, CalendarConstants.MessageKeys.ERROR_INVALID_DATE_RANGE, termWrapperToValidate.getName(), AcalCommonUtils.formatDate(termWrapperToValidate.getStartDate()), AcalCommonUtils.formatDate(termWrapperToValidate.getEndDate())); } if (!AcalCommonUtils.isDateWithinRange(acal.getStartDate(), acal.getEndDate(), termWrapperToValidate.getStartDate()) || !AcalCommonUtils.isDateWithinRange(acal.getStartDate(), acal.getEndDate(), termWrapperToValidate.getEndDate())) { GlobalVariables.getMessageMap().putWarningForSectionId(termSectionName, CalendarConstants.MessageKeys.ERROR_TERM_NOT_IN_ACAL_RANGE, termWrapperToValidate.getName()); } if (termWrapperToValidate.isSubTerm()) { if (termWrapperToValidate.getParentTermInfo() != null) { if (!AcalCommonUtils.isDateWithinRange(termWrapperToValidate.getParentTermInfo().getStartDate(), termWrapperToValidate.getParentTermInfo().getEndDate(), termWrapperToValidate.getStartDate()) || !AcalCommonUtils.isDateWithinRange( termWrapperToValidate.getParentTermInfo().getStartDate(), termWrapperToValidate.getParentTermInfo().getEndDate(), termWrapperToValidate.getEndDate())) { GlobalVariables.getMessageMap().putWarningForSectionId(termSectionName, CalendarConstants.MessageKeys.ERROR_TERM_NOT_IN_TERM_RANGE, termWrapperToValidate.getName(), termWrapperToValidate.getParentTermInfo().getName()); } } else { // Find term manually if calendar hasn't already been saved. AcademicTermWrapper parentTerm = null; for (AcademicTermWrapper term : termWrapper) { String termType = term.getTermType(); if (StringUtils.isBlank(termType)) { termType = term.getTermInfo().getTypeKey(); } if (termWrapperToValidate.getParentTerm().equals(termType)) { parentTerm = term; break; } } if (!AcalCommonUtils.isDateWithinRange(parentTerm.getStartDate(), parentTerm.getEndDate(), termWrapperToValidate.getStartDate()) || !AcalCommonUtils.isDateWithinRange(parentTerm.getStartDate(), parentTerm.getEndDate(), termWrapperToValidate.getEndDate())) { GlobalVariables.getMessageMap().putWarningForSectionId(termSectionName, CalendarConstants.MessageKeys.ERROR_TERM_NOT_IN_TERM_RANGE, termWrapperToValidate.getName(), parentTerm.getName()); } } } for (KeyDatesGroupWrapper keyDatesGroupWrapper : termWrapperToValidate.getKeyDatesGroupWrappers()) { for (KeyDateWrapper keyDateWrapper : keyDatesGroupWrapper.getKeydates()) { // Start and End Dates of the key date entry should be within the start and end dates of the term. if (!AcalCommonUtils.isDateWithinRange(termWrapperToValidate.getStartDate(), termWrapperToValidate.getEndDate(), keyDateWrapper.getStartDate()) || !AcalCommonUtils.isDateWithinRange(termWrapperToValidate.getStartDate(), termWrapperToValidate.getEndDate(), keyDateWrapper.getEndDate())) { String keyDatePath = "termWrapperList[" + beforeSortingIndex + "].keyDatesGroupWrappers[" + termWrapperToValidate.getKeyDatesGroupWrappers().indexOf(keyDatesGroupWrapper) + "].keydates[" + keyDatesGroupWrapper.getKeydates().indexOf(keyDateWrapper) + "]"; GlobalVariables.getMessageMap().putWarning(keyDatePath + ".startDate", CalendarConstants.MessageKeys.ERROR_INVALID_DATERANGE_KEYDATE, keyDateWrapper.getKeyDateNameUI(), termWrapperToValidate.getName()); } } } //Validate exam dates validateExamPeriod(termWrapperToValidate, beforeSortingIndex, afterSortingIndex); }
From source file:org.zebrafish.util.ChartHelper.java
/** * Scales the given array automatically. * //ww w . j ava2s. c om * @param array the array needed to be scaled * @param start the start of the range * @param end the end of the range * @return an scaled array */ public static float[] autoDataScale(float[] array, int start, int end) { if (ArrayUtils.isEmpty(array)) { return array; } float max = NumberUtils.max(array); float min = NumberUtils.min(array); int offset = 0; if (max > end || min < start) { // Sets an offset if (min < start) { offset = Math.abs((int) Math.floor(min)); } float scale = (float) ((end - start) / (Math.ceil(max) - (min >= start ? start : Math.floor(min)))); float[] newArray = new float[array.length]; for (int i = 0; i < array.length; i++) { newArray[i] = (array[i] + offset) * (scale >= 1 ? 1 : scale); } return newArray; } return array; }