List of usage examples for java.util Comparator Comparator
Comparator
From source file:org.lightadmin.core.view.preparer.DashboardViewPreparer.java
private Collection<Pair<MenuItem, Long>> dashboardDomainTypes( Collection<DomainTypeAdministrationConfiguration> configurations) { final List<Pair<MenuItem, Long>> domainTypeItems = newLinkedList(); for (DomainTypeAdministrationConfiguration configuration : configurations) { domainTypeItems.add(Pair.create(menuItem(configuration), configuration.getRepository().count())); }//from www . j a v a 2 s. c o m sort(domainTypeItems, new Comparator<Pair<MenuItem, Long>>() { @Override public int compare(final Pair<MenuItem, Long> menuItemPair1, final Pair<MenuItem, Long> menuItemPair2) { return MenuItemComparator.INSTANCE.compare(menuItemPair1.first, menuItemPair2.first); } }); return domainTypeItems; }
From source file:me.doshou.admin.maintain.editor.web.controller.utils.OnlineEditorUtils.java
public static void sort(final List<Map<Object, Object>> files, final Sort sort) { Collections.sort(files, new Comparator<Map<Object, Object>>() { @Override/*from w w w. ja v a 2 s . c o m*/ public int compare(Map<Object, Object> o1, Map<Object, Object> o2) { if (sort == null) { return 0; } Sort.Order nameOrder = sort.getOrderFor("name"); if (nameOrder != null) { String n1 = (String) o1.get("name"); String n2 = (String) o2.get("name"); Boolean n1IsDirecoty = (Boolean) o1.get("isDirectory"); Boolean n2IsDirecoty = (Boolean) o2.get("isDirectory"); if (n1IsDirecoty.equals(Boolean.TRUE) && n2IsDirecoty.equals(Boolean.FALSE)) { return -1; } else if (n1IsDirecoty.equals(Boolean.FALSE) && n2IsDirecoty.equals(Boolean.TRUE)) { return 1; } if (nameOrder.getDirection() == Sort.Direction.ASC) { return n1.compareTo(n2); } else { return -n1.compareTo(n2); } } Sort.Order lastModifiedOrder = sort.getOrderFor("lastModified"); if (lastModifiedOrder != null) { Long l1 = (Long) o1.get("lastModifiedForLong"); Long l2 = (Long) o2.get("lastModifiedForLong"); if (lastModifiedOrder.getDirection() == Sort.Direction.ASC) { return l1.compareTo(l2); } else { return -l1.compareTo(l2); } } Sort.Order sizeOrder = sort.getOrderFor("size"); if (sizeOrder != null) { Long s1 = (Long) o1.get("size"); Long s2 = (Long) o2.get("size"); if (sizeOrder.getDirection() == Sort.Direction.ASC) { return s1.compareTo(s2); } else { return -s1.compareTo(s2); } } return 0; } }); }
From source file:ar.com.zauber.commons.message.impl.message.ResourceBundleMessageTemplate.java
/** * @see MessageFactory#renderString(java.lang.String, java.util.Map) * //from w ww .ja v a 2 s . com * Try not to use this one. * * */ @SuppressWarnings("unchecked") public final String renderString(final String message, final Map<String, Object> model) { List<Map.Entry<String, Object>> entries = new ArrayList<Map.Entry<String, Object>>(model.entrySet()); Collections.sort(entries, new Comparator<Map.Entry<String, Object>>() { public int compare(final Map.Entry<String, Object> o1, final Map.Entry<String, Object> o2) { return o1.getKey().compareTo(o2.getKey()); } }); Collection<Object> parameters = CollectionUtils.collect(entries, new BeanToPropertyValueTransformer("value")); return renderString(message, parameters.toArray()); }
From source file:com.github.kutschkem.Qgen.QuestionRankerByParseProbability.java
public List<Question> rank(List<Question> questions) { System.out.println("afterPipeline:" + questions.size()); final Map<Question, Double> scores = new HashMap<Question, Double>(); for (Question q : questions) { List<HasWord> tokens = new DocumentPreprocessor(new StringReader(q.Question)).iterator().next(); LexicalizedParserQuery query = parser.parserQuery(); query.parse(tokens);/*from w ww .j a v a 2 s. co m*/ scores.put(q, average(query.getKBestPCFGParses(3))); } List<Question> result = new ArrayList<Question>(questions); Collections.sort(result, new Comparator<Question>() { public int compare(Question o1, Question o2) { return -scores.get(o1).compareTo(scores.get(o2)); } }); for (Question q : result) { System.out.println(q.Question + " " + scores.get(q)); } return result; }
From source file:com.walmartlabs.mupd8.application.Config.java
public Config(File directory) throws IOException { File[] files = directory.listFiles(new FilenameFilter() { @Override/*w w w . j av a2 s. c o m*/ public boolean accept(File dir, String name) { return name.endsWith(".cfg"); } }); if (files == null) { throw new FileNotFoundException("Configuration path " + directory.toString() + " is not a directory."); } Arrays.sort(files, new Comparator<File>() { @Override public int compare(File o1, File o2) { return o1.getName().compareTo(o2.getName()); } }); applyFiles(configuration, files); workerJSONs = extractWorkerJSONs(configuration); }
From source file:com.erinors.hpb.server.serviceimpl.PersistentObjectManagerImpl.java
@Override public void onApplicationEvent(ContextRefreshedEvent event) { handlers = new ArrayList<PersistentObjectHandler>( (Collection<? extends PersistentObjectHandler>) beanFactory .getBeansOfType(PersistentObjectHandler.class).values()); Collections.sort(handlers, new Comparator<PersistentObjectHandler>() { private OrderComparator orderComparator = new OrderComparator(); @Override/*from www . j a va 2s . c o m*/ public int compare(PersistentObjectHandler o1, PersistentObjectHandler o2) { return orderComparator.compare(o1, o2); } }); }
From source file:be.vds.jtbdive.client.view.core.stats.StatChartGenerator.java
private static JFreeChart buildChartForDiveDepths(StatQueryObject sqo) { Collection<StatSerie> s = sqo.getValues(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (StatSerie statSerie : s) { List<StatPoint> points = statSerie.getPoints(); Collections.sort(points, new Comparator<StatPoint>() { @Override//from www . jav a 2 s . co m public int compare(StatPoint o1, StatPoint o2) { return -((Double) (o1).getX()).compareTo((Double) (o2).getX()); } }); // int i = 0; // int indexMax = points.size()-1; // for (StatPoint point : points) { // String label =null; // if(i == indexMax){ // label = "< "+((Double) point.getX()); // }else{ // label = (Double) point.getX() + " - "+(Double) // points.get(i+1).getX(); // } // dataset.addValue(point.getY(), // label, ""); // i++; // } for (StatPoint point : points) { dataset.addValue(point.getY(), String.valueOf(UnitsAgent.getInstance().convertLengthFromModel((Double) point.getX())), ""); } } String xLabel = i18n.getString("depth") + " (" + UnitsAgent.getInstance().getLengthUnit().getSymbol() + ")"; String yLabel = i18n.getString("dives.numberof"); JFreeChart chart = createBarChart(dataset, xLabel, yLabel); return chart; }
From source file:com.logsniffer.model.file.WildcardLogSourceTest.java
@Test public void testLogsResolving() throws IOException { File tmp = File.createTempFile("sdkj", "jk"); tmp.deleteOnExit();//from w w w. j a v a2s . c o m File tmpFolder1 = new File(tmp.getPath() + "d", "f1"); tmpFolder1.mkdirs(); tmpFolder1.deleteOnExit(); File tmpFolder2 = new File(tmp.getPath() + "d", "f2"); tmpFolder2.mkdirs(); tmpFolder2.deleteOnExit(); FileUtils.write(new File(tmpFolder1, "1.txt"), "txt"); FileUtils.write(new File(tmpFolder1, "2.txt"), "txt"); FileUtils.write(new File(tmpFolder1, "3.log"), "log"); FileUtils.write(new File(tmpFolder2, "22.txt"), "txt"); File tmpDir = new File(tmpFolder2, "folder.txt"); tmpDir.mkdir(); tmpDir.deleteOnExit(); // Check now WildcardLogsSource source = new WildcardLogsSource(); source.setPattern(tmp.getPath() + "d/*.txt"); Assert.assertEquals(0, source.getLogs().size()); source.setPattern(tmp.getPath() + "d/**/*.txt"); Log[] logs = source.getLogs().toArray(new Log[0]); Assert.assertEquals(3, logs.length); Arrays.sort(logs, new Comparator<Log>() { @Override public int compare(final Log o1, final Log o2) { return o1.getPath().compareTo(o2.getPath()); } }); Assert.assertTrue(logs[0].getPath().endsWith("1.txt")); Assert.assertTrue(logs[1].getPath().endsWith("2.txt")); Assert.assertTrue(logs[2].getPath().endsWith("22.txt")); }
From source file:info.magnolia.module.admininterface.dialogs.LanguageSelect.java
/** * @see info.magnolia.cms.gui.dialog.DialogSelect#init(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, info.magnolia.cms.core.Content, info.magnolia.cms.core.Content) */// ww w . ja v a2 s .c o m public void init(HttpServletRequest request, HttpServletResponse response, Content websiteNode, Content configNode) throws RepositoryException { super.init(request, response, websiteNode, configNode); List options = new ArrayList(); Collection col = MessagesManager.getAvailableLocales(); for (Iterator iter = col.iterator(); iter.hasNext();) { Locale locale = (Locale) iter.next(); String code = locale.getLanguage(); if (StringUtils.isNotEmpty(locale.getCountry())) { code += "_" + locale.getCountry(); //$NON-NLS-1$ } String name = locale.getDisplayName(MgnlContext.getLocale()); SelectOption option = new SelectOption(name, code); options.add(option); } // sort them Collections.sort(options, new Comparator() { public int compare(Object arg0, Object arg1) { try { String name0 = ((SelectOption) arg0).getLabel(); String name1 = ((SelectOption) arg1).getLabel(); return name0.compareTo(name1); } catch (Exception e) { return 0; } } }); this.setOptions(options); }