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

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

Introduction

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

Prototype

@Nullable
public static <T> T find(Iterable<? extends T> iterable, Predicate<? super T> predicate,
        @Nullable T defaultValue) 

Source Link

Document

Returns the first element in iterable that satisfies the given predicate, or defaultValue if none found.

Usage

From source file:org.eclipse.viatra.query.runtime.matchers.psystem.queries.BasePQuery.java

@Override
public PAnnotation getFirstAnnotationByName(String annotationName) {
    ensureInitializedSneaky();/*  w  ww. j  av a 2s  .  c o  m*/
    return Iterables.find(annotations, new AnnotationNameTester(annotationName), null);
}

From source file:org.eclipse.emf.compare.uml2.internal.postprocessor.extension.sequence.UMLExecutionSpecificationChangeFactory.java

/**
 * {@inheritDoc}/*w w w  . j  a va2 s  . co m*/
 * 
 * @see org.eclipse.emf.compare.uml2.internal.postprocessor.AbstractUMLChangeFactory#getDiscriminant(org.eclipse.emf.compare.Diff)
 */
@Override
protected EObject getDiscriminant(Diff input) {
    return Iterables.find(getDiscriminants(input), instanceOf(ExecutionSpecification.class), null);
}

From source file:com.xebialabs.overthere.cifs.PathMapper.java

/**
 * @param path the remotely accessible path to convert (minus the host name, i.e. beginning with the share)
 * @return the local path (using drive letters) corresponding to the path that is remotely accessible using SMB
 *//*from   w  w  w .  j  a va  2  s . c o  m*/
@VisibleForTesting
String toLocalPath(String path) {
    final String lowerCasePath = path.toLowerCase();
    // assumes correct format share or share\path
    String mappedShare = Iterables.find(pathsForShares.keySet(), new Predicate<String>() {
        @Override
        public boolean apply(String input) {
            return lowerCasePath.startsWith(input);
        }
    }, null);
    if (mappedShare != null) {
        return pathsForShares.get(mappedShare) + path.substring(mappedShare.length());
    } else if ((path.length() >= 2) && ADMIN_SHARE_PATTERN.matcher(path.substring(0, 2)).matches()) {
        return path.substring(0, 1) + DRIVE_DESIGNATOR + path.substring(2);
    } else {
        throw new IllegalArgumentException(
                format("Remote path name '%s' uses unrecognized (i.e. neither mapped nor administrative) share",
                        path));
    }
}

From source file:org.eclipse.emf.compare.uml2.internal.postprocessor.extension.clazz.UMLAssociationChangeFactory.java

/**
 * {@inheritDoc}//w w w  .j a  v a 2s.  com
 * 
 * @see org.eclipse.emf.compare.uml2.internal.postprocessor.AbstractUMLChangeFactory#getDiscriminant(org.eclipse.emf.compare.Diff)
 */
@Override
protected EObject getDiscriminant(Diff input) {
    return Iterables.find(getDiscriminants(input), instanceOf(Association.class), null);
}

From source file:com.slimgears.slimrepo.apt.MetaFields.java

private static <P extends PropertyInfo> P findAnnotatedField(Iterable<? extends P> fields,
        final Class<? extends Annotation> annotationClass) {
    return Iterables.find(fields, input -> input.getAnnotation(annotationClass) != null, null);
}

From source file:brooklyn.launcher.BrooklynLauncherRebindTestFixture.java

@Test
public void testRebindsToExistingApp() throws Exception {
    populatePersistenceDir(persistenceDir, EntitySpec.create(TestApplication.class).displayName("myorig"));

    // Rebind to the app we just started last time

    newLauncherDefault(PersistMode.REBIND).start();

    assertOnlyApp(lastMgmt(), TestApplication.class);
    assertNotNull(/*w  ww .  j  a  v  a  2  s. c  om*/
            Iterables.find(lastMgmt().getApplications(), EntityPredicates.displayNameEqualTo("myorig"), null),
            "apps=" + lastMgmt().getApplications());
}

From source file:org.openhab.binding.loxone.internal.LoxoneGenericBindingProvider.java

