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:Main.java
DefaultMutableTreeNode addNodes(DefaultMutableTreeNode curTop, File dir) { DefaultMutableTreeNode curDir = new DefaultMutableTreeNode(dir); if (curTop != null) { curTop.add(curDir);/*from w w w . jav a2 s . com*/ } File[] tmp = dir.listFiles(); Vector<File> ol = new Vector<File>(); ol.addAll(Arrays.asList(tmp)); Collections.sort(ol, new Comparator<File>() { @Override public int compare(File o1, File o2) { int result = o1.getName().compareTo(o2.getName()); if (o1.isDirectory() && o2.isFile()) { result = -1; } else if (o2.isDirectory() && o1.isFile()) { result = 1; } return result; } }); for (int i = 0; i < ol.size(); i++) { File file = ol.elementAt(i); DefaultMutableTreeNode node = new DefaultMutableTreeNode(file); if (file.isDirectory()) { addNodes(node, file); } curDir.add(node); } return curDir; }
From source file:com.gantzgulch.sharing.controller.SharedFilesController.java
@RequestMapping(method = RequestMethod.GET) public ModelAndView doGet() throws Exception { List<SharedFile> sharedFiles = sharedFileManager.findAll(); Collections.sort(sharedFiles, new SharedFile.UploadDateComparator(true)); return new ModelAndView(".files", "files", sharedFiles); }
From source file:net.paoding.rose.jade.statement.DefaultInterpreterFactory.java
public synchronized void addInterpreter(Interpreter interpreter) { if (!ArrayUtils.contains(this.interpreters, interpreter)) { ArrayList<Interpreter> interpreters = new ArrayList<Interpreter>(this.interpreters.length + 1); interpreters.add(interpreter);//from ww w . ja va 2s . co m Collections.sort(interpreters, new InterpreterComparator()); this.interpreters = interpreters.toArray(new Interpreter[0]); } }
From source file:models.TimelineItemTest.java
@Test public void desc() { // When Collections.sort(list, TimelineItem.DESC); // Then assertThat(list).containsExactly(third, second, first); }
From source file:net.geertvos.gossip.core.Md5HashProvider.java
@Override public String hashCluster(Collection<GossipClusterMember> members) { List<GossipClusterMember> sortedMembers = new ArrayList<GossipClusterMember>(members); Collections.sort(sortedMembers, comperator); StringBuilder stringBuilder = new StringBuilder(); for (ClusterMember member : sortedMembers) { stringBuilder.append(member.getId() + "|"); }/*from w ww . j a v a 2 s . c o m*/ byte[] bytes = stringBuilder.toString().getBytes(charset); byte[] digest = digester.digest(bytes); byte[] encoded = Base64.encodeBase64(digest); return new String(encoded, charset); }
From source file:uk.co.onehp.trickle.dao.HibernateBetDao.java
@Override public Bet getNextBet() { List<Bet> bets = incompleteBets(); Collections.sort(bets, new Comparator<Bet>() { @Override//from w ww.java 2 s .c o m public int compare(Bet o1, Bet o2) { int mostSeconds1 = DateUtil.getMostSeconds(o1.getUnprocessedTimings()); int mostSeconds2 = DateUtil.getMostSeconds(o2.getUnprocessedTimings()); return o1.getHorse().getRace().getStartTime().minusSeconds(mostSeconds1) .compareTo(o2.getHorse().getRace().getStartTime().minusSeconds(mostSeconds2)); } }); return bets.size() > 0 ? bets.get(0) : null; }
From source file:org.macula.cart.demo.service.impl.DemoApplicationServiceImpl.java
@Override public List<DemoApplication> getAllApplications() { List<DemoApplication> result = new ArrayList<DemoApplication>(demoApplicationRepository.findAll()); Collections.sort(result, new Comparator<DemoApplication>() { @Override// w ww . j a v a2s .c o m public int compare(DemoApplication o1, DemoApplication o2) { int result = o1.getAppGroup().compareTo(o2.getAppGroup()); return result != 0 ? result : o1.getAppId().compareToIgnoreCase(o2.getAppId()); } }); return result; }
From source file:gov.nih.nci.cabig.caaers.web.table.SortRowsCallbackImpl.java
public Collection sortRows(TableModel model, Collection rows) throws Exception { boolean sorted = model.getLimit().isSorted(); if (!sorted) { return rows; }// w ww.j a v a 2 s .c o m Sort sort = model.getLimit().getSort(); String property = sort.getProperty(); String sortOrder = sort.getSortOrder(); if (StringUtils.contains(property, ".")) { try { if (sortOrder.equals(TableConstants.SORT_ASC)) { Collections.sort((List) rows, new NullSafeBeanComparator(property, new NullStringComparator())); } else if (sortOrder.equals(TableConstants.SORT_DESC)) { NullSafeBeanComparator reversedNaturalOrderBeanComparator = new NullSafeBeanComparator(property, new ReverseComparator(new NullStringComparator())); Collections.sort((List) rows, reversedNaturalOrderBeanComparator); } } catch (NoClassDefFoundError e) { String msg = "The column property [" + property + "] is nested and requires BeanUtils 1.7 or greater for proper sorting."; logger.error(msg); throw new NoClassDefFoundError(msg); //just rethrow so it is not hidden } } else { if (sortOrder.equals(TableConstants.SORT_ASC)) { BeanComparator comparator = new BeanComparator(property, new NullStringComparator()); Collections.sort((List) rows, comparator); } else if (sortOrder.equals(TableConstants.SORT_DESC)) { BeanComparator reversedNaturalOrderBeanComparator = new BeanComparator(property, new ReverseComparator(new NullStringComparator())); Collections.sort((List) rows, reversedNaturalOrderBeanComparator); } } return rows; }
From source file:net.sourceforge.fenixedu.presentationTier.renderers.providers.ExecutionCoursesForExamCoordinator.java
@Override public Object provide(Object source, Object currentValue) { ConvokeBean bean = (ConvokeBean) source; ExamCoordinator coordinator = bean.getExamCoordinator(); List<ExecutionCourse> courses = coordinator.getAssociatedExecutionCourses(); Collections.sort(courses, new BeanComparator("nome")); return courses; }
From source file:me.math.kdtree.KDTree.java
/** * /*w ww . ja v a 2 s. c o m*/ * @param aList */ public KDTree(List<AbstractSpatialGridPoint> aList, INodeCreator creator) { comparator_ = new GridComparator(INode.Direction.XLAT); Collections.sort(aList, comparator_); root_ = insertNode(aList, INode.Direction.XLAT, root_, 0, creator); }