Example usage for com.google.common.collect Iterables any

List of usage examples for com.google.common.collect Iterables any

Introduction

In this page you can find the example usage for com.google.common.collect Iterables any.

Prototype

public static <T> boolean any(Iterable<T> iterable, Predicate<? super T> predicate) 

Source Link

Document

Returns true if any element in iterable satisfies the predicate.

Usage

From source file:gov.nih.nci.firebird.test.data.SubinvestigatorRegistrationBuilder.java

private boolean isPersonAlreadySubinvestigator(InvestigatorRegistration primaryRegistration,
        final Person person) {
    return Iterables.any(primaryRegistration.getProfile().getSubInvestigators(),
            new Predicate<SubInvestigator>() {
                public boolean apply(SubInvestigator subInvestigator) {
                    return subInvestigator.getPerson().equals(person);
                }//from w ww .ja  va  2  s . c o  m
            });
}

From source file:org.auraframework.impl.css.token.TokenCacheImpl.java

@Override
public Set<String> getNames(Iterable<DefDescriptor<TokensDef>> f) throws QuickFixException {
    final Set<DefDescriptor<TokensDef>> filter = f != null ? ImmutableSet.copyOf(f) : null;
    Set<String> names = new HashSet<>();

    final Predicate<DefDescriptor<TokensDef>> predicate = new Predicate<DefDescriptor<TokensDef>>() {
        @Override/*from w w  w  .jav a2 s. c o m*/
        public boolean apply(DefDescriptor<TokensDef> desc) {
            return filter.contains(desc);
        }
    };

    for (DefDescriptor<TokensDef> descriptor : descriptors) {
        if (filter == null
                || (filter.contains(descriptor) || Iterables.any(originals.get(descriptor), predicate))) {
            Iterables.addAll(names, definitionService.getDefinition(descriptor).getAllNames());
            names.addAll(dynamicTokens.column(descriptor).keySet());
        }
    }

    return names;
}

From source file:org.eclipse.xtext.junit4.validation.AssertableDiagnostics.java

public AssertableDiagnostics assertAny(DiagnosticPredicate... predicates) {
    for (DiagnosticPredicate predicate : predicates)
        if (Iterables.any(getAllDiagnostics(), predicate))
            return this;
    fail("predicate not found");
    return this;
}

From source file:ratpack.file.internal.DefaultFileHttpTransmitter.java

private boolean isContentTypeCompressible() {
    final String contentType = httpHeaders.get(HttpHeaderConstants.CONTENT_TYPE);
    Predicate<String> contentTypeMatch = new PrefixMatchPredicate(contentType);
    return (compressionMimeTypeWhiteList == null
            || (contentType != null && Iterables.any(compressionMimeTypeWhiteList, contentTypeMatch)))
            && (contentType == null || !Iterables.any(compressionMimeTypeBlackList, contentTypeMatch));
}

From source file:elaborate.editor.model.orm.User.java

public boolean hasUserSetting(final String key) {
    return Iterables.any(Lists.newArrayList(getUserSettings()), userSettingWithKey(key));
}

From source file:org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences.java

