List of usage examples for java.util Arrays sort
public static void sort(Object[] a)
From source file:com.sixrr.metrics.ui.charts.DistributionDialog.java
private XYSeriesCollection createDistributionSeries() { final double[] strippedData = GraphUtils.stripNulls(datapoints); final XYSeries series = new XYSeries(metricName); Arrays.sort(strippedData); if (strippedData[0] != 0.0) { series.add(0.0, 0.0);// www. j av a 2 s. c o m } for (int i = 0; i < strippedData.length; i++) { int j = i + 1; while (j < strippedData.length && strippedData[i] == strippedData[j]) { i++; j++; } series.add(strippedData[i], (double) (i + 1) * 100.0 / (double) strippedData.length); } return new XYSeriesCollection(series); }
From source file:ca.nines.ise.cmd.Help.java
/** * Format a list of commands and send it to System.out. * * @throws InstantiationException/*from w w w . j av a 2 s .c om*/ * @throws IllegalAccessException */ public void listCommands() throws InstantiationException, IllegalAccessException { Formatter formatter = new Formatter(System.out); formatter.format("%n%12s %s%n%n", "command", "description"); Map<String, String> descriptions = new HashMap<>(); for (Class<?> cls : ClassIndex.getSubclasses(Command.class)) { Command cmd = (Command) cls.newInstance(); descriptions.put(cls.getSimpleName().toLowerCase(), cmd.description()); } String names[] = descriptions.keySet().toArray(new String[descriptions.size()]); Arrays.sort(names); for (String name : names) { formatter.format("%12s %s%n", name, descriptions.get(name)); } }
From source file:com.zb.app.external.wechat.service.WeiXinResponseHandler.java
/** * ????? ???/*from w ww . ja v a 2 s. com*/ * * @param signature ?? * @param timestamp * @param nonce ? * @return */ public boolean validateSignature(String signature, String timestamp, String nonce) { String[] authStrs = new String[] { weixinConfig.getToken(), timestamp, nonce }; Arrays.sort(authStrs); String validateSignature = DigestUtils.shaHex(StringUtils.join(authStrs, "")); return StringUtils.equals(signature, validateSignature); }
From source file:br.unicamp.ic.recod.gpsi.applications.gpsiTimeSeriesCreator.java
@Override public void run() throws Exception { String datasetsPath = Paths.get(super.datasetPath).getParent().getParent().toString(); System.out.println(datasetsPath); HashMap<Byte, double[][]> indicesMap = new HashMap<>(); ArrayList<double[]> entities; double[][] series; int daysCount = 0, i, dayIndex; gpsiRawDataset rawDataset;//from w ww . j ava 2 s . co m gpsiMLDataset dataset; VectorialMean vmean; Mean mean = new Mean(); File[] days, years = new File(datasetsPath).listFiles(File::isDirectory); Arrays.sort(years); for (File year : years) daysCount += 365 + (Integer.parseInt(year.getName()) % 4 == 0 ? 1 : 0); for (Byte label : classLabels) { series = new double[daysCount][descriptors.length]; for (double[] row : series) Arrays.fill(row, Double.NaN); indicesMap.put(label, series); } daysCount = 0; for (File year : years) { days = new File(year.getAbsolutePath()).listFiles(File::isDirectory); Arrays.sort(days); for (File day : days) { dayIndex = daysCount + Integer.parseInt(day.getName()) - 1; rawDataset = datasetReader.readDataset(day.getAbsolutePath() + "/", null, 0.0); rawDataset.assignFolds(new byte[] { 0 }, null, null); for (i = 0; i < descriptors.length; i++) { dataset = new gpsiMLDataset(descriptors[i]); dataset.loadTrainingSet(rawDataset.getTrainingEntities(), true); for (Byte label : classLabels) { if (!dataset.getTrainingEntities().containsKey(label)) { indicesMap.get(label)[dayIndex][i] = Double.NaN; continue; } vmean = new VectorialMean(dataset.getDimensionality()); entities = (ArrayList<double[]>) dataset.getTrainingEntities().get(label); for (double[] v : entities) vmean.increment(v); indicesMap.get(label)[dayIndex][i] = mean.evaluate(vmean.getResult()); } } } daysCount += 365 + (Integer.parseInt(year.getName()) % 4 == 0 ? 1 : 0); } for (Byte label : classLabels) stream.register(new gpsiDoubleCsvIOElement(indicesMap.get(label), names, "series/" + label + ".csv")); }
From source file:com.microsoft.tfs.core.clients.registration.ServerMap.java
public String[] getURIs() { final String[] uris = (String[]) map.keySet().toArray(new String[map.size()]); Arrays.sort(uris); return uris;//from w w w . ja va 2 s . c o m }
From source file:com.sixrr.metrics.ui.charts.DiffDistributionDialog.java
private XYSeriesCollection createDistributionSeries() { final double[] strippedDataPoints = GraphUtils.stripNulls(datapoints); final XYSeries series = new XYSeries(metricName); Arrays.sort(strippedDataPoints); if (strippedDataPoints[0] != 0.0) { series.add(0.0, 0.0);/*from w ww. j av a 2s. c om*/ } for (int i = 0; i < strippedDataPoints.length; i++) { int j = i + 1; while (j < strippedDataPoints.length && strippedDataPoints[i] == strippedDataPoints[j]) { i++; j++; } series.add(strippedDataPoints[i], (double) (i + 1) * 100.0 / (double) strippedDataPoints.length); } final XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series); final double[] strippedPrevDataPoints = GraphUtils.stripNulls(prevDatapoints); final XYSeries prevSeries = new XYSeries(MetricsReloadedBundle.message("previous") + " " + metricName); Arrays.sort(strippedPrevDataPoints); if (strippedPrevDataPoints[0] != 0.0) { prevSeries.add(0.0, 0.0); } for (int i = 0; i < strippedPrevDataPoints.length; i++) { int j = i + 1; while (j < strippedPrevDataPoints.length && strippedPrevDataPoints[i] == strippedPrevDataPoints[j]) { i++; j++; } prevSeries.add(strippedPrevDataPoints[i], (double) (i + 1) * 100.0 / (double) strippedPrevDataPoints.length); } seriesCollection.addSeries(prevSeries); return seriesCollection; }
From source file:com.sunchenbin.store.feilong.core.util.MapUtil.java
/** * map,keys,? value ?.// w ww. j av a 2 s. c o m * * @param <K> * the key type * @param <T> * the generic type * @param map * map * @param keys * key * @return keys key ? map ,null * @see java.util.Collection#toArray() * @see java.util.Arrays#sort(Object[]) */ @SuppressWarnings("unchecked") public static <K, T extends Number> T getMinValue(Map<K, T> map, K[] keys) { Map<K, T> subMap = getSubMap(map, keys); if (null == subMap) { return null; } Collection<T> values = subMap.values(); Object[] array = values.toArray(); Arrays.sort(array); return (T) array[0]; }
From source file:es.uam.eps.ir.ranksys.metrics.NDCG.java
private double idcg(UserNDCGRelevanceModel relModel) { double[] gains = relModel.getGainValues(); Arrays.sort(gains); ArrayUtils.reverse(gains);//from w ww .ja v a2 s. c o m double idcg = 0; int n = Math.min(cutoff, gains.length); for (int rank = 0; rank < n; rank++) { idcg += gains[rank] * disc.disc(rank); } return idcg; }
From source file:com.wx.iseeweather.GetPressurePlugin.GetPressure.java
private void sendFinalResult() { mSensorManager.unregisterListener(this); Arrays.sort(pressures); PluginResult result = new PluginResult(PluginResult.Status.OK, pressures[(NUMBER_OF_READINGS - 1) / 2]); result.setKeepCallback(false);//w w w .ja v a2 s . c o m callbackContext.sendPluginResult(result); }
From source file:edu.gsgp.utils.Utils.java
public static double getMedian(long[] array) { long[] auxArray = Arrays.copyOf(array, array.length); Arrays.sort(auxArray); // Even number if (auxArray.length % 2 == 0) { int secondElement = auxArray.length / 2; return (auxArray[secondElement - 1] + auxArray[secondElement]) / 2; } else {//from w w w. j a v a2s. c o m int element = (auxArray.length - 1) / 2; return auxArray[element]; } }