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

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

Source Link

Document

Returns the first element in iterable that satisfies the given predicate; use this method only when such an element is known to exist.

Usage

From source file:org.obiba.onyx.quartz.magma.AbstractQuartzBeanResolver.java

protected QuestionAnswer findQuestionAnswer(final QuestionnaireParticipant qp, final String questionName) {
    return Iterables.find(qp.getParticipantAnswers(), new Predicate<QuestionAnswer>() {
        public boolean apply(QuestionAnswer input) {
            return input.isActive() && input.getQuestionName().equals(questionName);
        }//from  www  .  j  a  v  a 2 s  .  c  om
    });
}

From source file:org.apache.isis.viewer.wicket.ui.selector.dropdown.DropDownSelectorPanelAbstract.java

private void addUnderlyingViews(final String underlyingId, final T model, final ComponentFactory factory) {
    final List<ComponentFactory> componentFactories = findOtherComponentFactories(model, factory);

    final ComponentFactory selectedComponentFactory = Iterables.find(componentFactories,
            determineInitialFactory(model));
    if (componentFactories.size() > 1) {
        final Model<ComponentFactory> componentFactoryModel = new Model<ComponentFactory>();

        componentFactoryModel.setObject(selectedComponentFactory);

        final WebMarkupContainer views = new WebMarkupContainer(ID_VIEWS);

        final DropDownChoiceComponentFactory viewsDropDown = new DropDownChoiceComponentFactory(
                ID_VIEWS_DROP_DOWN, componentFactoryModel, componentFactories, this, underlyingId, model);
        views.addOrReplace(viewsDropDown);

        addOrReplace(views);/*from ww  w  .j  ava 2 s  .  c o m*/
    } else {
        permanentlyHide(ID_VIEWS);
    }
    addOrReplace(selectedComponentFactory.createComponent(underlyingId, model));
}

From source file:org.caleydo.view.tourguide.impl.LogRankMetricFactory.java

@Override
public void fillStateMachine(IStateMachine stateMachine, List<TablePerspective> existing, EWizardMode mode,
        TablePerspective source) {/*  www  .  j a  v  a  2 s. c o  m*/

    final RootState other = Iterables.find(stateMachine.getRootStates(), RootState.ARE_INHOMOGENOUSVARIABLES);
    for (RootState start : Iterables.filter(stateMachine.getRootStates(), RootState.ARE_STRATIFICATIONS)) {
        if (mode == EWizardMode.GLOBAL) {
            BothUpdateLogRankState browse = new BothUpdateLogRankState(start.getAdapter());
            stateMachine.addState("LogRankBrowse", browse);
            IState target = stateMachine.addState("LogRank",
                    new CreateLogRankState(other.getAdapter(), browse));
            stateMachine.addTransition(start,
                    new SimpleTransition(target, "Based on log-rank test score (survival)", null));
        } else if (mode == EWizardMode.INDEPENDENT) {
            IState browseStratification = start.getBrowseState();
            stateMachine.addTransition(start, new CreateLogRankTransition(browseStratification, source));
        }
    }
}

From source file:org.jclouds.openstack.nova.v2_0.predicates.FindSecurityGroupWithNameAndReturnTrue.java

public boolean apply(AtomicReference<ZoneAndName> securityGroupInZoneRef) {
    checkNotNull(securityGroupInZoneRef, "securityGroupRef");
    final ZoneAndName securityGroupInZone = checkNotNull(securityGroupInZoneRef.get(), "securityGroupInZone");

    Optional<? extends SecurityGroupApi> api = novaApi
            .getSecurityGroupExtensionForZone(securityGroupInZone.getZone());
    checkArgument(api.isPresent(), "Security groups are required, but the extension is not available!");

    logger.trace("looking for security group %s", securityGroupInZone.slashEncode());
    try {//from   w  ww . ja v  a2s .c  om
        SecurityGroup returnVal = Iterables.find(api.get().list(), new Predicate<SecurityGroup>() {

            @Override
            public boolean apply(SecurityGroup input) {
                return input.getName().equals(securityGroupInZone.getName());
            }

        });
        securityGroupInZoneRef.set(new SecurityGroupInZone(returnVal, securityGroupInZone.getZone()));
        return true;
    } catch (ResourceNotFoundException e) {
        return false;
    } catch (NoSuchElementException e) {
        return false;
    }
}

