List of usage examples for java.util List sort
@SuppressWarnings({ "unchecked", "rawtypes" }) default void sort(Comparator<? super E> c)
From source file:com.netflix.genie.web.services.impl.JobSpecificationServiceImpl.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 w w. j a va 2 s. c om*/ * @return a CSV string */ private String tagsToString(final Set<String> tags) { final List<String> sortedTags = Lists.newArrayList(tags); // Sort tags for the sake of determinism (e.g., tests) sortedTags.sort(Comparator.naturalOrder()); final String joinedString = StringUtils.join(sortedTags, ','); // Escape quotes return RegExUtils.replaceAll(RegExUtils.replaceAll(joinedString, "\'", "\\\'"), "\"", "\\\""); }
From source file:no.ntnu.okse.web.controller.TopicController.java
/** * This method returns all topics registered in the TopicService * * @return A JSON serialization of all registered topics *//*from w w w . j a v a 2 s . c o m*/ @RequestMapping(method = RequestMethod.GET, value = GET_ALL_TOPICS) public @ResponseBody List<HashMap<String, Object>> getAlltopics() { TopicService ts = TopicService.getInstance(); SubscriptionService ss = SubscriptionService.getInstance(); HashSet<Topic> allTopics = ts.getAllTopics(); List<HashMap<String, Object>> results = new ArrayList<>(); allTopics.stream().forEach(t -> { int subscribers = ss.getAllSubscribersForTopic(t.getFullTopicString()).size(); HashMap<String, Object> topicInfo = new HashMap<String, Object>() { { put("subscribers", subscribers); put("topic", t); } }; results.add(topicInfo); }); results.sort((t1, t2) -> ((Topic) t1.get("topic")).getFullTopicString() .compareTo(((Topic) t2.get("topic")).getFullTopicString())); return results; }
From source file:com.navercorp.pinpoint.web.service.AgentInfoServiceImpl.java
private List<String> getApplicationNameList(List<Application> applications) { List<String> applicationNameList = new ArrayList<>(applications.size()); for (Application application : applications) { if (!applicationNameList.contains(application.getName())) { applicationNameList.add(application.getName()); }/*w ww . j ava2 s . c om*/ } applicationNameList.sort(Ordering.usingToString()); return applicationNameList; }
From source file:com.joyent.manta.client.MantaObjectDepthComparatorTest.java
public void verifyOrderingWithMoreSubdirectoriesDataSet() { List<MantaObject> objects = new ArrayList<>(); List<MantaObject> dirs = dirObjects(29); for (MantaObject dir : dirs) { objects.add(dir);/* w ww .j a v a2s .c o m*/ objects.addAll(fileObjects(dir, 24)); MantaObject subdir = mockDirectory(dir.getPath() + MantaClient.SEPARATOR + "subdir"); objects.add(subdir); objects.addAll(fileObjects(subdir, 3)); } Collections.shuffle(objects); objects.sort(MantaObjectDepthComparator.INSTANCE); assertOrdering(objects); }
From source file:com.coverity.report.analysis.ProtecodeSCToolProcessor.java
private List<ComponentCriticalities> makeRolledUpList(Map<String, Map<Criticality, Integer>> map, final int rollupIndex) { // Transfer the data to a list List<ComponentCriticalities> pairs = new ArrayList<>(); map.forEach((k, v) -> pairs.add(new ComponentCriticalities(k, v))); // Sort by sum pairs.sort((a, b) -> b.sum() - a.sum()); // roll up the last n - rollupIndex pairs into another pair ComponentCriticalities other = new ComponentCriticalities("Other Components", new HashMap<>()); Arrays.stream(Criticality.values()).forEach(c -> other.map.put(c, 0)); for (int i = pairs.size() - 1; i >= rollupIndex; --i) { pairs.get(i).map.forEach((k, v) -> other.map.put(k, other.map.get(k) + v)); pairs.remove(i);// ww w . j a va2s . c o m } // If other is nonempty, add it. if (other.sum() > 0) { pairs.add(other); } return pairs; }
From source file:de.upb.timok.models.PDTTA.java
@Deprecated public TimedSequence createAbnormalEventSequence(Random mutation) { // choose very unlikely sequences final TIntList eventList = new TIntArrayList(); final TDoubleList timeList = new TDoubleArrayList(); boolean choseFinalState = false; int currentState = 0; while (!choseFinalState) { final List<Transition> possibleTransitions = getTransitions(currentState, true); possibleTransitions.sort((o1, o2) -> Double.compare(o1.getProbability(), o2.getProbability())); int listIndex = 3; if (possibleTransitions.size() <= listIndex) { listIndex = possibleTransitions.size() - 1; }//from ww w . j av a 2 s .c om int tempListIndex = Math.min(3, possibleTransitions.size() - 1); if (tempListIndex != listIndex) { throw new IllegalStateException(); } final List<Transition> topThree = possibleTransitions.subList(0, listIndex); final double randomValue = mutation.nextDouble(); int chosenTransitionIndex = -1; if (randomValue <= ANOMALY_TYPE_TWO_P_1) { chosenTransitionIndex = 0; } else if (randomValue > ANOMALY_TYPE_TWO_P_1 && randomValue < ANOMALY_TYPE_TWO_P_2) { chosenTransitionIndex = 1; } else { chosenTransitionIndex = 2; } int indexToTake = chosenTransitionIndex; if (indexToTake >= topThree.size()) { indexToTake = topThree.size() - 1; } tempListIndex = Math.min(chosenTransitionIndex, topThree.size() - 1); if (tempListIndex != indexToTake) { throw new IllegalStateException(); } final Transition chosenTransition = topThree.get(indexToTake); if (chosenTransition.isStopTraversingTransition() || eventList.size() > MAX_SEQUENCE_LENGTH) { choseFinalState = true; } else { currentState = chosenTransition.getToState(); final Distribution d = transitionDistributions.get(chosenTransition.toZeroProbTransition()); if (d == null) { // just do it again with other random sampling return createAbnormalEventSequence(mutation); } final double timeValue = d.sample(1, mutation)[0]; eventList.add(chosenTransition.getSymbol()); timeList.add(timeValue); } } return new TimedSequence(eventList, timeList, ClassLabel.ANOMALY); }
From source file:com.baidu.rigel.biplatform.tesseract.node.service.impl.IsNodeServiceImpl.java
/** * //from w ww . j a va2s .co m * ???? * * @param nodeList * ? */ private void sortNodeListByFreeBlockCount(List<Node> nodeList) { if (nodeList == null || nodeList.size() == 0) { return; } nodeList.sort(new Comparator<Node>() { @Override public int compare(Node o1, Node o2) { if (o1 != null && o2 != null) { if (o1.getFreeBlockNum() > o2.getFreeBlockNum()) { return -1; } else if (o1.getFreeBlockNum() != 0 && o1.getFreeBlockNum() == o2.getFreeBlockNum()) { return 0; } else { return 1; } } else if (o1 == null && o2 != null) { return 1; } else if (o1 != null && o2 == null) { return -1; } return 0; } }); return; }
From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.OrganizerImpl.java
private List<Place> getAllPlaces() { LOGGER.debug("fetching journeys"); try {/*from w ww . j a v a2 s .com*/ List<Place> list = clusterService.getAllPlaces(); list.sort((a, b) -> { int c = a.getCountry().compareTo(b.getCountry()); if (c != 0) return c; return a.getCity().compareTo(b.getCity()); }); list.add(0, null); return list; } catch (ServiceException ex) { LOGGER.error("fetching journeys failed", ex); ErrorDialog.show(root, "Fehler beim Laden", "Reisen konnten nicht geladen werden."); return new ArrayList<>(); } }
From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.OrganizerImpl.java
private List<Journey> getAllJourneys() { LOGGER.debug("fetching journeys"); try {//from w ww. j av a 2 s .c om List<Journey> list = clusterService.getAllJourneys(); list.sort((a, b) -> a.getName().compareTo(b.getName())); list.add(0, null); return list; } catch (ServiceException ex) { LOGGER.error("fetching journeys failed", ex); InfoDialog dialog = new InfoDialog(root, "Fehler"); dialog.setError(true); dialog.setHeaderText("Fehler beim Laden"); dialog.setContentText("Reisen konnten nicht geladen werden."); dialog.showAndWait(); return new ArrayList<>(); } }
From source file:com.evolveum.midpoint.model.common.stringpolicy.ObjectValuePolicyEvaluator.java
private List<PasswordHistoryEntryType> getSortedHistoryList( PrismContainer<PasswordHistoryEntryType> historyEntries, boolean ascending) { if (historyEntries == null || historyEntries.isEmpty()) { return new ArrayList<>(); }//from ww w. j av a 2 s. c o m List<PasswordHistoryEntryType> historyEntryValues = (List<PasswordHistoryEntryType>) historyEntries .getRealValues(); historyEntryValues.sort((o1, o2) -> { XMLGregorianCalendar changeTimestampFirst = o1.getChangeTimestamp(); XMLGregorianCalendar changeTimestampSecond = o2.getChangeTimestamp(); if (ascending) { return changeTimestampFirst.compare(changeTimestampSecond); } else { return changeTimestampSecond.compare(changeTimestampFirst); } }); return historyEntryValues; }