public static NetconfSessionPreferences fromStrings(final Collection<String> capabilities) {
    final Set<QName> moduleBasedCaps = new HashSet<>();
    final Set<String> nonModuleCaps = Sets.newHashSet(capabilities);

    for (final String capability : capabilities) {
        final int qmark = capability.indexOf('?');
        if (qmark == -1) {
            continue;
        }/*from   w ww  .j a  va 2 s. c o m*/

        final String namespace = capability.substring(0, qmark);
        final Iterable<String> queryParams = AMP_SPLITTER.split(capability.substring(qmark + 1));
        final String moduleName = MODULE_PARAM.from(queryParams);
        if (Strings.isNullOrEmpty(moduleName)) {
            continue;
        }

        String revision = REVISION_PARAM.from(queryParams);
        if (!Strings.isNullOrEmpty(revision)) {
            addModuleQName(moduleBasedCaps, nonModuleCaps, capability,
                    cachedQName(namespace, revision, moduleName));
            continue;
        }

        /*
         * We have seen devices which mis-escape revision, but the revision may not
         * even be there. First check if there is a substring that matches revision.
         */
        if (Iterables.any(queryParams, CONTAINS_REVISION)) {

            LOG.debug("Netconf device was not reporting revision correctly, trying to get amp;revision=");
            revision = BROKEN_REVISON_PARAM.from(queryParams);
            if (Strings.isNullOrEmpty(revision)) {
                LOG.warn("Netconf device returned revision incorrectly escaped for {}, ignoring it",
                        capability);
                addModuleQName(moduleBasedCaps, nonModuleCaps, capability, cachedQName(namespace, moduleName));
            } else {
                addModuleQName(moduleBasedCaps, nonModuleCaps, capability,
                        cachedQName(namespace, revision, moduleName));
            }
            continue;
        }

        // Fallback, no revision provided for module
        addModuleQName(moduleBasedCaps, nonModuleCaps, capability, cachedQName(namespace, moduleName));
    }

    return new NetconfSessionPreferences(ImmutableSet.copyOf(nonModuleCaps),
            ImmutableSet.copyOf(moduleBasedCaps));
}

From source file:org.gradle.model.internal.manage.schema.extract.StructStrategy.java

public <R> ModelSchemaExtractionResult<R> extract(final ModelSchemaExtractionContext<R> extractionContext,
        final ModelSchemaCache cache) {
    ModelType<R> type = extractionContext.getType();
    Class<? super R> clazz = type.getRawClass();
    if (clazz.isAnnotationPresent(Managed.class)) {
        validateType(type, extractionContext);

        Iterable<Method> methods = Arrays.asList(clazz.getMethods());
        if (!clazz.isInterface()) {
            methods = filterIgnoredMethods(methods);
        }//w ww.  ja  v  a2s.c  om
        ImmutableListMultimap<String, Method> methodsByName = Multimaps.index(methods,
                new Function<Method, String>() {
                    public String apply(Method method) {
                        return method.getName();
                    }
                });

        ensureNoOverloadedMethods(extractionContext, methodsByName);

        List<ModelProperty<?>> properties = Lists.newLinkedList();
        List<Method> handled = Lists.newArrayListWithCapacity(clazz.getMethods().length);
        ReturnTypeSpecializationOrdering returnTypeSpecializationOrdering = new ReturnTypeSpecializationOrdering();

        for (String methodName : methodsByName.keySet()) {
            if (methodName.startsWith("get") && !methodName.equals("get")) {
                ImmutableList<Method> getterMethods = methodsByName.get(methodName);

                // The overload check earlier verified that all methods for are equivalent for our purposes
                // So, taking the first one with the most specialized return type is fine.
                Method sampleMethod = returnTypeSpecializationOrdering.max(getterMethods);

                boolean abstractGetter = Modifier.isAbstract(sampleMethod.getModifiers());

                if (sampleMethod.getParameterTypes().length != 0) {
                    throw invalidMethod(extractionContext, "getter methods cannot take parameters",
                            sampleMethod);
                }

                Character getterPropertyNameFirstChar = methodName.charAt(3);
                if (!Character.isUpperCase(getterPropertyNameFirstChar)) {
                    throw invalidMethod(extractionContext,
                            "the 4th character of the getter method name must be an uppercase character",
                            sampleMethod);
                }

                ModelType<?> returnType = ModelType.returnType(sampleMethod);

                String propertyNameCapitalized = methodName.substring(3);
                String propertyName = StringUtils.uncapitalize(propertyNameCapitalized);
                String setterName = "set" + propertyNameCapitalized;
                ImmutableList<Method> setterMethods = methodsByName.get(setterName);

                boolean isWritable = !setterMethods.isEmpty();
                if (isWritable) {
                    Method setter = setterMethods.get(0);

                    if (!abstractGetter) {
                        throw invalidMethod(extractionContext,
                                "setters are not allowed for non-abstract getters", setter);
                    }
                    validateSetter(extractionContext, returnType, setter);
                    handled.addAll(setterMethods);
                }

                if (abstractGetter) {
                    ImmutableSet<ModelType<?>> declaringClasses = ImmutableSet
                            .copyOf(Iterables.transform(getterMethods, new Function<Method, ModelType<?>>() {
                                public ModelType<?> apply(Method input) {
                                    return ModelType.of(input.getDeclaringClass());
                                }
                            }));

                    boolean unmanaged = Iterables.any(getterMethods, new Predicate<Method>() {
                        public boolean apply(Method input) {
                            return input.getAnnotation(Unmanaged.class) != null;
                        }
                    });

                    properties.add(ModelProperty.of(returnType, propertyName, isWritable, declaringClasses,
                            unmanaged));
                }
                handled.addAll(getterMethods);
            }
        }

        Iterable<Method> notHandled = Iterables.filter(methodsByName.values(),
                Predicates.not(Predicates.in(handled)));

        // TODO - should call out valid getters without setters
        if (!Iterables.isEmpty(notHandled)) {
            throw invalidMethods(extractionContext, "only paired getter/setter methods are supported",
                    notHandled);
        }

        Class<R> concreteClass = type.getConcreteClass();
        Class<? extends R> implClass = classGenerator.generate(concreteClass);
        final ModelStructSchema<R> schema = ModelSchema.struct(type, properties, implClass);
        extractionContext.addValidator(new Action<ModelSchemaExtractionContext<R>>() {
            @Override
            public void execute(ModelSchemaExtractionContext<R> validatorModelSchemaExtractionContext) {
                ensureCanBeInstantiated(extractionContext, schema);
            }
        });
        Iterable<ModelSchemaExtractionContext<?>> propertyDependencies = Iterables.transform(properties,
                new Function<ModelProperty<?>, ModelSchemaExtractionContext<?>>() {
                    public ModelSchemaExtractionContext<?> apply(final ModelProperty<?> property) {
                        return toPropertyExtractionContext(extractionContext, property, cache);
                    }
                });

        return new ModelSchemaExtractionResult<R>(schema, propertyDependencies);
    } else {
        return null;
    }
}

