List of usage examples for java.util Comparator comparingInt
public static <T> Comparator<T> comparingInt(ToIntFunction<? super T> keyExtractor)
From source file:io.kamax.mxisd.invitation.InvitationManager.java
private String findHomeserverForDomain(String domain) { Optional<String> entryOpt = dns.findHost(domain); if (entryOpt.isPresent()) { String entry = entryOpt.get(); log.info("Found DNS overwrite for {} to {}", domain, entry); try {/*from ww w . j ava 2s . com*/ return new URL(entry).toString(); } catch (MalformedURLException e) { log.warn("Skipping homeserver Federation DNS overwrite for {} - not a valid URL: {}", domain, entry); } } log.debug("Performing SRV lookup for {}", domain); String lookupDns = getSrvRecordName(domain); log.info("Lookup name: {}", lookupDns); try { List<SRVRecord> srvRecords = new ArrayList<>(); Record[] rawRecords = new Lookup(lookupDns, Type.SRV).run(); if (rawRecords != null && rawRecords.length > 0) { for (Record record : rawRecords) { if (Type.SRV == record.getType()) { srvRecords.add((SRVRecord) record); } else { log.info("Got non-SRV record: {}", record.toString()); } } srvRecords.sort(Comparator.comparingInt(SRVRecord::getPriority)); for (SRVRecord record : srvRecords) { log.info("Found SRV record: {}", record.toString()); return "https://" + record.getTarget().toString(true) + ":" + record.getPort(); } } else { log.info("No SRV record for {}", lookupDns); } } catch (TextParseException e) { log.warn("Unable to perform DNS SRV query for {}: {}", lookupDns, e.getMessage()); } log.info("Performing basic lookup using domain name {}", domain); return "https://" + domain + ":8448"; }
From source file:io.fd.maintainer.plugin.util.MaintainersIndex.java
private int mostSpecificPathLengthFromTuple(final MatchLevel maximumMatchLevel, final LinkedListMultimap<MatchLevel, Tuple2<ComponentPath, Maintainer>> byMatchIndex) { return byMatchIndex.get(maximumMatchLevel).stream().map(tuple -> tuple.a).map(ComponentPath::getPath) .map(MaintainersIndex::getPathLength).max(Comparator.comparingInt(integer -> integer)).orElse(0); }
From source file:io.fd.maintainer.plugin.util.MaintainersIndex.java
private int mostSpecificPathLengthFromComponent(final MatchLevel maximumMatchLevel, final LinkedListMultimap<MatchLevel, ComponentPath> byMatchIndex) { return byMatchIndex.get(maximumMatchLevel).stream().map(ComponentPath::getPath) .map(MaintainersIndex::getPathLength).max(Comparator.comparingInt(integer -> integer)).orElse(0); }
From source file:com.bwc.ora.OraUtils.java
/** * Create the anchor LRP. Does this by creating the LRP model and then adds * it to the LRP collections used by the application for storing LRPs for * analysis and display// w w w . j av a 2s . c o m * * @param assisted use fovea finding algorithm or manual click to identify * fovea */ public static void generateAnchorLrp(boolean assisted, JButton buttonToEnable) { OCTDisplayPanel octDisplayPanel = OCTDisplayPanel.getInstance(); LrpSettings lrpSettings = ModelsCollection.getInstance().getLrpSettings(); DisplaySettings displaySettings = ModelsCollection.getInstance().getDisplaySettings(); if (assisted) { JOptionPane.showMessageDialog(null, "Click and drag a window on the OCT which\n" + "contains the foveal pit, some of the vitrious,\n" + "and some of the Bruch's membrane and choroid.\n" + "ORA will the place a LRP at what it believes is\n" + "the center of the foveal pit.\n" + "\n" + "Use the arrow keys to move the LRP if desired after placement.\n" + "If any setting are adjusted while in this mode\n" + "you'll have to click the mouse on the OCT to regain\n" + "the ability to move the LRP with the arrow keys.", "Draw foveal pit window", JOptionPane.INFORMATION_MESSAGE); //allow the user to select region on screen where fovea should be found OctWindowSelector octWindowSelector = ModelsCollection.getInstance().getOctWindowSelector(); MouseInputAdapter selectorMouseListener = new MouseInputAdapter() { Point firstPoint = null; Point secondPoint = null; Point lastWindowPoint = null; @Override public void mousePressed(MouseEvent e) { Collections.getInstance().getOctDrawnLineCollection().clear(); Collections.getInstance().getLrpCollection().clearLrps(); if ((firstPoint = octDisplayPanel.convertPanelPointToOctPoint(e.getPoint())) != null) { octWindowSelector.setDisplay(true); displaySettings.setDisplaySelectorWindow(true); } } @Override public void mouseReleased(MouseEvent e) { secondPoint = octDisplayPanel.convertPanelPointToOctPoint(e.getPoint()); octWindowSelector.setDisplay(false); displaySettings.setDisplaySelectorWindow(false); octDisplayPanel.removeMouseListener(this); octDisplayPanel.removeMouseMotionListener(this); OctPolyLine ilm = ILMsegmenter.segmentILM(firstPoint, secondPoint == null ? lastWindowPoint : secondPoint); Collections.getInstance().getOctDrawnLineCollection().add(ilm); //use ILM segmented line to find local minima and place LRP Point maxYPoint = ilm.stream().max(Comparator.comparingInt(p -> p.y)).orElse(ilm.get(0)); int fovealCenterX = (int) Math.round(ilm.stream().filter(p -> p.y == maxYPoint.y) .mapToInt(p -> p.x).average().getAsDouble()); Lrp newLrp; try { newLrp = new Lrp("Fovea", fovealCenterX, Oct.getInstance().getImageHeight() / 2, lrpSettings.getLrpWidth(), lrpSettings.getLrpHeight(), LrpType.FOVEAL); lrpCollection.setLrps(Arrays.asList(newLrp)); octDisplayPanel.removeMouseListener(this); if (buttonToEnable != null) { buttonToEnable.setEnabled(true); } } catch (LRPBoundaryViolationException e1) { JOptionPane.showMessageDialog(null, e1.getMessage() + " Try again.", "LRP generation error", JOptionPane.ERROR_MESSAGE); return; } } @Override public void mouseDragged(MouseEvent e) { Point dragPoint; if ((dragPoint = octDisplayPanel.convertPanelPointToOctPoint(e.getPoint())) != null) { lastWindowPoint = dragPoint; int minX = Math.min(firstPoint.x, dragPoint.x); int minY = Math.min(firstPoint.y, dragPoint.y); int width = Math.max(firstPoint.x, dragPoint.x) - minX; int height = Math.max(firstPoint.y, dragPoint.y) - minY; octWindowSelector.setRect(minX, minY, width, height); displaySettings.setDisplaySelectorWindow(false); displaySettings.setDisplaySelectorWindow(true); } } }; octDisplayPanel.addMouseListener(selectorMouseListener); octDisplayPanel.addMouseMotionListener(selectorMouseListener); } else { JOptionPane.showMessageDialog(null, "Click on the OCT where the anchor LRP should go.\n" + "Use the arrow keys to move the LRP.\n" + "If any setting are adjusted while in this mode\n" + "you'll have to click the mouse on the OCT to regain\n" + "the ability to move the LRP with the arrow keys.", "Click anchor point", JOptionPane.INFORMATION_MESSAGE); //listen for the location on the screen where the user clicks, create LRP at location octDisplayPanel.addMouseListener(new MouseInputAdapter() { @Override public void mouseClicked(MouseEvent e) { Point clickPoint; if ((clickPoint = octDisplayPanel.convertPanelPointToOctPoint(e.getPoint())) != null) { Lrp newLrp; try { newLrp = new Lrp("Fovea", clickPoint.x, clickPoint.y, lrpSettings.getLrpWidth(), lrpSettings.getLrpHeight(), LrpType.FOVEAL); lrpCollection.setLrps(Arrays.asList(newLrp)); octDisplayPanel.removeMouseListener(this); if (buttonToEnable != null) { buttonToEnable.setEnabled(true); } } catch (LRPBoundaryViolationException e1) { JOptionPane.showMessageDialog(null, e1.getMessage() + " Try again.", "LRP generation error", JOptionPane.ERROR_MESSAGE); return; } } } }); } }
From source file:com.kantenkugel.discordbot.jdocparser.JDoc.java
private static List<Documentation> getMethodDocs(JDocParser.ClassDocumentation classDoc, String methodName, String methodSig, boolean isFuzzy) { List<JDocParser.MethodDocumentation> docs = classDoc.methodDocs.get(methodName.toLowerCase()).stream() .sorted(Comparator.comparingInt(m -> m.argTypes.size())).collect(Collectors.toList()); List<JDocParser.MethodDocumentation> filteredDocs = docs.parallelStream() .filter(doc -> doc.matches(methodSig, isFuzzy)).collect(Collectors.toList()); switch (filteredDocs.size()) { case 1://from w w w. ja va2s .c om return Collections.singletonList(filteredDocs.get(0)); case 0: return Collections.unmodifiableList(docs); default: return Collections.unmodifiableList(filteredDocs); } }
From source file:com.cognifide.qa.bb.aem.touch.siteadmin.aem62.SiteadminPage.java
private void goForwardToDestination(String currentUrl, String destination) { ChildPageRow closestPage = getChildPageWindow().getChildPageRows().stream() .filter(childPage -> childPage.getHref().equals(destination)).findFirst() .orElseGet(() -> getChildPageWindow().getChildPageRows().stream() .collect(Collectors.toMap(Function.identity(), childPageRow -> StringUtils.difference(currentUrl, childPageRow.getHref()))) .entrySet().stream().min(Comparator.comparingInt(a -> a.getValue().length())).get() .getKey());// w ww .j a v a2 s . co m closestPage.click(); }
From source file:com.cognifide.qa.bb.aem.touch.siteadmin.aem62.SiteadminPage.java
private void goBackUsingNavigator(String destination, String currentUrl) { String closestPath = navigatorDropdown.getAvailablePaths().stream().distinct() .filter(path -> !currentUrl.equals(path)) .collect(Collectors.toMap(Function.identity(), path -> StringUtils.difference(path, destination))) .entrySet().stream().min(Comparator.comparingInt(a -> a.getValue().length())).get().getKey(); navigatorDropdown.selectByPath(closestPath); }
From source file:com.simiacryptus.mindseye.applications.ObjectLocationBase.java
/** * Gets shuffle comparator./*from w w w . ja v a2 s. c o m*/ * * @param <T> the type parameter * @return the shuffle comparator */ public <T> Comparator<T> getShuffleComparator() { final int seed = (int) ((System.nanoTime() >>> 8) % (Integer.MAX_VALUE - 84)); return Comparator.comparingInt(a1 -> System.identityHashCode(a1) ^ seed); }
From source file:net.dv8tion.jda.core.entities.impl.ReceivedMessage.java
@Override public String getContentStripped() { if (strippedContent != null) return strippedContent; synchronized (mutex) { if (strippedContent != null) return strippedContent; String tmp = getContentDisplay(); //all the formatting keys to keep track of String[] keys = new String[] { "*", "_", "`", "~~" }; //find all tokens (formatting strings described above) TreeSet<FormatToken> tokens = new TreeSet<>(Comparator.comparingInt(t -> t.start)); for (String key : keys) { Matcher matcher = Pattern.compile(Pattern.quote(key)).matcher(tmp); while (matcher.find()) tokens.add(new FormatToken(key, matcher.start())); }/* w w w. ja va2s . c o m*/ //iterate over all tokens, find all matching pairs, and add them to the list toRemove Deque<FormatToken> stack = new ArrayDeque<>(); List<FormatToken> toRemove = new ArrayList<>(); boolean inBlock = false; for (FormatToken token : tokens) { if (stack.isEmpty() || !stack.peek().format.equals(token.format) || stack.peek().start + token.format.length() == token.start) { //we are at opening tag if (!inBlock) { //we are outside of block -> handle normally if (token.format.equals("`")) { //block start... invalidate all previous tags stack.clear(); inBlock = true; } stack.push(token); } else if (token.format.equals("`")) { //we are inside of a block -> handle only block tag stack.push(token); } } else if (!stack.isEmpty()) { //we found a matching close-tag toRemove.add(stack.pop()); toRemove.add(token); if (token.format.equals("`") && stack.isEmpty()) //close tag closed the block inBlock = false; } } //sort tags to remove by their start-index and iteratively build the remaining string toRemove.sort(Comparator.comparingInt(t -> t.start)); StringBuilder out = new StringBuilder(); int currIndex = 0; for (FormatToken formatToken : toRemove) { if (currIndex < formatToken.start) out.append(tmp.substring(currIndex, formatToken.start)); currIndex = formatToken.start + formatToken.format.length(); } if (currIndex < tmp.length()) out.append(tmp.substring(currIndex)); //return the stripped text, escape all remaining formatting characters (did not have matching // open/close before or were left/right of block return strippedContent = out.toString().replace("*", "\\*").replace("_", "\\_").replace("~", "\\~"); } }
From source file:com.liferay.blade.cli.command.CreateCommand.java
private void _printTemplates() throws Exception { BladeCLI bladeCLI = getBladeCLI();/*from w w w .ja v a2 s.c om*/ Map<String, String> templates = BladeUtil.getTemplates(bladeCLI); List<String> templateNames = new ArrayList<>(BladeUtil.getTemplateNames(getBladeCLI())); Collections.sort(templateNames); Comparator<String> compareLength = Comparator.comparingInt(String::length); Stream<String> stream = templateNames.stream(); String longestString = stream.max(compareLength).get(); int padLength = longestString.length() + 2; for (String name : templateNames) { PrintStream out = bladeCLI.out(); out.print(StringUtils.rightPad(name, padLength)); bladeCLI.out(templates.get(name)); } }