List of usage examples for java.util List sort
@SuppressWarnings({ "unchecked", "rawtypes" }) default void sort(Comparator<? super E> c)
From source file:org.egov.council.service.CouncilReportService.java
public byte[] generatePDFForAgendaDetails(final CouncilMeeting councilMeeting) { if (councilMeeting != null) { final Map<String, Object> agendaDetails = new HashMap<>(); final List<CouncilAgendaDetails> agendaDetailsList = councilMeeting.getMeetingMOMs().get(0).getAgenda() .getAgendaDetails();/* w w w . ja va2 s. c om*/ agendaDetailsList.sort((final CouncilAgendaDetails f1, final CouncilAgendaDetails f2) -> f1 .getItemNumber().compareTo(f2.getItemNumber())); agendaDetails.put("agendaList", agendaDetailsList); ReportRequest reportInput = new ReportRequest(AGENDA, agendaDetails, buildReportParameters(councilMeeting)); reportInput.setReportFormat(ReportFormat.RTF); reportInput.setPrintDialogOnOpenReport(false); return createReport(reportInput).getReportOutputData(); } return new byte[0]; }
From source file:org.sonar.server.qualityprofile.ws.ProjectsAction.java
@Override public void handle(Request request, Response response) throws Exception { String profileKey = request.mandatoryParam(PARAM_KEY); try (DbSession session = dbClient.openSession(false)) { checkProfileExists(profileKey, session); String selected = request.param(Param.SELECTED); String query = request.param(PARAM_QUERY); int pageSize = request.mandatoryParamAsInt(PARAM_PAGE_SIZE); int page = request.mandatoryParamAsInt(PARAM_PAGE); List<ProjectQprofileAssociationDto> projects = loadProjects(profileKey, session, selected, query); projects.sort((o1, o2) -> new CompareToBuilder() // First, sort by name .append(o1.getProjectName(), o2.getProjectName()) // Then by UUID to disambiguate .append(o1.getProjectUuid(), o2.getProjectUuid()).toComparison()); Collection<Long> projectIds = Collections2.transform(projects, new NonNullInputFunction<ProjectQprofileAssociationDto, Long>() { @Override/*from ww w. jav a2s. com*/ protected Long doApply(ProjectQprofileAssociationDto input) { return input.getProjectId(); } }); Collection<Long> authorizedProjectIds = dbClient.authorizationDao().keepAuthorizedProjectIds(session, projectIds, userSession.getUserId(), UserRole.USER); Iterable<ProjectQprofileAssociationDto> authorizedProjects = Iterables.filter(projects, input -> authorizedProjectIds.contains(input.getProjectId())); Paging paging = forPageIndex(page).withPageSize(pageSize).andTotal(authorizedProjectIds.size()); List<ProjectQprofileAssociationDto> pagedAuthorizedProjects = Lists.newArrayList(authorizedProjects); if (pagedAuthorizedProjects.size() <= paging.offset()) { pagedAuthorizedProjects = Lists.newArrayList(); } else if (pagedAuthorizedProjects.size() > paging.pageSize()) { int endIndex = Math.min(paging.offset() + pageSize, pagedAuthorizedProjects.size()); pagedAuthorizedProjects = pagedAuthorizedProjects.subList(paging.offset(), endIndex); } writeProjects(response.newJsonWriter(), pagedAuthorizedProjects, paging); } }
From source file:com.acmutv.ontoqa.tool.io.IOManagerTest.java
/** * Tests directory listing with filter./* ww w .jav a 2s . co m*/ */ @Test public void test_listAllFiles_withExtension() throws IOException { String directory = IOManagerTest.class.getResource("/tool/io/").getPath(); List<Path> actual = IOManager.allFiles(directory, "*.txt"); actual.sort(Comparator.naturalOrder()); List<Path> expected = new ArrayList<>(); expected.add( FileSystems.getDefault().getPath(IOManagerTest.class.getResource("/tool/io/sample.txt").getPath())); expected.sort(Comparator.naturalOrder()); Assert.assertEquals(expected, actual); }
From source file:org.gradoop.flink.model.impl.operators.matching.single.cypher.planning.queryplan.binary.JoinEmbeddingsNodeTest.java
@Test public void testExecute() throws Exception { GradoopId a = GradoopId.get();//from w ww . j ava 2 s .c o m GradoopId b = GradoopId.get(); GradoopId c = GradoopId.get(); GradoopId d = GradoopId.get(); GradoopId e = GradoopId.get(); GradoopId f = GradoopId.get(); EmbeddingMetaData leftInputMetaData = new EmbeddingMetaData(); leftInputMetaData.setEntryColumn("v1", EntryType.VERTEX, 0); leftInputMetaData.setPropertyColumn("v1", "age", 0); Embedding embedding1 = createEmbedding(singletonList(Pair.of(a, singletonList(42)))); Embedding embedding2 = createEmbedding(singletonList(Pair.of(b, singletonList(23)))); DataSet<Embedding> leftEmbeddings = getExecutionEnvironment().fromElements(embedding1, embedding2); /* * ---------------------------------- * | v1 | e1 | v2 | v2.age | * ---------------------------------- * | id(a) | id(c) | id(e) | 84 | -> Embedding 3 * ---------------------------------- * | id(b) | id(d) | id(f) | 77 | -> Embedding 4 * ---------------------------------- */ EmbeddingMetaData rightInputMetaData = new EmbeddingMetaData(); rightInputMetaData.setEntryColumn("v1", EntryType.VERTEX, 0); rightInputMetaData.setEntryColumn("e1", EntryType.EDGE, 1); rightInputMetaData.setEntryColumn("v2", EntryType.VERTEX, 2); rightInputMetaData.setPropertyColumn("v2", "age", 0); Embedding embedding3 = createEmbedding( asList(Pair.of(a, emptyList()), Pair.of(c, emptyList()), Pair.of(e, singletonList(84)))); Embedding embedding4 = createEmbedding( asList(Pair.of(b, emptyList()), Pair.of(d, emptyList()), Pair.of(f, singletonList(77)))); DataSet<Embedding> rightEmbeddings = getExecutionEnvironment().fromElements(embedding3, embedding4); MockPlanNode leftChild = new MockPlanNode(leftEmbeddings, leftInputMetaData); MockPlanNode rightChild = new MockPlanNode(rightEmbeddings, rightInputMetaData); JoinEmbeddingsNode node = new JoinEmbeddingsNode(leftChild, rightChild, singletonList("v1"), MatchStrategy.ISOMORPHISM, MatchStrategy.ISOMORPHISM); List<Embedding> result = node.execute().collect(); result.sort(Comparator.comparing(o -> o.getProperty(0))); // sort by property value in column 0 assertThat(result.size(), is(2)); assertEmbedding(result.get(0), asList(b, d, f), asList(PropertyValue.create(23), PropertyValue.create(77))); assertEmbedding(result.get(1), asList(a, c, e), asList(PropertyValue.create(42), PropertyValue.create(84))); }
From source file:sonicScream.services.SettingsServiceTest.java
/** * Test of saveSettings method, of class SettingsService. Occurs last, because * it causes side effects that affect the rest of the tests. * @throws sonicScream.services.ProfileNameExistsException * @throws java.io.IOException/*from ww w .j a v a2 s . com*/ */ @Test public void z_testSaveSettings() throws ProfileNameExistsException, IOException, InterruptedException { _testService.putSetting("testSetting", "1"); _testService.putCrc("testCrc", 214980124); _testService.saveSettings("test"); Map<String, String> expSettings = _testService.getReadonlySettings(); Map<String, Long> expCrcs = _testService.getReadonlyCRCs(); List<Profile> exp = _testService.getAllProfiles(); List<Profile> expProfiles = new ArrayList<>(exp); expProfiles.sort(null); SettingsService result = new SettingsService(settingsFile, crcFile, profileDir); Map<String, String> resultSettings = result.getReadonlySettings(); Map<String, Long> resultCrcs = result.getReadonlyCRCs(); List<Profile> res = result.getAllProfiles(); List<Profile> resultProfiles = new ArrayList<>(res); resultProfiles.sort(null); assertEquals(expSettings, resultSettings); assertEquals(expCrcs, resultCrcs); assertEquals(expProfiles.size(), resultProfiles.size()); assertEquals(expProfiles, resultProfiles); }
From source file:org.fenixedu.ulisboa.integration.sas.ui.spring.controller.manageScholarshipReportRequests.ScholarshipReportRequestController.java
@RequestMapping(value = "/createscholarshipreportrequeststep1", method = RequestMethod.GET) public String createscholarshipreportrequeststep1(Model model) { List<ExecutionYear> sortedExecutionYears = Bennu.getInstance().getExecutionYearsSet().stream() .collect(Collectors.toList()); sortedExecutionYears.sort(ExecutionYear.COMPARATOR_BY_BEGIN_DATE.reversed()); model.addAttribute("ScholarshipReportRequest_executionYear_options", sortedExecutionYears); return "integration/sas/managescholarshipreportrequests/scholarshipreportrequest/createscholarshipreportrequeststep1"; }
From source file:com.navercorp.pinpoint.web.mapper.SpanMapperV2.java
private void sortSpanEvent(List<SpanBo> spanBoList) { for (SpanBo spanBo : spanBoList) { List<SpanEventBo> spanEventBoList = spanBo.getSpanEventBoList(); spanEventBoList.sort(SpanEventComparator.INSTANCE); }/*w ww . j a va 2s . c o m*/ }
From source file:org.gradoop.flink.model.impl.operators.matching.single.cypher.planning.queryplan.binary.ValueJoinNodeTest.java
@Test public void testExecute() throws Exception { GradoopId a = GradoopId.get();//from w w w . ja v a 2 s.c om GradoopId b = GradoopId.get(); GradoopId c = GradoopId.get(); GradoopId d = GradoopId.get(); GradoopId e = GradoopId.get(); GradoopId f = GradoopId.get(); GradoopId g = GradoopId.get(); GradoopId h = GradoopId.get(); EmbeddingMetaData leftInputMetaData = new EmbeddingMetaData(); leftInputMetaData.setEntryColumn("v1", EntryType.VERTEX, 0); leftInputMetaData.setPropertyColumn("v1", "age", 0); Embedding embedding1 = createEmbedding(singletonList(Pair.of(a, singletonList(42)))); Embedding embedding2 = createEmbedding(singletonList(Pair.of(b, singletonList(21)))); DataSet<Embedding> leftEmbeddings = getExecutionEnvironment().fromElements(embedding1, embedding2); /* * ---------------------------------- * | v2 | e1 | v3 | v3.age | * ---------------------------------- * | id(c) | id(d) | id(e) | 42 | -> Embedding 3 * ---------------------------------- * | id(f) | id(g) | id(h) | 21 | -> Embedding 4 * ---------------------------------- */ EmbeddingMetaData rightInputMetaData = new EmbeddingMetaData(); rightInputMetaData.setEntryColumn("v2", EntryType.VERTEX, 0); rightInputMetaData.setEntryColumn("e1", EntryType.EDGE, 1); rightInputMetaData.setEntryColumn("v3", EntryType.VERTEX, 2); rightInputMetaData.setPropertyColumn("v3", "age", 0); Embedding embedding3 = createEmbedding( asList(Pair.of(c, emptyList()), Pair.of(d, emptyList()), Pair.of(e, singletonList(42)))); Embedding embedding4 = createEmbedding( asList(Pair.of(f, emptyList()), Pair.of(g, emptyList()), Pair.of(h, singletonList(21)))); DataSet<Embedding> rightEmbeddings = getExecutionEnvironment().fromElements(embedding3, embedding4); MockPlanNode leftChild = new MockPlanNode(leftEmbeddings, leftInputMetaData); MockPlanNode rightChild = new MockPlanNode(rightEmbeddings, rightInputMetaData); ValueJoinNode node = new ValueJoinNode(leftChild, rightChild, singletonList(Pair.of("v1", "age")), singletonList(Pair.of("v3", "age")), MatchStrategy.ISOMORPHISM, MatchStrategy.ISOMORPHISM); List<Embedding> result = node.execute().collect(); result.sort(Comparator.comparing(o -> o.getProperty(0))); // sort by property value in column 0 assertThat(result.size(), is(2)); assertEmbedding(result.get(0), asList(b, f, g, h), asList(PropertyValue.create(21), PropertyValue.create(21))); assertEmbedding(result.get(1), asList(a, c, d, e), asList(PropertyValue.create(42), PropertyValue.create(42))); }
From source file:cc.kave.commons.pointsto.evaluation.ProjectTrainValidateEvaluation.java
private List<List<ProjectIdentifier>> createProjectFolds(Set<ProjectIdentifier> projects, ICoReTypeName type, List<ProjectUsageStore> usageStores) throws IOException { Map<ProjectIdentifier, Double> numberOfUsages = new HashMap<>(projects.size()); for (ProjectUsageStore store : usageStores) { Map<ProjectIdentifier, Integer> numberOfStoreUsages = store.getNumberOfUsagesPerProject(type); store.flush();/* w w w .jav a2 s. c o m*/ for (Map.Entry<ProjectIdentifier, Integer> entry : numberOfStoreUsages.entrySet()) { double currentAverage = numberOfUsages.getOrDefault(entry.getKey(), 0.0); numberOfUsages.put(entry.getKey(), currentAverage + (1.0 / usageStores.size()) * entry.getValue()); } } List<ProjectIdentifier> sortedProjects = new ArrayList<>(projects); sortedProjects.sort(new Comparator<ProjectIdentifier>() { @Override public int compare(ProjectIdentifier o1, ProjectIdentifier o2) { double avg1 = numberOfUsages.get(o1); double avg2 = numberOfUsages.get(o2); return Double.compare(avg1, avg2); } }); return foldBuilder.createFolds(sortedProjects, numberOfUsages); }
From source file:com.haulmont.cuba.gui.app.security.role.edit.tabs.UiPermissionsFrame.java
protected Collection<WindowInfo> sortWindowInfos(Collection<WindowInfo> infos) { List<WindowInfo> infosContainer = new ArrayList<>(infos); infosContainer.sort((o1, o2) -> { if (o1.getId().contains("$") != o2.getId().contains("$")) { if (o1.getId().contains("$")) { return -1; } else { return 1; }//from ww w . j a v a 2s . co m } else { return o1.getId().compareTo(o2.getId()); } }); return infosContainer; }