List of usage examples for java.util Collections sort
@SuppressWarnings({ "unchecked", "rawtypes" }) public static <T> void sort(List<T> list, Comparator<? super T> c)
From source file:org.lieuofs.extraction.commune.ExtractionGeTax.java
public void extraire() throws IOException { CommuneCritere critere = new CommuneCritere(); Calendar cal = Calendar.getInstance(); cal.set(2012, Calendar.JANUARY, 1); critere.setDateValiditeApres(cal.getTime()); cal.set(2012, Calendar.DECEMBER, 31); critere.setDateValiditeAvant(cal.getTime()); List<ICommuneSuisse> communes = gestionnaire.rechercher(critere); Collections.sort(communes, new Comparator<ICommuneSuisse>() { @Override//from www .j a va2s . co m public int compare(ICommuneSuisse o1, ICommuneSuisse o2) { return o1.getNumeroOFS() - o2.getNumeroOFS(); } }); // Attention, le fichier est une iste historise des communes. // Une commune peut donc figurer 2 fois dans le fichier Set<Integer> numOFS = new HashSet<Integer>(3000); int nbreCommune = 0; BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(new File("ExtractionCommuneGETaX2012.csv")), Charset.forName("ISO8859-1"))); for (ICommuneSuisse commune : communes) { if (!numOFS.contains(commune.getNumeroOFS())) { nbreCommune++; numOFS.add(commune.getNumeroOFS()); writer.write(String.valueOf(commune.getNumeroOFS())); writer.write(";"); writer.write(commune.getNomCourt()); writer.write(";"); writer.write(commune.getCanton().getCodeIso2()); writer.newLine(); System.out.println(commune.getNumeroOFS() + " " + commune.getNomCourt()); } } writer.close(); System.out.println("Nbre commune : " + nbreCommune); }
From source file:net.sourceforge.fenixedu.presentationTier.renderers.providers.VigilantGroupsProvider.java
@Override public Object provide(Object source, Object currentValue) { VigilantBean bean = (VigilantBean) source; List<VigilantGroup> groups = new ArrayList(bean.getVigilantGroups()); Collections.sort(groups, new BeanComparator("name")); return groups; }
From source file:gov.nih.nci.iso21090.hibernate.node.ComplexNode.java
/** * @param node Node to be added to innerNodes *//*w ww. j a v a 2 s . co m*/ public void addInnerNode(Node node) { innerNodes.add(node); Collections.sort(innerNodes, new NodeNameComparator()); }
From source file:org.openmrs.module.uiframeworkpatientsummarysupport.fragment.controller.PatientProblemsFragmentController.java
public void controller(FragmentModel model, @FragmentParam(value = "patientId") Patient patient) { //TODO should be able to use problem added and problem resolved GP //but for demo purposes we are using the active list service List<ActiveListItem> problems = Context.getActiveListService().getActiveListItems(patient, Problem.ACTIVE_LIST_TYPE); //sort the problems by date started descending Collections.sort(problems, Collections.reverseOrder(new ActiveListItemByStartDateComparator())); model.addAttribute("problems", problems); }
From source file:net.sourceforge.fenixedu.presentationTier.renderers.providers.ExecutionSemestersProvider.java
@Override public Object provide(Object source, Object currentValue) { final List<ExecutionSemester> executionSemesters = new ArrayList<ExecutionSemester>( Bennu.getInstance().getExecutionPeriodsSet()); Collections.sort(executionSemesters, new ReverseComparator()); return executionSemesters; }
From source file:org.schedulesdirect.grabber.ScheduleTask.java
static void commit(FileSystem vfs) throws IOException { Iterator<String> itr = FULL_SCHEDS.keySet().iterator(); while (itr.hasNext()) { String id = itr.next();//from ww w . j ava 2s . co m JSONObject sched = new JSONObject(); List<JSONObject> airs = FULL_SCHEDS.get(id); Collections.sort(airs, new Comparator<JSONObject>() { @Override public int compare(JSONObject arg0, JSONObject arg1) { return arg0.getString("airDateTime").compareTo(arg1.getString("airDateTime")); } }); sched.put("programs", airs); Path p = vfs.getPath("schedules", String.format("%s.txt", id)); Files.write(p, sched.toString(3).getBytes(ZipEpgClient.ZIP_CHARSET), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE); } FULL_SCHEDS.clear(); }
From source file:de.tor.tribes.util.AllyUtils.java
public static Ally[] filterAllies(Ally[] pAllies, String pFilter, Comparator<Ally> pComparator) { List<Ally> result = new LinkedList<>(); if (pFilter == null || pFilter.length() == 0) { Collections.addAll(result, pAllies); } else {//ww w . ja v a 2 s . c o m String filter = pFilter.toLowerCase(); for (Ally a : pAllies) { if (a.getName().toLowerCase().contains(filter) || a.getTag().toLowerCase().contains(filter)) { result.add(a); } } } if (pComparator != null) { Collections.sort(result, pComparator); } return result.toArray(new Ally[result.size()]); }
From source file:com.skelril.skree.content.modifier.ModifierNotifier.java
@Listener public void onPlayerJoin(ClientConnectionEvent.Join event) { Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class); if (!optService.isPresent()) { return;/*from ww w . jav a 2 s .c om*/ } ModifierService service = optService.get(); List<String> messages = new ArrayList<>(); for (Map.Entry<String, Long> entry : service.getActiveModifiers().entrySet()) { String friendlyName = StringUtils.capitalize(entry.getKey().replace("_", " ").toLowerCase()); String friendlyTime = PrettyText.date(entry.getValue()); messages.add(" - " + friendlyName + " till " + friendlyTime); } if (messages.isEmpty()) return; Collections.sort(messages, String.CASE_INSENSITIVE_ORDER); messages.add(0, "\n\nThe following donation perks are enabled:"); Player player = event.getTargetEntity(); Task.builder().execute(() -> { for (String message : messages) { player.sendMessage(Text.of(TextColors.GOLD, message)); } }).delay(1, TimeUnit.SECONDS).submit(SkreePlugin.inst()); }
From source file:com.agiletec.apsadmin.portal.PageFinderAction.java
@Override public List<IPage> getPagesFound() { List<IPage> result = null; try {//from w ww . j a va 2 s. co m List<String> allowedGroupCodes = this.getAllowedGroupCodes(); result = this.getPageManager().searchPages(this.getPageCodeToken(), allowedGroupCodes); BeanComparator comparator = new BeanComparator("code"); Collections.sort(result, comparator); } catch (Throwable t) { _logger.error("Error on searching pages", t); //ApsSystemUtils.logThrowable(t, this, "Error on searching pages"); throw new RuntimeException("Error on searching pages", t); } return result; }
From source file:org.freeeed.search.web.controller.ListCasesController.java
@Override public ModelAndView execute() { log.debug("List cases called..."); if (!loggedSiteVisitor.getUser().hasRight(User.Right.CASES)) { try {/*from ww w .ja v a 2s . c o m*/ response.sendRedirect(WebConstants.MAIN_PAGE_REDIRECT); } catch (IOException e) { } } List<Case> cases = caseDao.listCases(); Collections.sort(cases, new Comparator<Case>() { @Override public int compare(Case o1, Case o2) { return o1.getName().compareTo(o2.getName()); } }); valueStack.put("cases", cases); return new ModelAndView(WebConstants.LIST_CASES_PAGE); }