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:gov.nih.nci.firebird.selenium2.pages.investigator.profile.AbstractSpecialtyCredentialSectionHelper.java

private SpecialtyCredentialListing getListingByValues(final SpecialtyCredential credential) {
    return (SpecialtyCredentialListing) Iterables.find(section.getListings(),
            new Predicate<SpecialtyCredentialListing>() {
                @Override//from www. ja  v  a 2  s .co m
                public boolean apply(SpecialtyCredentialListing listing) {
                    return isEquivalent(credential, listing);
                }
            }, null);
}

From source file:gov.nih.nci.firebird.selenium2.pages.investigator.protocol.registration.HumanResearchCertificateTabHelper.java

public CertificateListing getListing(final Certificate certificate) {
    return Iterables.find(getTab().getCertificates(), new Predicate<CertificateListing>() {
        @Override/* ww  w.  j  a va 2s .  c  o  m*/
        public boolean apply(CertificateListing listing) {
            return isEquivalent(certificate, listing);
        }
    }, null);
}

From source file:zookeeper.example.discovery.DiscoveryExample.java

private static void deleteInstance(String[] args, String command, List<ExampleServer> servers) {
    // simulate a random instance going down
    // in a real application, this would occur due to normal operation, a crash, maintenance, etc.

    if (args.length != 1) {
        System.err.println("syntax error (expected delete <name>): " + command);
        return;//from ww w. j  a  v  a2 s.  c  o m
    }

    final String serviceName = args[0];
    ExampleServer server = Iterables.find(servers, new Predicate<ExampleServer>() {
        @Override
        public boolean apply(ExampleServer server) {
            return server.getThisInstance().getName().endsWith(serviceName);
        }
    }, null);
    if (server == null) {
        System.err.println("No servers found named: " + serviceName);
        return;
    }

    servers.remove(server);
    Closeables.closeQuietly(server);
    System.out.println("Removed a random instance of: " + serviceName);
}

From source file:com.synflow.cx.CxUtil.java

/**
 * Returns the function in the given module that has the given name, or <code>null</code>.
 * /*from ww w.ja v  a  2  s.  co m*/
 * @param module
 *            a module
 * @param name
 *            name of a function
 * @return a function, or <code>null</code>
 */
public static Variable getFunction(Task task, final String name) {
    return Iterables.find(getFunctions(task), new Predicate<Variable>() {
        @Override
        public boolean apply(Variable variable) {
            return name.equals(variable.getName());
        }
    }, null);
}

From source file:gov.nih.nci.firebird.selenium2.pages.util.FirebirdTableUtils.java

public static <T extends TableListing> T getListing(List<T> listings, final PersistentObject persistentObject) {
    return Iterables.find(listings, new Predicate<T>() {
        @Override/*w  ww .  j a v a2s.  c  om*/
        public boolean apply(T listing) {
            return ObjectUtils.equals(listing.getId(), persistentObject.getId());
        }
    }, null);
}

From source file:ru.ksu.niimm.cll.mocassin.crawl.parser.latex.StructureBuilderImpl.java

private String extractName(OutlineNode node, LatexDocumentModel model) {
    String nodeName;/*from ww w. j av  a2 s  . co  m*/
    switch (node.getType()) {
    case OutlineNode.TYPE_SECTION:
        nodeName = "section";
        break;
    case OutlineNode.TYPE_SUBSECTION:
        nodeName = "subsection";
        break;
    case OutlineNode.TYPE_SUBSUBSECTION:
        nodeName = "subsubsection";
        break;
    default: {
        nodeName = node.getName();
        NewtheoremCommand foundCommand = Iterables.find(model.getNewtheorems(),
                new NewtheoremCommand.KeyPredicate(nodeName), null);
        if (foundCommand != null) {
            nodeName = foundCommand.getTitle();
        }
    }
    }
    return nodeName;
}

From source file:org.apache.curator.example.DiscoveryExample.java

private static void deleteInstance(String[] args, String command, List<ExampleServer> servers) {
    // simulate a random instance going down
    // in a real application, this would occur due to normal operation, a
    // crash, maintenance, etc.

    if (args.length != 1) {
        System.err.println("syntax error (expected delete <name>): " + command);
        return;//from   ww  w  . j a  v  a2s.  c  o m
    }

    final String serviceName = args[0];
    ExampleServer server = Iterables.find(servers, new Predicate<ExampleServer>() {
        @Override
        public boolean apply(ExampleServer server) {
            return server.getThisInstance().getName().endsWith(serviceName);
        }
    }, null);
    if (server == null) {
        System.err.println("No servers found named: " + serviceName);
        return;
    }

    servers.remove(server);
    CloseableUtils.closeQuietly(server);
    System.out.println("Removed a random instance of: " + serviceName);
}

From source file:gov.nih.nci.firebird.selenium2.pages.investigator.protocol.registration.Form1572SectionHelper.java

private Form1572OrganizationAssociationListing getListingByValues(final Organization organization) {
    return Iterables.find(section.getListings(), new Predicate<Form1572OrganizationAssociationListing>() {
        @Override//from w  w w  . j a v  a  2s .co m
        public boolean apply(Form1572OrganizationAssociationListing listing) {
            return isEquivalent(organization, listing);
        }
    }, null);
}

From source file:gov.nih.nci.firebird.selenium2.pages.sponsor.protocol.review.ReviewRegistrationOverviewTabHelper.java

public RegistrationListing getListing(final Person newSubInvestigator) {
    return Iterables.find(tab.getListings(), new Predicate<RegistrationListing>() {
        @Override//from w ww. j  ava  2s  . c  o m
        public boolean apply(RegistrationListing listing) {
            return listing.getInvestigator().equals(newSubInvestigator.getDisplayNameForList());
        }
    }, null);
}

From source file:com.sfxie.extension.zookeeper.curator.discover.DiscoveryExample.java

private static void deleteInstance(String[] args, String command, List<ExampleServer> servers) {
    // simulate a random instance going down
    // in a real application, this would occur due to normal operation, a crash, maintenance, etc.

    if (args.length != 1) {
        System.err.println("syntax error (expected delete <name>): " + command);
        return;/*from  w  w  w . j a v a 2  s.  c o m*/
    }

    final String serviceName = args[0];
    ExampleServer server = Iterables.find(servers, new Predicate<ExampleServer>() {
        @Override
        public boolean apply(ExampleServer server) {
            return server.getThisInstance().getName().endsWith(serviceName);
        }
    }, null);
    if (server == null) {
        System.err.println("No servers found named: " + serviceName);
        return;
    }

    servers.remove(server);
    CloseableUtils.closeQuietly(server);
    System.out.println("Removed a random instance of: " + serviceName);
}