List of usage examples for java.util Comparator Comparator
Comparator
From source file:com.iflytek.edu.cloud.frame.spring.rest.ServiceMethodInfoHandlerMapping.java
/** * Provide a Comparator to sort RequestMappingInfos matched to a request. *//*from w w w . j av a 2 s . c o m*/ @Override protected Comparator<ServiceMethodInfo> getMappingComparator(final HttpServletRequest request) { return new Comparator<ServiceMethodInfo>() { @Override public int compare(ServiceMethodInfo info1, ServiceMethodInfo info2) { return info1.compareTo(info2, request); } }; }
From source file:biomine.bmvis2.pipeline.BestPathHiderOperation.java
private void hideNodes(VisualGraph graph, long target) { HashSet<VisualNode> hiddenNodes = new HashSet<VisualNode>(); ArrayList<VisualNode> nodes = new ArrayList<VisualNode>(graph.getAllNodes()); if (this.grader == null || nodes.size() <= target) { graph.hideNodes(hiddenNodes);/*from w w w. ja va 2s.c o m*/ return; } Collections.sort(nodes, new Comparator<VisualNode>() { public int compare(VisualNode node1, VisualNode node2) { return Double.compare(grader.getNodeGoodness(node2), grader.getNodeGoodness(node1)); } }); for (VisualNode node : nodes) { if (target == 0) break; hiddenNodes.add(node); target--; } graph.hideNodes(hiddenNodes); }
From source file:de.langmi.spring.batch.examples.readers.file.archive.ArchiveMultiResourceItemReader.java
/** * Tries to extract all files in the archives and adds them as resources to * the normal MultiResourceItemReader. Overwrites the Comparator from * the super class to get it working with itemstreams. * * @param executionContext/* w w w . java2 s . c om*/ * @throws ItemStreamException */ @Override public void open(ExecutionContext executionContext) throws ItemStreamException { // really used with archives? if (archives != null) { // overwrite the comparator to use description instead of filename this.setComparator(new Comparator<Resource>() { /** Compares resource descriptions. */ @Override public int compare(Resource r1, Resource r2) { return r1.getDescription().compareTo(r2.getDescription()); } }); // get the inputStreams from all files inside the archives wrappedArchives = new TFile[archives.length]; List<Resource> extractedResources = new ArrayList<Resource>(); try { for (int i = 0; i < archives.length; i++) { wrappedArchives[i] = new TFile(archives[i].getFile()); // iterate over each TFile and get the file list // extract only the files, ignore directories List<TFile> fileList = new ArrayList<TFile>(); runNestedDirs(wrappedArchives[i], fileList, filenameFilter); for (TFile tFile : fileList) { extractedResources .add(new InputStreamResource(new TFileInputStream(tFile), tFile.getName())); LOG.info("using extracted file:" + tFile.getName()); } } } catch (Exception ex) { throw new ItemStreamException(ex); } // propagate extracted resources this.setResources(extractedResources.toArray(new Resource[extractedResources.size()])); } super.open(executionContext); }
From source file:info.magnolia.cms.beans.config.URI2RepositoryManager.java
protected Comparator<URI2RepositoryMapping> getMappingComparator() { return new Comparator<URI2RepositoryMapping>() { @Override//from w w w . j ava 2 s . c o m public int compare(URI2RepositoryMapping m0, URI2RepositoryMapping m1) { return m1.getURIPrefix().compareTo(m0.getURIPrefix()); } }; }
From source file:com.couchbase.trombi.services.SearchService.java
public List<Coworker> findNearestTeamMembers(String teamName, String coworkerId) { List<Coworker> lc;/*from w ww . ja v a2s . com*/ if (teamName.equals("*")) lc = (List<Coworker>) coworkerRepository.findAll(); else lc = coworkerRepository.findByTeamIs(teamName); Coworker center = coworkerRepository.findOne(coworkerId); if (lc == null || lc.isEmpty() || center == null) { return Collections.emptyList(); } final int centerZoneOffset = center.getLastCheckin() == null ? center.getMainLocation().getTimeZoneOffset() : center.getLastCheckin().getTimeZoneOffset(); Comparator<Coworker> zoneComparator = new Comparator<Coworker>() { @Override public int compare(Coworker o1, Coworker o2) { int offset1 = o1.getLastCheckin() == null ? o1.getMainLocation().getTimeZoneOffset() : o1.getLastCheckin().getTimeZoneOffset(); int offset2 = o2.getLastCheckin() == null ? o2.getMainLocation().getTimeZoneOffset() : o2.getLastCheckin().getTimeZoneOffset(); int hourDiff1 = Math.abs(offset1 - centerZoneOffset); int hourDiff2 = Math.abs(offset2 - centerZoneOffset); return hourDiff1 - hourDiff2; } }; Collections.sort(lc, zoneComparator); return lc; }
From source file:funnycats.RankingController.java
private Map sortByRating(Map<?, ?> unsortedMap) { List list = new LinkedList(unsortedMap.entrySet()); // sort list based on comparator Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { return ((Comparable) ((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue()); }//from w w w . ja va2s.c o m }); Collections.reverse(list); // put sorted list into map again Map sortedMap = new LinkedHashMap(); for (Iterator it = list.iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); sortedMap.put(entry.getKey(), entry.getValue()); } return sortedMap; }
From source file:org.openmrs.module.hospitalcore.web.controller.ajax.AjaxController.java
/** * Concept search autocomplete for form/*from ww w.ja v a2s.c o m*/ * * @param name * @param model * @return */ @SuppressWarnings("deprecation") @RequestMapping(value = "/module/hospitalcore/ajax/autocompleteConceptSearch.htm", method = RequestMethod.GET) public String autocompleteConceptSearch(@RequestParam(value = "q", required = false) String name, Model model) { List<ConceptWord> cws = Context.getConceptService().findConcepts(name, new Locale("en"), false); Set<String> conceptNames = new HashSet<String>(); for (ConceptWord word : cws) { String conceptName = word.getConcept().getName().getName(); conceptNames.add(conceptName); } List<String> concepts = new ArrayList<String>(); concepts.addAll(conceptNames); Collections.sort(concepts, new Comparator<String>() { public int compare(String o1, String o2) { return o1.compareToIgnoreCase(o2); } }); model.addAttribute("conceptNames", concepts); return "/module/hospitalcore/ajax/autocompleteConceptSearch"; }
From source file:com.floreantpos.extension.ExtensionManager.java
private synchronized void initialize() { PluginManager pluginManager = PluginManagerFactory.createPluginManager(); String jarLocation = JarUtil.getJarLocation(Application.class); URI uri = new File(jarLocation).toURI(); pluginManager.addPluginsFrom(uri);//from w w w.j a v a2 s . com String pluginsPath = System.getProperty("pluginsPath"); //$NON-NLS-1$ if (StringUtils.isNotEmpty(pluginsPath)) { String[] paths = pluginsPath.split(","); //$NON-NLS-1$ for (String string : paths) { pluginManager.addPluginsFrom(new File(string).toURI()); } } else { pluginManager.addPluginsFrom(new File("plugins/").toURI()); //$NON-NLS-1$ } PluginManagerUtil pmUtil = new PluginManagerUtil(pluginManager); List<Plugin> allPlugins = (List<Plugin>) pmUtil.getPlugins(); //sort plugins java.util.Collections.sort(allPlugins, new Comparator<Plugin>() { @Override public int compare(Plugin o1, Plugin o2) { return o1.getClass().getName().compareToIgnoreCase(o2.getClass().getName()); } }); List<FloreantPlugin> floreantPlugins = new ArrayList<FloreantPlugin>(); for (Plugin plugin : allPlugins) { if (plugin instanceof FloreantPlugin) { FloreantPlugin floreantPlugin = (FloreantPlugin) plugin; if (floreantPlugin.requireLicense()) { floreantPlugin.initLicense(); if (floreantPlugin.hasValidLicense()) { floreantPlugins.add(floreantPlugin); } } else { floreantPlugins.add(floreantPlugin); } } } this.plugins = Collections.unmodifiableList(floreantPlugins); }
From source file:net.big_oh.algorithms.search.informed.astar.AStarSearch.java
public AStarSearchResult<SearchNodeType> doSearch(SearchNodeType startNode) { Duration searchDuration = new Duration(); // create priority queue SortedSet<SearchNodeType> prioritySet = new TreeSet<SearchNodeType>(new Comparator<SearchNodeType>() { public int compare(SearchNodeType o1, SearchNodeType o2) { switch (searchType) { case MIN: return Double.compare(getF(o1), getF(o2)); case MAX: return -1 * Double.compare(getF(o1), getF(o2)); default: throw new RuntimeException("Unexpected search type: " + searchType); }/*www .j a va2 s. co m*/ } }); // enqueue the start node prioritySet.add(startNode); // declare tracking member variables int numSearchNodesGenerated = 0; int numSearchNodesConsidered = 0; int maxPossibleBranchingFactor = 1; // search for a goal state SearchNodeType goalNode = null; while (!prioritySet.isEmpty()) { // Remove the best candidate node from the queue SearchNodeType candidateSearchNode = prioritySet.first(); prioritySet.remove(candidateSearchNode); numSearchNodesConsidered++; // get the next search node candidates Collection<SearchNodeType> nextSearchNodes = nextNodesGenerator.getNextSearchNodes(candidateSearchNode); // do some record keeping numSearchNodesGenerated += nextSearchNodes.size(); maxPossibleBranchingFactor = Math.max(maxPossibleBranchingFactor, nextSearchNodes.size()); if (candidateSearchNode.isGoalState()) { // sanity check assert (nextSearchNodes.isEmpty()); // found an optimal solution goalNode = candidateSearchNode; break; } else { // enqueue all next search nodes Duration enqueueDuration = new Duration(); prioritySet.addAll(nextSearchNodes); if (logger.isDebugEnabled()) { logger.debug("Enqueued " + nextSearchNodes.size() + " A* search nodes in " + enqueueDuration.stop() + " milliseconds."); } } } // return the search results AStarSearchResult<SearchNodeType> results = new AStarSearchResult<SearchNodeType>(goalNode, numSearchNodesGenerated, calculateEffectiveBranchingFactor(goalNode.getNodeDepth(), numSearchNodesConsidered, maxPossibleBranchingFactor)); logger.debug("Completed an A* search in " + searchDuration.stop() + " milliseconds."); logger.debug("Number of nodes generated: " + results.getNumSearchNodesGenerated()); logger.debug("Depth of goal node: " + results.getGoalNode().getNodeDepth()); logger.debug("Effective branching factor: " + results.getEfectiveBranchingFactor()); return results; }
From source file:interactivespaces.network.client.internal.ros.RosNetworkInformationClient.java
public RosNetworkInformationClient() { lowerCaseStringComparator = new Comparator<String>() { @Override//from ww w. j a v a2 s . com public int compare(String o1, String o2) { return o1.compareToIgnoreCase(o2); } }; networkTopicInformationComparator = new Comparator<NetworkTopicInformation>() { @Override public int compare(NetworkTopicInformation o1, NetworkTopicInformation o2) { return o1.getTopicName().compareToIgnoreCase(o2.getTopicName()); } }; networkNodeInformationComparator = new Comparator<NetworkNodeInformation>() { @Override public int compare(NetworkNodeInformation o1, NetworkNodeInformation o2) { return o1.getNodeName().compareToIgnoreCase(o2.getNodeName()); } }; }