List of usage examples for java.util Arrays sort
public static void sort(Object[] a)
From source file:fi.smaa.libror.RandomUtil.java
/** * Creates random numbers that sum to 1.0 and are sorted in ascending order. * // w w w .ja va 2s.com * @param dest the destination array to create the random numbers to * @throws NullPointerException if dest == null */ public static void createSumToOneSorted(double[] dest) throws NullPointerException { createSumToOneRand(dest); Arrays.sort(dest); }
From source file:com.sudarmuthu.android.feedstats.utils.StatsGraphHandler.java
/** * Load the default graph/*w w w. ja v a 2 s. c o m*/ */ public void loadGraph() { JSONArray data = new JSONArray(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Object[] key = mStats.keySet().toArray(); Arrays.sort(key); // keys should be sorted, otherwise the graph will not work properly. for (int i = 0; i < key.length; i++) { JSONArray entry = new JSONArray(); try { entry.put(formatter.parse(key[i] + " 00:00:00").getTime()); } catch (ParseException e) { Log.d(this.getClass().getSimpleName(), "Some problem in parsing dates"); e.printStackTrace(); } entry.put(Integer.parseInt(mStats.get(key[i]))); data.put(entry); } loadGraph(data); }
From source file:com.semagia.mql.tolog.TestXSLOptimizer.java
@Parameters(name = "{index}: {0}") public static Iterable<Object[]> makeTestCases() { JSONTokener tokener = new JSONTokener( TestXSLOptimizer.class.getResourceAsStream("/xsltests/tolog/query2optimizers.json")); JSONObject root = new JSONObject(tokener); Object[][] res = new Object[root.length()][2]; @SuppressWarnings("unchecked") String[] keys = ((Set<String>) root.keySet()).toArray(new String[root.length()]); Arrays.sort(keys); for (int i = 0; i < keys.length; i++) { res[i][0] = keys[i];/* w w w . j av a 2 s .c o m*/ JSONArray arr = root.getJSONArray(keys[i]); String[] values = new String[arr.length() + 1]; values[0] = "query-c14n"; for (int j = 0; j < arr.length(); j++) { values[j + 1] = arr.getString(j); } res[i][1] = values; } return Arrays.asList(res); }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Sort.java
/** * Sorts values statelessly in order given by enumeration * @param v1 the values to sort (a native backed array) * @param d the direction in which the sorted array should be returned (based on {@link direction}) * @return tmp the sorted values//from w w w . ja v a 2 s. co m */ public static int[] stateless(int[] v1, direction d) { Validate.notNull(v1); int[] tmp = Arrays.copyOf(v1, v1.length); Arrays.sort(tmp); switch (d) { case ascend: break; case descend: Reverse.inPlace(tmp); } return tmp; }
From source file:edu.gsgp.utils.Utils.java
public static double getMedian(double[] array) { double[] 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 . ja v a 2 s .co m*/ int element = (auxArray.length - 1) / 2; return auxArray[element]; } }
From source file:ching.icecreaming.action.TimeZones.java
@Action(value = "time-zones", results = { @Result(name = "success", location = "json.jsp") }) public String execute() { String[] array1 = TimeZone.getAvailableIDs(); List<String> list1 = Arrays.asList(array1); Arrays.sort(array1); Map<String, List<String>> map0 = new HashMap<String, List<String>>(); map0.put("timeZones", list1); Gson gson = new GsonBuilder().create(); jsonData = gson.toJson(map0);/* w ww . j a va2 s. c om*/ return SUCCESS; }
From source file:io.apiman.test.common.mock.EchoServlet.java
/** * Create an echo response from the inbound information in the http server * request.//from w ww . j a v a2 s .c o m * @param request the request * @param withBody if request is with body * @return a new echo response */ public static EchoResponse response(HttpServletRequest request, boolean withBody) { EchoResponse response = new EchoResponse(); response.setMethod(request.getMethod()); if (request.getQueryString() != null) { String[] normalisedQueryString = request.getQueryString().split("&"); Arrays.sort(normalisedQueryString); response.setResource( request.getRequestURI() + "?" + SimpleStringUtils.join("&", normalisedQueryString)); } else { response.setResource(request.getRequestURI()); } response.setUri(request.getRequestURI()); Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = headerNames.nextElement(); String value = request.getHeader(name); response.getHeaders().put(name, value); } if (withBody) { long totalBytes = 0; InputStream is = null; try { is = request.getInputStream(); MessageDigest sha1 = MessageDigest.getInstance("SHA1"); byte[] data = new byte[1024]; int read; while ((read = is.read(data)) != -1) { sha1.update(data, 0, read); totalBytes += read; } ; byte[] hashBytes = sha1.digest(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < hashBytes.length; i++) { sb.append(Integer.toString((hashBytes[i] & 0xff) + 0x100, 16).substring(1)); } String fileHash = sb.toString(); response.setBodyLength(totalBytes); response.setBodySha1(fileHash); } catch (Exception e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(is); } } return response; }
From source file:com.opengamma.analytics.math.statistics.descriptive.PartialMomentCalculator.java
/** * @param x The array of data, not null or empty * @return The partial moment/* ww w . j a va2s . co m*/ */ @Override public Double evaluate(final double[] x) { Validate.notNull(x, "x"); Validate.isTrue(x.length > 0, "x cannot be empty"); final int n = x.length; final double[] copyX = Arrays.copyOf(x, n); Arrays.sort(copyX); double sum = 0; if (_useDownSide) { int i = 0; if (copyX[i] > _threshold) { return 0.; } while (i < n && copyX[i] < _threshold) { sum += (copyX[i] - _threshold) * (copyX[i] - _threshold); i++; } return Math.sqrt(sum / i); } int i = n - 1; int count = 0; if (copyX[i] < _threshold) { return 0.; } while (i >= 0 && copyX[i] > _threshold) { sum += (copyX[i] - _threshold) * (copyX[i] - _threshold); count++; i--; } return Math.sqrt(sum / count); }
From source file:com.pureinfo.srm.reports.table.data.pinggu.ParameterSetAction.java
/** * @see com.pureinfo.ark.interaction.ActionBase#executeAction() *///from w w w. j a v a2s . com public ActionForward executeAction() throws PureException { tempOrgCode = request.getRequiredParameter("tempOrgCode", "code"); propFileName = ClassResourceUtil.mapFullPath(propFileName, true); Properties prop = new Properties(); InputStream iFile = null; FileOutputStream oFile = null; try { iFile = new FileInputStream(propFileName); prop.load(iFile); String codeInSystem = prop.getProperty("parameter.org.code"); if (StringUtils.isEmpty(codeInSystem)) { codeInSystem = tempOrgCode; } else { String[] codeArr = codeInSystem.split(","); Arrays.sort(codeArr); int index = Arrays.binarySearch(codeArr, tempOrgCode); if (index < 0) { codeInSystem += "," + tempOrgCode; } } prop.setProperty("parameter.org.code", codeInSystem); Enumeration e = request.getParameterNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); if (!name.startsWith("para.")) { continue; } String value = request.getParameter(name); if (StringUtils.isEmpty(value)) { logger.debug("the value of " + name.substring(5) + " is empty.SKIP."); continue; } value = value.trim(); logger.debug("to set property:" + name.substring(5) + "with[" + value + "]"); prop.setProperty(name.substring(5), value); } oFile = new FileOutputStream(propFileName, false); prop.store(oFile, "parameter for pinggu"); // to reload properties. PureSystem.shutdown(); } catch (Exception ex) { throw new PureException(0, "", ex); } finally { try { if (iFile != null) iFile.close(); if (oFile != null) oFile.close(); prop.clear(); } catch (IOException e) { e.printStackTrace(System.err); } } return mapping.findForward("success"); }
From source file:fi.smaa.libror.RandomUtil.java
public static void createSorted(double[] dest) { for (int i = 0; i < dest.length; i++) { dest[i] = createUnif01();//from ww w .j a v a 2 s . co m } Arrays.sort(dest); }