From source file:org.loadui.testfx.service.finder.impl.WindowFinderImpl.java

public Window window(String stageTitleRegex) {
    List<Window> windows = listWindows();
    return Iterables.find(windows, hasStageTitlePredicate(stageTitleRegex));
}

From source file:org.droidphy.core.network.raft.HttpClusterConfig.java

@Override
public Replica getReplica(String info) {
    Uri uri = Uri.parse(info);//  ww w  . j a v a2 s  .c o m

    if (local.match(uri))
        return local;

    return Iterables.find(remote(), match(uri));
}

From source file:org.jclouds.openstack.nova.v1_1.predicates.FindSecurityGroupWithNameAndReturnTrue.java

public boolean apply(AtomicReference<ZoneAndName> securityGroupInZoneRef) {
    checkNotNull(securityGroupInZoneRef, "securityGroupRef");
    final ZoneAndName securityGroupInZone = checkNotNull(securityGroupInZoneRef.get(), "securityGroupInZone");

    Optional<SecurityGroupClient> client = novaClient
            .getSecurityGroupExtensionForZone(securityGroupInZone.getZone());
    checkArgument(client.isPresent(), "Security groups are required, but the extension is not available!");

    logger.trace("looking for security group %s", securityGroupInZone.slashEncode());
    try {//w ww  .j  a  v a2s.  c o  m
        SecurityGroup returnVal = Iterables.find(client.get().listSecurityGroups(),
                new Predicate<SecurityGroup>() {

                    @Override
                    public boolean apply(SecurityGroup input) {
                        return input.getName().equals(securityGroupInZone.getName());
                    }

                });
        securityGroupInZoneRef.set(new SecurityGroupInZone(returnVal, securityGroupInZone.getZone()));
        return true;
    } catch (ResourceNotFoundException e) {
        return false;
    } catch (NoSuchElementException e) {
        return false;
    }
}

From source file:org.ow2.play.governance.groups.ResourceHelper.java

public static final String getValue(final MetaResource metaResource, final String key, final String def) {
    String result = null;/*from   w w w . j a v  a2 s .  c om*/
    try {
        Metadata md = Iterables.find(metaResource.getMetadata(), new Predicate<Metadata>() {
            public boolean apply(Metadata input) {
                return input.getName().equals(key);
            };
        });
        if (md.getData() != null && md.getData().size() > 0) {
            result = md.getData().get(0).getValue();
        } else {
            result = def;
        }
    } catch (NoSuchElementException e) {
        result = def;
    }
    return result;
}

From source file:org.richfaces.cdk.model.ModelSet.java

@Override
public E find(final Predicate<? super E> predicate) {
    try {//from  www.  j  a  v a 2  s.co m
        return Iterables.find(elements, predicate);
    } catch (NoSuchElementException e) {
        return null;
    }
}

From source file:org.yakindu.sct.domain.extension.DomainRegistry.java

public static boolean domainExists(final String domainID) {
    try {// ww  w .ja  v  a2 s.c o  m
        Iterables.find(getDomains(), new Predicate<IDomain>() {
            @Override
            public boolean apply(IDomain input) {
                return input.getDomainID()
                        .equals(domainID == null || domainID.isEmpty()
                                ? BasePackage.Literals.DOMAIN_ELEMENT__DOMAIN_ID.getDefaultValueLiteral()
                                : domainID);
            }
        });
    } catch (NoSuchElementException e) {
        return false;
    }
    return true;
}