List of usage examples for java.util List sort
@SuppressWarnings({ "unchecked", "rawtypes" }) default void sort(Comparator<? super E> c)
From source file:cc.kave.commons.pointsto.evaluation.cv.ProjectCVFoldBuilder.java
@Override public List<List<Usage>> createFolds(Map<ProjectIdentifier, List<Usage>> projectUsages) { List<ProjectIdentifier> projects = new ArrayList<>(projectUsages.keySet()); // sort projects in ascending order according to the number of usages projects.sort(new Comparator<ProjectIdentifier>() { @Override/*ww w .j a va 2s . co m*/ public int compare(ProjectIdentifier o1, ProjectIdentifier o2) { return projectUsages.get(o1).size() - projectUsages.get(o2).size(); } }); List<List<Usage>> folds = createFolds(calcAvgFoldSize(projectUsages.values())); for (int i = projects.size() - 1; i >= 0; --i) { ProjectIdentifier project = projects.get(i); List<Usage> fold = getSmallestFold(folds); fold.addAll(projectUsages.remove(project)); } shuffleUsages(folds); return folds; }
From source file:org.egov.infra.web.controller.InboxController.java
private String createInboxData(final List<StateAware> inboxStates) { final List<Inbox> inboxItems = new LinkedList<>(); inboxStates.sort(byCreatedDate()); for (final StateAware stateAware : inboxStates) { final State state = stateAware.getCurrentState(); final WorkflowTypes workflowTypes = inboxRenderServiceDeligate .getWorkflowType(stateAware.getStateType()); final Inbox inboxItem = new Inbox(); inboxItem.setId(InboxRenderService.GROUP_Y.equals(workflowTypes.getGroupYN()) ? EMPTY : state.getId() + "#" + workflowTypes.getId()); inboxItem.setDate(DATE_FORMATTER.print(new DateTime(state.getCreatedDate()))); inboxItem.setSender(state.getSenderName()); inboxItem.setTask(//from w ww . java 2 s. c om isBlank(state.getNatureOfTask()) ? workflowTypes.getDisplayName() : state.getNatureOfTask()); final String nextAction = inboxRenderServiceDeligate.getNextAction(state); inboxItem.setStatus(state.getValue() + (isBlank(nextAction) ? EMPTY : " - " + nextAction)); inboxItem.setDetails(isBlank(stateAware.getStateDetails()) ? EMPTY : stateAware.getStateDetails()); inboxItem.setLink(workflowTypes.getLink().replace(":ID", stateAware.myLinkId())); inboxItems.add(inboxItem); } return "{ \"data\":" + new GsonBuilder().create().toJson(inboxItems) + "}"; }
From source file:de.whs.poodle.controllers.instructor.InstructorStartController.java
private List<AbstractExercise> getLatestChanges(int instructorId) { /* load the latest changes for exercises and mcQuestions and * then merge both into a List<AbstractExercise> .*/ List<Exercise> exercises = exerciseRepo.getLatestExercises(instructorId, CHANGES_MAX); List<McQuestion> mcQuestions = mcQuestionRepo.getLatest(instructorId, CHANGES_MAX); // merge/*from ww w . jav a 2 s . co m*/ List<AbstractExercise> allExercises = new ArrayList<>(); allExercises.addAll(exercises); allExercises.addAll(mcQuestions); // sort allExercises.sort((a, b) -> b.getCreatedAt().compareTo(a.getCreatedAt())); // trim list to CHANGES_MAX if (allExercises.size() > CHANGES_MAX) allExercises = allExercises.subList(0, CHANGES_MAX - 1); return allExercises; }
From source file:app.Histogram.java
public void createHistogram(List<WordStatistic> was) { final String series1 = "??? "; final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); was.sort(null); for (int i = 0; i < 40; i++) { dataset.addValue(was.get(i).getFrequency(), series1, was.get(i).getWord()); }//from w w w. j a v a 2 s . c om final JFreeChart chart = ChartFactory.createBarChart( "? ?? ? ?? ?? ?", "??? ", "? ?? ?? ", dataset, PlotOrientation.VERTICAL, false, true, false); histogramDesign(chart); }
From source file:org.apache.bookkeeper.mledger.impl.EntryCacheDefaultEvictionPolicy.java
@Override public void doEviction(List<EntryCache> caches, long sizeToFree) { checkArgument(sizeToFree > 0);//from w w w . j a v a 2 s . c o m checkArgument(!caches.isEmpty()); caches.sort(reverseOrder()); long totalSize = 0; for (EntryCache cache : caches) { totalSize += cache.getSize(); } // This algorithm apply the eviction only the group of caches whose combined size reaches the // PercentOfSizeToConsiderForEviction List<EntryCache> cachesToEvict = Lists.newArrayList(); long cachesToEvictTotalSize = 0; long sizeToConsiderForEviction = (long) (totalSize * PercentOfSizeToConsiderForEviction); log.debug("Need to gather at least {} from caches", sizeToConsiderForEviction); int cacheIdx = 0; while (cachesToEvictTotalSize < sizeToConsiderForEviction) { // This condition should always be true, considering that we cannot free more size that what we have in // cache checkArgument(cacheIdx < caches.size()); EntryCache entryCache = caches.get(cacheIdx++); cachesToEvictTotalSize += entryCache.getSize(); cachesToEvict.add(entryCache); log.debug("Added cache {} with size {}", entryCache.getName(), entryCache.getSize()); } int evictedEntries = 0; long evictedSize = 0; for (EntryCache entryCache : cachesToEvict) { // To each entryCache chosen to for eviction, we'll ask to evict a proportional amount of data long singleCacheSizeToFree = (long) (sizeToFree * (entryCache.getSize() / (double) cachesToEvictTotalSize)); if (singleCacheSizeToFree == 0) { // If the size of this cache went to 0, it probably means that its entries has been removed from the // cache since the time we've computed the ranking continue; } Pair<Integer, Long> evicted = entryCache.evictEntries(singleCacheSizeToFree); evictedEntries += evicted.getLeft(); evictedSize += evicted.getRight(); } log.info("Completed cache eviction. Removed {} entries from {} caches. ({} Mb)", evictedEntries, cachesToEvict.size(), evictedSize / EntryCacheManager.MB); }
From source file:com.haulmont.cuba.core.sys.AppProperties.java
/** * @return all property names defined in the set of {@code app.properties} files and exported by the app components *//*from ww w. ja va 2 s. c om*/ public String[] getPropertyNames() { Set<String> namesSet = new HashSet<>(); for (AppComponent appComponent : appComponents.getComponents()) { namesSet.addAll(appComponent.getPropertyNames()); } namesSet.addAll(properties.keySet()); List<String> list = new ArrayList<>(namesSet); list.sort(Comparator.naturalOrder()); return list.toArray(new String[list.size()]); }
From source file:com.netflix.spinnaker.halyard.deploy.provider.v1.ProviderInterface.java
public void reapOrcaServerGroups(AccountDeploymentDetails<T> details, OrcaService orcaService) { Orca orca = connectTo(details, orcaService); Map<String, Orca.ActiveExecutions> executions = orca.getActiveExecutions(); Map<String, Integer> executionsByServerGroup = new HashMap<>(); // Record the total number of executions in each pool of orcas. executions.forEach((s, e) -> {//from w ww . j a v a2 s . com String instanceName = s.split("@")[1]; String serverGroupName = getServerGroupFromInstanceId(details, orcaService, instanceName); int count = executionsByServerGroup.getOrDefault(serverGroupName, 0); count += e.getCount(); executionsByServerGroup.put(serverGroupName, count); }); // Omit the last deployed orcas from being deleted, since they are kept around for rollbacks. List<String> allOrcas = new ArrayList<>(executionsByServerGroup.keySet()); allOrcas.sort(String::compareTo); int orcaCount = allOrcas.size(); if (orcaCount <= MAX_REMAINING_SERVER_GROUPS) { return; } allOrcas = allOrcas.subList(0, orcaCount - MAX_REMAINING_SERVER_GROUPS); for (String orcaName : allOrcas) { // TODO(lwander) consult clouddriver to ensure this orca isn't enabled if (executionsByServerGroup.get(orcaName) == 0) { DaemonTaskHandler.log("Reaping old orca instance " + orcaName); deleteServerGroup(details, orcaService, orcaName); } } }
From source file:de.mgd.simplesoundboard.dao.FileSystemSoundResourceDao.java
@Override public List<String> findSoundCategories() { List<File> files = findFilesInStorageDirectoryIfAny(this::isSoundCategory); if (files.isEmpty()) { return Collections.emptyList(); }/*ww w . java2 s. c om*/ files.sort(NameFileComparator.NAME_INSENSITIVE_COMPARATOR); return files.stream().map(File::getName).collect(Collectors.toList()); }
From source file:edu.elka.peakadvisor.model.CassandraDao.java
public List<Pair<Double, Integer>> getPricesWithTimestampRange(String name, int timestampStart, int timestampEnd) { CassandraOperations template = this.cassandraTemplate; Select selectStatement = QueryBuilder.select() //znowu nie dziala bez cydzyslowow, trzeba wszystko wybierac .from("Latest").allowFiltering(); selectStatement.where(QueryBuilder.gte("timestamp", timestampStart)); selectStatement.where(QueryBuilder.lte("timestamp", timestampEnd)); List<Latest> queryResult = template.select(selectStatement, Latest.class); queryResult.sort(new Comparator<Latest>() { @Override/*from w ww .ja v a 2s .co m*/ public int compare(Latest o1, Latest o2) { if (o1.getTimestamp() > o2.getTimestamp()) return 1; else if (o1.getTimestamp() < o2.getTimestamp()) return -1; else return 0; } }); List<Pair<Number, Integer>> list = new ArrayList<>(); queryResult.stream().map((l) -> { try { return new Pair( ((l.getRates().getClass().getMethod("get" + name.toUpperCase()).invoke(l.getRates()))), l.getTimestamp()); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } return null; }).forEach(p -> list.add(p)); List<Pair<Double, Integer>> result2 = new ArrayList<>(); // for(Pair p:list){ // result2.add(new Pair<Double, Integer>((Double) p.getKey(),(Integer) p.getValue())); // } list.stream().map((r) -> new Pair(((Double) r.getKey()).doubleValue(), ((Integer) r.getValue()).intValue())) .forEach(p -> result2.add(p)); return result2; }
From source file:org.cgiar.ccafs.marlo.action.json.global.MilestonesbyYearAction.java
@Override public String execute() throws Exception { crpMilestones = new ArrayList<Map<String, Object>>(); CrpProgramOutcome crpProgramOutcome = crpProgramManager.getCrpProgramOutcomeById(crpProgamID); List<CrpMilestone> milestones = crpProgramOutcome.getCrpMilestones().stream() .filter(c -> c.isActive() & c.getYear() >= year).collect(Collectors.toList()); milestones.sort(Comparator.comparing(CrpMilestone::getYear)); for (CrpMilestone crpMilestoneInfo : milestones) { Map<String, Object> crpMilestone = new HashMap<>(); crpMilestone.put("id", crpMilestoneInfo.getId()); crpMilestone.put("description", crpMilestoneInfo.getComposedName()); crpMilestones.add(crpMilestone); }/*from w ww .ja v a 2 s . co m*/ return SUCCESS; }