List of usage examples for java.util ArrayList sort
@Override @SuppressWarnings("unchecked") public void sort(Comparator<? super E> c)
From source file:com.pros.jsontransform.sort.ArraySortAbstract.java
static void doSort(final ArrayNode arrayNode, final JsonNode sortNode, final ObjectTransformer transformer) { // move array nodes to sorted array int size = arrayNode.size(); ArrayList<JsonNode> sortedArray = new ArrayList<JsonNode>(arrayNode.size()); for (int i = 0; i < size; i++) { sortedArray.add(arrayNode.remove(0)); }/*ww w. j a v a 2 s .co m*/ // sort array sortedArray.sort(new NodeComparator(sortNode, transformer)); // move nodes back to targetArray for (int i = 0; i < sortedArray.size(); i++) { arrayNode.add(sortedArray.get(i)); } }
From source file:com.yahoo.elide.core.EntityBinding.java
/** * Convert a deque to a list.//from ww w . j ava 2s . co m * * @param deque Deque to convert * @return Deque as a list */ private static List<String> dequeToList(final Deque<String> deque) { ArrayList<String> result = new ArrayList<>(); deque.stream().forEachOrdered(result::add); result.sort(String.CASE_INSENSITIVE_ORDER); return Collections.unmodifiableList(result); }
From source file:luceneGazateer.EntryData.java
public static void produceCandidates(String indexPath, String fileName, GeoNameResolver resolver) throws IOException { BufferedReader filereader = new BufferedReader( new InputStreamReader(new FileInputStream(fileName), "UTF-8")); FileWriter ps = new FileWriter("output.txt", true); String line = ""; String testString = ""; String uri = ""; while ((line = filereader.readLine()) != null) { String[] locArgs = line.split("\t"); try {/*from w ww . j a v a 2 s . c o m*/ uri = locArgs[0]; testString = locArgs[1]; System.out.println(testString); } catch (IndexOutOfBoundsException e) { e.printStackTrace(); System.exit(-1); } ArrayList<EntryData> resolved = resolver.searchDocuments(indexPath, testString, globalDocType); resolved.sort(new Comparator<EntryData>() { @Override public int compare(EntryData e1, EntryData e2) { Double diff = e1.getScore() - e2.getScore(); if (diff < 1e-6 && diff > -1e-6) return 0; else if (diff > 0) return -1; return 1; } }); ps.write("{\"query_string\":{\"uri\":\"" + uri + "\",\"name\":\"" + testString + "\", \"candidates\":"); ps.write("["); for (int i = 0; i < resolved.size(); i++) { //for(Map.Entry<String, Double> entry : candidatesEntryList){ ps.write("{\"uri\":\"" + resolved.get(i).getId() + "\","); ps.write("\"name\":\"" + resolved.get(i).getName() + "\","); ps.write("\"score\":\"" + resolved.get(i).getScore() + "\""); if (i < resolved.size() - 1) { ps.write("},"); } else { ps.write("}"); } //System.out.println("\t" + entry.getValue() + "\t" + entry.getKey()); } ps.write("]}}\n"); ps.flush(); } }
From source file:com.pros.jsontransform.plugin.sort.ArraySortByAvgAge.java
public static void sort(final ArrayNode arrayNode, final JsonNode sortNode, final ObjectTransformer transformer) throws ObjectTransformerException { // target array does not contain age information so // we need to use the source array from transformer context to perform the sort ArrayNode sourceArray = (ArrayNode) transformer.getSourceNode(); // move source and target array nodes to sorting array int size = arrayNode.size(); ArrayList<JsonNode> sortingArray = new ArrayList<JsonNode>(arrayNode.size()); for (int i = 0; i < size; i++) { ObjectNode sortingElement = transformer.mapper.createObjectNode(); sortingElement.put("source", sourceArray.get(i)); sortingElement.put("target", arrayNode.remove(0)); sortingArray.add(sortingElement); }// w w w . j ava2s. co m // sort array sortingArray.sort(new AvgAgeComparator(sortNode)); // move nodes back to targetArray for (int i = 0; i < sortingArray.size(); i++) { arrayNode.add(sortingArray.get(i).get("target")); } }
From source file:org.briljantframework.data.Collectors.java
/** * @return an aggregator that computes the median. *//*from ww w . j av a2 s. c o m*/ public static Collector<Number, ?, Double> median() { return Collector.of(ArrayList::new, ArrayList::add, (left, right) -> { left.addAll(right); return left; }, (ArrayList<Number> list) -> { int size = list.size(); if (size == 0) { return Na.of(Double.class); } else if (size == 1) { return list.get(0).doubleValue(); } else if (size == 2) { return (list.get(0).doubleValue() + list.get(1).doubleValue()) / 2; } else { list.sort((a, b) -> Double.compare(a.doubleValue(), b.doubleValue())); int index = (size - 1) / 2; if (size % 2 == 0) { return (list.get(index).doubleValue() + list.get(index + 1).doubleValue()) / 2; } else { return list.get(index).doubleValue(); } } }); }
From source file:cool.pandora.modeller.util.ResourceList.java
/** * getResourceList./*from w w w . j a va2 s . com*/ * * @return resourceList */ public ArrayList<String> getResourceList() { try { final String resource = ModellerClient.doGetContainerResources(this.resourceContainerURI); final Model model = ModelFactory.createDefaultModel(); model.read(new ByteArrayInputStream(resource != null ? resource.getBytes() : new byte[0]), null, "TTL"); final ArrayList<String> resourceList = getChilden(model); resourceList.sort(String.CASE_INSENSITIVE_ORDER); return resourceList; } catch (final ModellerClientFailedException e) { System.out.println(getMessage(e)); } return null; }
From source file:com.yahoo.elide.jsonapi.models.Data.java
/** * Sort method using provided sort function. * * @param sortFunction comparator to sort data with *///from www . j a v a2 s . c om public void sort(Comparator<T> sortFunction) { if (values instanceof List) { ((List<T>) values).sort(sortFunction); } else { ArrayList<T> sortedList = new ArrayList<>(values); sortedList.sort(sortFunction); values.clear(); values.addAll(sortedList); } }
From source file:com.netflix.genie.core.jobs.workflow.impl.InitialSetupTask.java
/** * Helper to convert a set of tags into a string that is a suitable value for a shell environment variable. * Adds double quotes as necessary (i.e. in case of spaces, newlines), performs escaping of in-tag quotes. * Input tags are sorted to produce a deterministic output value. * @param tags a set of tags or null//from w ww . j a va2s . co m * @return a CSV string */ @VisibleForTesting String tagsToString(final Set<String> tags) { final ArrayList<String> sortedTags = new ArrayList<>(tags == null ? Collections.emptySet() : tags); // Sort tags for the sake of determinism (e.g., tests) sortedTags.sort(Comparator.naturalOrder()); final String joinedString = StringUtils.join(sortedTags, ','); // Escape quotes return StringUtils.replaceAll(StringUtils.replaceAll(joinedString, "\'", "\\\'"), "\"", "\\\""); }
From source file:org.hyperledger.fabric.sdk.ServiceDiscovery.java
private static List<SDEndorser> topNbyHeight(int required, List<SDEndorser> endorsers) { ArrayList<SDEndorser> ret = new ArrayList<>(endorsers); ret.sort(Comparator.comparingLong(SDEndorser::getLedgerHeight)); return ret.subList(Math.max(ret.size() - required, 0), ret.size()); }
From source file:com.denkbares.semanticcore.utils.ResultTableModel.java
@NotNull @Override//from ww w. j a v a 2 s . co m public Iterator<TableRow> iterator() { if (comparators.isEmpty()) { return rows.iterator(); } else { ArrayList<TableRow> tableRows = new ArrayList<>(rows); Collections.reverse(comparators); for (Comparator<TableRow> comparator : comparators) { tableRows.sort(comparator); } return tableRows.iterator(); } }