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.runners.ProjectStoreRunner.java
public static void main(String[] args) throws IOException { Path storeDir = Paths.get(args[0]); try (ProjectUsageStore store = new ProjectUsageStore(storeDir)) { List<ICoReTypeName> types = new ArrayList<>(store.getAllTypes()); types.sort(new TypeNameComparator()); System.out.println(/* www .j a va 2 s . c o m*/ types.stream().filter(t -> t.getIdentifier().contains("KaVE.")).collect(Collectors.toList())); // if (args.length == 1 || args[1].equals("countFilteredUsages")) { // countFilteredUsages(types, store); // } else if (args[1].equals("countRecvCallSites")) { // countRecvCallSites(types, store); // } // methodPropabilities(types, store); } }
From source file:Main.java
public static void main(String[] args) { List<Person> people = new ArrayList<Person>(); people.add(new Person("C", 21)); people.add(new Person("T", 20)); people.add(new Person("B", 35)); people.add(new Person("A", 22)); people.sort(Comparator.comparing(Person::getName)); people.forEach(System.out::println); }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("Java"); list.add("R"); list.add("CSS"); list.add("XML"); System.out.println("List: " + list); // Uses List.sort() method with a Comparator list.sort(Comparator.comparing(String::length)); System.out.println("Sorted List: " + list); }
From source file:org.openbase.bco.manager.util.launch.BCOSystemValidator.java
public static void main(String[] args) { BCO.printLogo();/*from w ww. j a v a 2 s . c om*/ JPService.setApplicationName("bco-validate"); JPService.registerProperty(JPDebugMode.class); JPService.registerProperty(JPVerbose.class); JPService.parseAndExitOnError(args); try { System.out.println("=================================================="); System.out.println("BaseCubeOne - System Validator"); System.out.println("=================================================="); System.out.println(); System.out.println("=== " + AnsiColor.colorize("Check Registries", AnsiColor.ANSI_BLUE) + " ===\n"); final BooleanComparator trueFirstBooleanComparator = new BooleanComparator(true); final BooleanComparator falseFirstBooleanComparator = new BooleanComparator(false); // check List<RegistryRemote> registries = Registries.getRegistries(false); registries.sort((registryRemote, t1) -> falseFirstBooleanComparator.compare( registryRemote instanceof AbstractVirtualRegistryRemote, t1 instanceof AbstractVirtualRegistryRemote)); for (final RegistryRemote registry : registries) { if (!check(registry, TimeUnit.SECONDS.toMillis(2))) { if (registry.isConsistent()) { System.out.println( StringProcessor.fillWithSpaces(registry.getName(), LABEL_RANGE, Alignment.RIGHT) + " " + AnsiColor.colorize(OK, AnsiColor.ANSI_GREEN)); } else { System.out.println( StringProcessor.fillWithSpaces(registry.getName(), LABEL_RANGE, Alignment.RIGHT) + " " + AnsiColor.colorize("INCONSISTENT", AnsiColor.ANSI_RED)); } } } System.out.println(); System.out.println("=== " + AnsiColor.colorize("Check Units", AnsiColor.ANSI_BLUE) + " ===\n"); Future<List<UnitRemote<?>>> futureUnits = Units.getFutureUnits(false); System.out.println(StringProcessor.fillWithSpaces("Unit Pool", LABEL_RANGE, Alignment.RIGHT) + " " + check(futureUnits, DEFAULT_UNIT_POOL_DELAY_TIME)); System.out.println(); if (futureUnits.isCancelled()) { System.out.println(AnsiColor.colorize( "Connection could not be established, please make sure BaseCubeOne is up and running!\n", AnsiColor.ANSI_YELLOW)); try { futureUnits.get(); } catch (ExecutionException | CancellationException ex) { ExceptionPrinter.printHistory("Error Details", ex, System.err); } } else { boolean printed = false; final List<UnitRemote<?>> unitList = new ArrayList<>(futureUnits.get()); unitList.sort((unitRemote, t1) -> { try { return trueFirstBooleanComparator.compare(unitRemote.isDalUnit(), t1.isDalUnit()); } catch (CouldNotPerformException ex) { LOGGER.warn("Could not compare unit[" + unitRemote + "] and unit[" + t1 + "]", ex); return 0; } }); for (final UnitRemote<?> unit : unitList) { printed = check(unit) || printed; } if (!printed) { System.out.println( StringProcessor.fillWithSpaces("Unit Connections", LABEL_RANGE, Alignment.RIGHT) + " " + AnsiColor.colorize(OK, AnsiColor.ANSI_GREEN)); } } } catch (InterruptedException ex) { System.out.println("killed"); System.exit(253); return; } catch (Exception ex) { ExceptionPrinter.printHistory(new CouldNotPerformException("Could not validate system!", ex), System.err); System.exit(254); } System.out.println(); System.out.println("=============================================================="); System.out.print("=== "); switch (errorCounter) { case 0: System.out.print(AnsiColor.colorize("VALIDATION SUCCESSFUL", AnsiColor.ANSI_GREEN)); break; default: System.out.print(errorCounter + " " + AnsiColor .colorize("ERROR" + (errorCounter > 1 ? "S" : "") + " DETECTED", AnsiColor.ANSI_RED)); break; } System.out.println(" average ping is " + AnsiColor.colorize(pingFormat.format(getGlobalPing()), AnsiColor.ANSI_CYAN) + " milli"); System.out.println("=============================================================="); System.out.println(); System.exit(Math.min(errorCounter, 200)); }
From source file:org.cgiar.ccafs.marlo.utils.SendEmails.java
public static void main(String[] args) { users = new ArrayList<>(); usersEmail = new ArrayList<>(); ApplicationContext ctx = new AnnotationConfigApplicationContext(ApplicationContextConfig.class); SessionFactory sessionFactory = ctx.getBean(SessionFactory.class); sessionFactory.getCurrentSession().beginTransaction(); userDAO = ctx.getBean(UserDAO.class); roleDAO = ctx.getBean(RoleDAO.class); dao = ctx.getBean(ProjectDAO.class); sendMail = ctx.getBean(SendMailS.class); action = ctx.getBean(ReportingSummaryAction.class); validateProjectSectionAction = ctx.getBean(ValidateProjectSectionAction.class); projectLeaderEditAction = ctx.getBean(ProjectLeaderEditAction.class); globalUnitManager = ctx.getBean(GlobalUnitManager.class); globalUnitProjectManager = ctx.getBean(GlobalUnitProjectManager.class); action.setUsersToActive(new ArrayList<Map<String, Object>>()); AuditLogContextProvider.push(new AuditLogContext()); List<Map<String, Object>> list = userDAO.findCustomQuery( " select p.id from projects p inner join global_unit_projects gp on gp.project_id=p.id where p.id_consolidado is not null and gp.global_unit_id=21 and p.id>880; "); action.setSession(new HashMap<>()); action.loadProvider(action.getSession()); action.getSession().put(APConstants.CRP_ADMIN_ROLE, "83"); action.getSession().put(APConstants.CRP_EMAIL_CC_FL_FM_CL, true); action.getSession().put(APConstants.CRP_PMU_ROLE, "84"); action.getSession().put(APConstants.CRP_PL_ROLE, "91"); action.getSession().put(APConstants.CRP_PL_ROLE, "91"); action.getSession().put(APConstants.CRP_LESSONS_ACTIVE, true); action.setPhaseID(new Long(7)); List<Phase> phases = globalUnitManager.getGlobalUnitById(21L).getPhases().stream().filter(c -> c.isActive()) .collect(Collectors.toList()); phases.sort((p1, p2) -> p1.getStartDate().compareTo(p2.getStartDate())); Map<Long, Phase> allPhasesMap = new HashMap<>(); for (Phase phase : phases) { allPhasesMap.put(phase.getId(), phase); }// w w w .jav a 2 s. co m action.getSession().put(APConstants.ALL_PHASES, allPhasesMap); Long plRoleID = Long.parseLong((String) action.getSession().get(APConstants.CRP_PL_ROLE)); Role plRole = roleDAO.find(plRoleID); for (Map<String, Object> map : list) { Long id = Long.parseLong(map.get("id").toString()); Project project = dao.find(id); for (ProjectPartner projectPartner : project.getProjectPartners().stream().filter( c -> c.isActive() && c.getPhase().getId().longValue() == action.getPhaseID().longValue()) .collect(Collectors.toList())) { for (ProjectPartnerPerson projectPartnerPerson : projectPartner.getProjectPartnerPersons().stream() .filter(c -> c.isActive()).collect(Collectors.toList())) { if (projectPartnerPerson.getContactType().equals("PL")) { if (!usersEmail.contains(projectPartnerPerson.getUser().getEmail())) { notifyNewUserCreated(projectPartnerPerson.getUser()); } notifyRoleAssigned(projectPartnerPerson.getUser(), plRole, project, globalUnitProjectManager.findByProjectId(project.getId()).getGlobalUnit()); } } } for (Phase phase : phases) { if (phase.getYear() == 2017 || phase.getYear() == 2018) { System.out.println("VALIDATE PROJECT " + project.getId()); validateProjectSectionAction.setProjectID(project.getId()); validateProjectSectionAction.setSession(action.getSession()); validateProjectSectionAction.setValidSection(true); validateProjectSectionAction.setExistProject(true); validateProjectSectionAction.setInvalidFields(new HashMap<>()); validateProjectSectionAction.setValidationMessage(new StringBuilder()); validateProjectSectionAction.loadProvider(action.getSession()); validateProjectSectionAction.setPhaseID(phase.getId()); validateProjectSectionAction.setCrpID( globalUnitProjectManager.findByProjectId(project.getId()).getGlobalUnit().getId()); validateProjectSectionAction.setMissingFields(new StringBuilder()); validateProjectSectionAction.setSectionName(ProjectSectionStatusEnum.DESCRIPTION.getStatus()); try { validateProjectSectionAction.execute(); } catch (Exception e) { e.printStackTrace(); } validateProjectSectionAction.setMissingFields(new StringBuilder()); validateProjectSectionAction.setSectionName(ProjectSectionStatusEnum.PARTNERS.getStatus()); try { validateProjectSectionAction.execute(); } catch (Exception e) { e.printStackTrace(); } validateProjectSectionAction.setMissingFields(new StringBuilder()); validateProjectSectionAction.setSectionName(ProjectSectionStatusEnum.BUDGET.getStatus()); try { validateProjectSectionAction.execute(); } catch (Exception e) { e.printStackTrace(); } projectLeaderEditAction.setProjectId(project.getId()); projectLeaderEditAction.setProjectStatus(true); projectLeaderEditAction.setSession(action.getSession()); projectLeaderEditAction.setInvalidFields(new HashMap<>()); projectLeaderEditAction.setValidationMessage(new StringBuilder()); projectLeaderEditAction.loadProvider(action.getSession()); projectLeaderEditAction.setPhaseID(phase.getId()); projectLeaderEditAction.setCrpID( globalUnitProjectManager.findByProjectId(project.getId()).getGlobalUnit().getId()); projectLeaderEditAction.setMissingFields(new StringBuilder()); try { if (projectLeaderEditAction.isCompletePreProject(project.getId())) { projectLeaderEditAction.execute(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } list = userDAO.findCustomQuery( " select p.id from projects p inner join global_unit_projects gp on gp.project_id=p.id where p.id_consolidado is not null and gp.global_unit_id=22 ; "); action.setSession(new HashMap<>()); action.loadProvider(action.getSession()); action.getSession().put(APConstants.CRP_ADMIN_ROLE, "98"); action.getSession().put(APConstants.CRP_EMAIL_CC_FL_FM_CL, true); action.getSession().put(APConstants.CRP_PMU_ROLE, "99"); action.getSession().put(APConstants.CRP_PL_ROLE, "106"); action.setPhaseID(new Long(8)); action.getSession().put(APConstants.CRP_LESSONS_ACTIVE, true); phases = globalUnitManager.getGlobalUnitById(22L).getPhases().stream().filter(c -> c.isActive()) .collect(Collectors.toList()); phases.sort((p1, p2) -> p1.getStartDate().compareTo(p2.getStartDate())); allPhasesMap = new HashMap<>(); for (Phase phase : phases) { allPhasesMap.put(phase.getId(), phase); } action.getSession().put(APConstants.ALL_PHASES, allPhasesMap); plRoleID = Long.parseLong((String) action.getSession().get(APConstants.CRP_PL_ROLE)); plRole = roleDAO.find(plRoleID); for (Map<String, Object> map : list) { Long id = Long.parseLong(map.get("id").toString()); Project project = dao.find(id); for (ProjectPartner projectPartner : project.getProjectPartners().stream().filter( c -> c.isActive() && c.getPhase().getId().longValue() == action.getPhaseID().longValue()) .collect(Collectors.toList())) { for (ProjectPartnerPerson projectPartnerPerson : projectPartner.getProjectPartnerPersons().stream() .filter(c -> c.isActive()).collect(Collectors.toList())) { if (projectPartnerPerson.getContactType().equals("PL")) { if (!usersEmail.contains(projectPartnerPerson.getUser().getEmail())) { notifyNewUserCreated(projectPartnerPerson.getUser()); } notifyRoleAssigned(projectPartnerPerson.getUser(), plRole, project, globalUnitProjectManager.findByProjectId(project.getId()).getGlobalUnit()); } } } for (Phase phase : phases) { if (phase.getYear() == 2017 || phase.getYear() == 2018 && phase.getDescription().equals("Planning")) { System.out.println("VALIDATE PROJECT " + project.getId()); validateProjectSectionAction.setProjectID(project.getId()); validateProjectSectionAction.setSession(action.getSession()); validateProjectSectionAction.setValidSection(true); validateProjectSectionAction.setExistProject(true); validateProjectSectionAction.setInvalidFields(new HashMap<>()); validateProjectSectionAction.setValidationMessage(new StringBuilder()); validateProjectSectionAction.loadProvider(action.getSession()); validateProjectSectionAction.setPhaseID(phase.getId()); validateProjectSectionAction.setCrpID( globalUnitProjectManager.findByProjectId(project.getId()).getGlobalUnit().getId()); validateProjectSectionAction.setMissingFields(new StringBuilder()); validateProjectSectionAction.setSectionName(ProjectSectionStatusEnum.DESCRIPTION.getStatus()); try { validateProjectSectionAction.execute(); } catch (Exception e) { e.printStackTrace(); } validateProjectSectionAction.setMissingFields(new StringBuilder()); validateProjectSectionAction.setSectionName(ProjectSectionStatusEnum.PARTNERS.getStatus()); try { validateProjectSectionAction.execute(); } catch (Exception e) { e.printStackTrace(); } validateProjectSectionAction.setMissingFields(new StringBuilder()); validateProjectSectionAction.setSectionName(ProjectSectionStatusEnum.BUDGET.getStatus()); try { validateProjectSectionAction.execute(); } catch (Exception e) { e.printStackTrace(); } } } } action.addUsers(); sessionFactory.getCurrentSession().getTransaction().commit(); }
From source file:Main.java
@Deprecated public static <T> void sort(List<T> list, Comparator<? super T> c) { list.sort(c); }
From source file:Main.java
/** * Sorts given map by given comparator/* w w w . j a v a 2s .c o m*/ * * @param map The map * @param comparator The comparator to sort the map * @param <K> The key type * @param <V> The value type * @return The sorted map */ public static <K, V> Map<K, V> sortMapByValue(Map<K, V> map, Comparator<Map.Entry<K, V>> comparator) { List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet()); list.sort(comparator); Map<K, V> result = new LinkedHashMap<>(); for (Map.Entry<K, V> entry : list) { result.put(entry.getKey(), entry.getValue()); } return result; }
From source file:Main.java
public static <K, V> void sortMap(LinkedHashMap<K, V> map, Comparator<Map.Entry<K, V>> c) { List<Map.Entry<K, V>> entries = new ArrayList<>(map.entrySet()); entries.sort(c); map.clear();//from w w w .j a v a2 s . co m for (Map.Entry<K, V> e : entries) { map.put(e.getKey(), e.getValue()); } }
From source file:Main.java
public static <T> List<T> range(List<? extends T> list, T min, T max, Comparator<? super T> comparator) { List<T> tList = newArrayList(); addAll(list, tList);// w ww . j a v a 2s . c o m tList.sort(comparator); return tList.subList(indexOf(list, min), indexOf(list, max) + 1); /* return list.stream() .sorted(comparator) .filter(t -> comparator.compare(t,min)>=0&&comparator.compare(t,max)<=0) .collect(Collectors.toList()); */ }
From source file:org.shareok.data.redis.RedisUtil.java
public static void sortJobList(List<RedisJob> jobList) { jobList.sort(new Comparator<RedisJob>() { @Override/* w w w . ja va 2 s .c o m*/ public int compare(RedisJob o1, RedisJob o2) { int result = 0; try { if (null != o1 && null != o2) { result = Math.toIntExact(o1.getJobId() - o2.getJobId()); } } catch (UnsupportedOperationException uoex) { logger.error("Cannot compare the tow job objects", uoex); } return result; } }); }