@Override
public LoxoneBindingConfig findLoxoneBindingConfigByUUID(final String instance, final String uuid) {
    Map.Entry<String, BindingConfig> entry = Iterables.find(bindingConfigs.entrySet(),
            new Predicate<Map.Entry<String, BindingConfig>>() {
                public boolean apply(Map.Entry<String, BindingConfig> entry) {
                    LoxoneBindingConfig config = (LoxoneBindingConfig) entry.getValue();
                    boolean matchesInstance = isDefaultLoxoneInstance(config.instance) ? true
                            : config.instance.equalsIgnoreCase(instance);
                    boolean matchesUUID = uuid.equalsIgnoreCase(config.uuid);
                    return matchesInstance && matchesUUID;
                }/*from   ww w .j  ava 2  s .c o m*/
            }, null);
    return (LoxoneBindingConfig) (entry == null ? null : entry.getValue());
}

From source file:com.technophobia.substeps.runner.CoreVersionChecker.java

public void checkVersion(MavenProject runningProject, List<Artifact> pluginsDependencies)
        throws MojoExecutionException {

    Dependency substepsCoreDependency = Iterables.find((List<Dependency>) runningProject.getTestDependencies(),
            IS_SUBSTEPS_CORE, null);/*from   w w w.  j  a  v  a 2  s.co m*/

    if (substepsCoreDependency == null) {

        log.warn("Invalid plugin configuration, no version of " + CORE_ARTIFACT_ID + " found");

    } else {
        MavenProject coreProject = loadProject(substepsCoreDependency);

        Dependency apiDependencyInCore = Iterables.find((List<Dependency>) coreProject.getDependencies(),
                IS_SUBSTEPS_API, null);

        Artifact apiArtifactInPlugin = Iterables.find(pluginsDependencies, ARTIFACT_IS_SUBSTEPS_API, null);

        assertSameVersion(apiDependencyInCore, apiArtifactInPlugin);
    }
}

From source file:net.bobah.mail.Searcher.java

private static final String contentType(final Headers reqHeaders) {
    final String reqContentType = reqHeaders.getFirst(HttpHeaders.CONTENT_TYPE);
    String encoding = "utf-8";
    if (!Strings.isNullOrEmpty(reqContentType)) {
        final Iterable<String> params = headerValueSplitter.split(reqContentType);
        final String param = Iterables.find(params, new Predicate<String>() {
            @Override/*from w ww . ja va 2  s .c om*/
            public boolean apply(String param) {
                return param.startsWith("encoding=");
            }
        }, "encoding=utf-8");
        encoding = param.substring("encoding=".length());
    }
    return encoding;
}

From source file:org.sonar.server.computation.step.PersistComponentLinksStep.java

private void mergeLinks(DbSession session, String componentUuid, List<BatchReport.ComponentLink> links,
        List<ComponentLinkDto> previousLinks) {
    Set<String> linkType = newHashSet();
    for (final BatchReport.ComponentLink link : links) {
        String type = convertType(link.getType());
        if (!linkType.contains(type)) {
            linkType.add(type);/*from w  w  w  .  j a  va  2 s.  c o m*/
        } else {
            throw new IllegalArgumentException(String.format(
                    "Link of type '%s' has already been declared on component '%s'", type, componentUuid));
        }

        ComponentLinkDto previousLink = Iterables.find(previousLinks, new Predicate<ComponentLinkDto>() {
            @Override
            public boolean apply(@Nullable ComponentLinkDto input) {
                return input != null && input.getType().equals(convertType(link.getType()));
            }
        }, null);
        if (previousLink == null) {
            dbClient.componentLinkDao().insert(session,
                    new ComponentLinkDto().setComponentUuid(componentUuid).setType(type)
                            .setName(i18n.message(Locale.ENGLISH, "project_links." + type, null))
                            .setHref(link.getHref()));
        } else {
            previousLink.setHref(link.getHref());
            dbClient.componentLinkDao().update(session, previousLink);
        }
    }

    for (ComponentLinkDto dto : previousLinks) {
        if (!linkType.contains(dto.getType()) && ComponentLinkDto.PROVIDED_TYPES.contains(dto.getType())) {
            dbClient.componentLinkDao().delete(session, dto.getId());
        }
    }
}