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:com.netflix.exhibitor.core.state.UsState.java

public UsState(Exhibitor exhibitor) {
    config = exhibitor.getConfigManager().getConfig();
    serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC));
    us = Iterables.find(serverList.getSpecs(), ServerList.isUs(exhibitor.getThisJVMHostname()), null);
}

From source file:org.polarsys.reqcycle.traceability.types.configuration.typeconfiguration.util.ConfigUtils.java

public static Type getType(TypeConfigContainer container, final String id) {
    return Iterables.find(container.getTypes(), new Predicate<Type>() {
        public boolean apply(Type t) {
            return id.equals(t.getTypeId());
        }/*from www. j  av  a2 s.  co m*/
    }, null);
}

From source file:org.jclouds.abiquo.functions.ReturnFalseOn5xx.java

@Override
public Object apply(final Exception from) {
    Throwable exception = Iterables.find(Throwables.getCausalChain(from), hasResponse(from), null);

    if (exception != null) {
        HttpResponseException responseException = (HttpResponseException) exception;
        HttpResponse response = responseException.getResponse();

        if (response != null && response.getStatusCode() >= 500 && response.getStatusCode() < 600) {
            return false;
        }//w  w w  .j ava 2s. c  o m
    }

    throw Throwables.propagate(from);
}

From source file:org.jclouds.abiquo.functions.ReturnMovedResource.java

@Override
public T apply(final Exception from) {
    Throwable exception = Iterables.find(Throwables.getCausalChain(from), isMovedException(from), null);

    if (exception != null) {
        HttpResponseException responseException = (HttpResponseException) exception;
        HttpResponse response = responseException.getResponse();

        return getMovedEntity(response);
    }/*from  w w  w . ja  v  a 2  s.  co m*/

    throw Throwables.propagate(from);
}

From source file:org.jclouds.abiquo.functions.ReturnAbiquoExceptionOnNotFoundOr4xx.java

@Override
public Object apply(final Exception from) {
    Throwable exception = Iterables.find(Throwables.getCausalChain(from), isNotFoundAndHasAbiquoException(from),
            null);//from  www  .  j a v a2  s .co m

    throw Throwables.propagate(exception == null ? from : (AbiquoException) exception.getCause());
}

From source file:org.jclouds.abiquo.functions.ReturnNullOn303.java

@Override
public Object apply(final Exception from) {
    Throwable exception = Iterables.find(Throwables.getCausalChain(from), hasResponse(from), null);

    if (exception != null) {
        HttpResponseException responseException = (HttpResponseException) exception;
        HttpResponse response = responseException.getResponse();

        if (response != null && response.getStatusCode() == Status.SEE_OTHER.getStatusCode()) {
            return null;
        }/*from w w w  .j  a  v a  2 s  .c  o m*/
    }

    throw Throwables.propagate(from);
}

From source file:org.jclouds.abiquo.functions.ReturnFalseIfNotAvailable.java

@Override
public Object apply(final Exception from) {
    Throwable exception = Iterables.find(Throwables.getCausalChain(from), isNotAvailableException(from), null);

    if (exception != null) {
        if (exception instanceof HttpResponseException) {
            HttpResponseException responseException = (HttpResponseException) exception;
            HttpResponse response = responseException.getResponse();

            if (response != null && response.getStatusCode() >= 500 && response.getStatusCode() < 600) {
                return false;
            }/*from w ww  .j  a  va 2  s  . c o  m*/
        } else {
            // Will enter here when exception is a ResourceNotFoundException
            return false;
        }
    }

    throw Throwables.propagate(from);
}

From source file:com.b2international.snowowl.datastore.ContentAvailabilityInfoManager.java

/**
 * Returns with {@code true} if the underlying content is available for the
 * given tooling feature. /*from   w w w. j  ava  2s.c o  m*/
 * Otherwise returns with {@code false}.
 * @param repositoryUuid the unique repository UUID to check the content availability. 
 * @return {@code true} if the content is available.
 */
public boolean isAvailable(final String repositoryUuid) {
    return Iterables.find(getExtensions(EXTENSION_POINT_ID, ContentAvailabilityInfoProvider.class),
            new Predicate<ContentAvailabilityInfoProvider>() {
                public boolean apply(final ContentAvailabilityInfoProvider provider) {
                    return checkNotNull(repositoryUuid, "repositoryUuid").equals(provider.getRepositoryUuid());
                }
            }, ContentAvailabilityInfoProvider.NULL_IMPL).isAvailable();
}

From source file:org.polarsys.reqcycle.traceability.cache.emfbased.functions.Traceable2TraceableElement.java

@Override
public TraceableElement apply(Reachable arg0) {
    TraceableElement eleme = Iterables.find(model.getTraceables(), new TraceableEqualsToTraceableElement(arg0),
            null);/*from   ww w.  jav a2s .com*/
    if (eleme == null) {
        eleme = CacheTracabilityFactory.eINSTANCE.createTraceableElement();
        eleme.setUri(arg0.getURI().toString());
        for (String s : arg0.extraKeys()) {
            Property p = CacheTracabilityFactory.eINSTANCE.createProperty();
            p.setName(s);
            p.setValue(arg0.get(s));
            eleme.getProperties().add(p);
        }
        model.getTraceables().add(eleme);
    }
    return eleme;
}

From source file:org.solovyev.android.calculator.wizard.ListWizardFlow.java

@Nullable
@Override/*from   w  ww .  j  a  va 2  s.c  o m*/
public WizardStep getStep(@Nonnull final String name) {
    return Iterables.find(wizardSteps, new Predicate<WizardStep>() {
        @Override
        public boolean apply(@Nullable WizardStep step) {
            assert step != null;
            return step.getName().equals(name);
        }
    }, null);
}