From source file:org.geoserver.importer.ImportContext.java

/**
 * We are going to scan all the Import Context Tasks and return "true" if any "isDirect".
 * //from  w  w  w . j a v  a  2s .  co m
 * "isDirect" means that the Importer will rely on uploaded data position to create the Store.
 * The uploaded data should be preserved, otherwise the Layer will be broken.
 * 
 * @return boolean
 */
public boolean isDirect() {
    boolean isDirect = Iterables.any(getTasks(), new Predicate<ImportTask>() {
        @Override
        public boolean apply(ImportTask input) {
            return input.isDirect();
        }
    });
    return isDirect;
}

From source file:edu.ucsb.eucalyptus.util.SystemUtil.java

private static boolean maybeRestrictedOp(String... command) {
    if (Iterables.any(Arrays.asList(command).subList(0, Math.min(command.length, 2)),
            restrictionFilter.get())) {/*from   ww  w .j ava2  s.  co m*/
        try {
            concurrentOps.acquire();
            LOG.debug("Started concurrent op: " + Joiner.on(" ").join(command));
            return true;
        } catch (Exception ex) {
            return false;
        }
    } else {
        return false;
    }
}

From source file:org.whitesource.bamboo.plugins.AgentTaskConfigurator.java

@Nullable
public static Job findMavenJob(@NotNull Chain chain) {
    for (Job job : chain.getAllJobs()) {
        if (Iterables.any(job.getBuildDefinition().getTaskDefinitions(), BambooPredicates
                .isTaskDefinitionPluginKeyEqual("com.atlassian.bamboo.plugins.maven:task.builder.mvn2"))) {
            return job;
        } else if (Iterables.any(job.getBuildDefinition().getTaskDefinitions(), BambooPredicates
                .isTaskDefinitionPluginKeyEqual("com.atlassian.bamboo.plugins.maven:task.builder.mvn3"))) {
            return job;
        }// w  w  w  .j a v  a  2  s  . c  o m
    }
    return null;
}