private List<KeyboardShortcut> getShortcuts(final KeyboardShortcutManager.Context context, final List<KeyboardShortcut> shortcuts) { return new ArrayList<KeyboardShortcut>(CollectionUtil.filter(shortcuts, new Predicate<KeyboardShortcut>() { public boolean evaluate(final KeyboardShortcut input) { return context.equals(input.getContext()); } })); }
/** * Does the supplied {@link Iterator} contain anything that matches the predicate? * * @param <T> the element type * @param iterator containing elements * @param predicate the matcher * @return true if the predicate returns true for any elements. */ public static <T> boolean contains(@Nonnull final Iterator<? extends T> iterator, @Nonnull final Predicate<T> predicate) { return filter(iterator, predicate).hasNext(); }
public static <T, R> Iterable<R> transformAndFilter(final Iterable<T> iterable, final Function<T, R> transformer, final Predicate<R> predicate) { return filter(transform(iterable, transformer), predicate); }
/** * Returns all temporary attachments, which were bound to given form token. Form token may not be null. * * @param formToken * @return a collection of temporary attachments for this form token sorted by creation date */ public Collection<TemporaryAttachment> getByFormToken(final String formToken) { if(formToken == null) { return Collections.emptyList(); } final List<TemporaryAttachment> ret = new ArrayList<TemporaryAttachment>(CollectionUtil.filter(temporaryAttachments.values(), new Predicate<TemporaryAttachment>() { public boolean evaluate(final TemporaryAttachment input) { return formToken.equals(input.getFormToken()); } })); Collections.sort(ret); return ret; }
@Override public Collection<IssueLinkType> getIssueLinkTypes(boolean excludeSystemLinks) { Collection<IssueLinkType> types = ImmutableList.copyOf(cache.get().values()); if (!excludeSystemLinks) { return types; } return CollectionUtil.filter(types, new Predicate<IssueLinkType>() { @Override public boolean evaluate(final IssueLinkType type) { return !type.isSystemLinkType(); } }); }
final Iterator<String> disallowedIds = CollectionUtil.filter(projectStringIds.iterator(), new Predicate<String>()
/** * Filter a {@link Collection} for the specified subtype. * * @param <T> the incoming type * @param <R> the result type * @param iterable an iterable whose values are of the source type * @param subclass the result type, only return elements if they are of this type * @return a filtered {@link Collection} of the subtype */ public static <T, R extends T> Collection<R> filterByType(@Nonnull final Iterable<T> iterable, @Nonnull final Class<R> subclass) { return transform(filter(iterable, Predicates.<T> isInstanceOf(subclass)), Functions.<T, R> downcast(subclass)); }
@Override public void refreshLiveNodes() { final Collection<String> heartbeatLiveNodesIds = heartbeatServiceRef.get().findLiveNodes(); Collection<Node> filter = CollectionUtil.filter(getAllNodes(), new Predicate<Node>() { @Override public boolean evaluate(final Node node) { return node != null && node.getState() == ACTIVE && heartbeatLiveNodesIds.contains(node.getNodeId()); } }); liveNodes = ImmutableSet.<Node>copyOf(filter); }
private Collection<IssueLinkType> getIssueLinkTypesByPredicate(final Predicate<GenericValue> predicate) { final Collection<GenericValue> inwardLinkTypes = CollectionUtil.filter( queryDatabase(OfBizDelegator.ISSUE_LINK_TYPE, MapBuilder.<String, Object>emptyMap()), predicate); return buildIssueLinkTypes(inwardLinkTypes, false); }
public List<ProjectAndRole> getProjects(final ApplicationUser user) { final Collection<Project> projects = projectManager.getProjectObjects(); final ImmutableList.Builder<ProjectAndRole> resultsBuilder = ImmutableList.builder(); final Set<ProjectRoleActor> allRoleActorsForUser = roleActorFactory.getAllRoleActorsForUser(user); resultsBuilder.addAll(Iterables.transform(allRoleActorsForUser, new Function<ProjectRoleActor, ProjectAndRole>() { @Override public ProjectAndRole apply(final ProjectRoleActor simpleRoleActor) { return new ProjectAndRole(simpleRoleActor.getProjectId(), simpleRoleActor.getProjectRoleId()); } })); for (final Project project : CollectionUtil.filter(projects, new Predicate<Project>() { public boolean evaluate(final Project o) { return permissionManager.hasPermission(BROWSE_PROJECTS, o, user); } })) { resultsBuilder.add(new ProjectAndRole(project.getId())); } return resultsBuilder.build(); }
@GET @Path ("gadget/fields") @Produces (MediaType.APPLICATION_JSON) public Response getLabelFields() { @SuppressWarnings ("unchecked") final Collection<CustomField> labelCfTypes = CollectionUtil.filter( customFieldManager.getCustomFieldObjects(), new Predicate<CustomField>() { public boolean evaluate(final CustomField input) { return input.getCustomFieldType() instanceof LabelsCFType; } } ); final List<LabelField> labelFields = new ArrayList<LabelField>(labelCfTypes.size() + 1); labelFields.add(new LabelField(authenticationContext.getI18nHelper().getText("issue.field.labels"), IssueFieldConstants.LABELS)); for (CustomField labelCf : labelCfTypes) { LabelField labelField = new LabelField(labelCf.getName(), labelCf.getId()); labelFields.add(labelField); } return Response.ok(new LabelFields(labelFields)).cacheControl(NO_CACHE).build(); }
protected BooleanQuery generateRangeQueryForPredicate(final String fieldName, final Predicate<T> match) { final Collection<T> domainObjects = resolver.getAll(); BooleanQuery bq = new BooleanQuery(); for (T indexedObject : CollectionUtil.filter(domainObjects, match)) { bq.add(getTermQuery(fieldName, indexInfoResolver.getIndexedValue(indexedObject)), BooleanClause.Occur.SHOULD); } return bq; }
private Collection<TaskDescriptor<?>> findTasksInternal(final TaskMatcher matcher) { notNull("matcher", matcher); return toList(transform(filter(getTasks(taskMap), new TaskMatcherPredicate(matcher)), Functions.<TaskDescriptor<?>, TaskDescriptor<?>>coerceToSuper())); }
private JqlClauseBuilder getQueryForSubTasks(List<Issue> parentIssues, final boolean onlyIncludeUnresolved) { final List<Long> parentIssueIds = CollectionUtil.transform( CollectionUtil.filter(parentIssues, Predicates.notNull()), new Function<Issue, Long>() { public Long get(final Issue input) { return input.getId(); } }); JqlClauseBuilder builder = JqlQueryBuilder.newBuilder().where().issueParent().inNumbers(parentIssueIds); if (onlyIncludeUnresolved) { builder = builder.and().unresolved(); } return builder; } }