@Override public Option<Application> apply(final Iterable<Application> applications) { return com.atlassian.fugue.Iterables.findFirst(applications, new Predicate<Application>() { @Override public boolean apply(final Application input) { boolean isPlatform = input instanceof PlatformApplication; boolean hasPostInstallStep = input.getPostInstallURI().isDefined(); if (log.isDebugEnabled()) { log.debug(String.format( "Application %s(%s), isPlatform %b, postInstallStep: %s", input.getName(), input.getKey(), isPlatform, input.getPostInstallURI())); } return !isPlatform && hasPostInstallStep; } }); } });
@Override public Option<PluginApplicationMetaData> getApplication(final ApplicationKey key) { return Iterables.findFirst(getApplications(), new Predicate<PluginApplicationMetaData>() { @Override public boolean apply(@Nullable final PluginApplicationMetaData input) { return input != null && input.getKey().equals(key); } }); }
public Option<String> getHttpHeaderFromLastRequest(final String name) { Predicate<String> equalsIgnoreCase = headerName -> headerName.equalsIgnoreCase(name); Option<String> maybeHeaderName = Iterables.findFirst(this.headersFromLastRequest.keySet(), equalsIgnoreCase); return maybeHeaderName.flatMap(headerName -> Option.option(headersFromLastRequest.get(headerName))); }
private <E> RegistrationStrategy<E> registrationStrategy() { return Iterables.findFirst(SUPPORTED_EXTRACTOR_TYPES.entrySet(), new Predicate<Map.Entry<Class<? extends EntitySearchExtractor>, RegistrationStrategy<?>>>() { @Override public boolean apply(final Map.Entry<Class<? extends EntitySearchExtractor>, RegistrationStrategy<?>> entry) { return entry.getKey().isAssignableFrom(getModuleClass()); } }).fold(new Supplier<RegistrationStrategy<E>>() { @Override public RegistrationStrategy<E> get() { throw new PluginException("Class " + getModuleClassName() + " is not implementing extractor for comment, issue or change history"); } }, new Function<Map.Entry<Class<? extends EntitySearchExtractor>, RegistrationStrategy<?>>, RegistrationStrategy<E>>() { @Override public RegistrationStrategy<E> apply(final Map.Entry<Class<? extends EntitySearchExtractor>, RegistrationStrategy<?>> entry) { // noinspection unchecked return (RegistrationStrategy<E>) entry.getValue(); } }); }
@Override public boolean verifyXsrfToken(HttpServletRequest servletRequest) { final Option<Cookie> cookie = Iterables.findFirst(ImmutableList.copyOf(servletRequest.getCookies()), new Predicate<Cookie>() { @Override public boolean apply(Cookie cookie) { return cookie.getName() .equals(tokenGenerator.getXsrfTokenName()); } } ); return cookie.isDefined() && tokenGenerator.validateToken(servletRequest, cookie.get().getValue()); } }
@Nonnull @Override public Option<ApplicationRoleDefinition> getDefined(final ApplicationKey applicationKey) { return findFirst(getDefined(), def -> def != null && def.key().equals(applicationKey)); }
private Option<PageElement> getDashboardElement(final String dashboardName) { final List<PageElement> dashboards = dropDown().find(By.id("dashboard_link_main")).findAll(By.tagName("a")); return Iterables.findFirst(dashboards, new Predicate<PageElement>() { @Override public boolean apply(final PageElement dashboard) { final String tabName = dashboard.getAttribute("title"); return tabName.equals(dashboardName); } }); }
@Override @Nullable public String getTabContentHtml(final String panelKey, ActionDescriptor action, JiraWorkflow workflow) { final Map<String, Object> context = createContext(action, workflow); final Iterable<WebPanelModuleDescriptor> panels = getDisplayableWebPanelDescriptors(context); final Option<WebPanelModuleDescriptor> tabDescriptor = com.atlassian.fugue.Iterables.findFirst(panels, new Predicate<WebPanelModuleDescriptor>() { @Override public boolean apply(final WebPanelModuleDescriptor input) { return Objects.equal(input.getKey(), panelKey); } } ); return Iterables.getFirst(SafePluginPointAccess.to().descriptors(tabDescriptor, new PluginPointFunction<WebPanelModuleDescriptor, WebPanel, String>() { @Override public String onModule(final WebPanelModuleDescriptor moduleDescriptor, final WebPanel module) { return moduleDescriptor.getModule().getHtml(context); } } ), null); }