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.sonar.api.batch.debt.internal.DefaultDebtModel.java

@Override
@CheckForNull//from  w  w w . j  a va  2 s .  co  m
public DebtCharacteristic characteristicByKey(final String key) {
    return Iterables.find(characteristicsByKey.values(), new MatchDebtCharacteristicKey(key), null);
}

From source file:org.sonar.core.technicaldebt.DefaultTechnicalDebtModel.java

@Override
@CheckForNull/*from   w  w w . j  av  a  2  s .c om*/
public DefaultCharacteristic characteristicById(final Integer id) {
    return Iterables.find(characteristics(), new Predicate<DefaultCharacteristic>() {
        @Override
        public boolean apply(DefaultCharacteristic input) {
            return input.id().equals(id);
        }
    }, null);
}

From source file:ru.ksu.niimm.cll.mocassin.frontend.viewer.server.ViewerServiceImpl.java

@Override
public ArticleInfo load(String uri) {
    ArticleMetadata metadata = ontologyResourceFacade.load(new OntologyResource(uri));
    if (metadata == null) {
        logger.warn("Not found metadata for URI='{}'. Stub will be returned", uri);
        metadata = new ArticleMetadata();
    }//from  www .  j  a v a 2  s  . c o m
    ArticleInfo info = new ArticleInfo();
    info.setKey(metadata.getCollectionId());
    info.setUri(metadata.getId());
    info.setTitle(metadata.getTitle());
    info.setCurrentSegmentUri(metadata.getCurrentSegmentUri());
    info.setCurrentPageNumber(metadata.getCurrentPageNumber());
    Set<Author> authors = metadata.getAuthors();
    List<String> authorNames = new ArrayList<String>();
    for (Author author : authors) {
        authorNames.add(author.getName());
    }
    info.setAuthors(authorNames);
    Link pdfLink = Iterables.find(metadata.getLinks(), new Link.PdfLinkPredicate(), Link.nullPdfLink());
    info.setPdfUri(pdfLink.getHref());
    return info;
}

From source file:org.gradle.model.internal.core.DomainObjectSetBackedModelMap.java

@Nullable
@Override
public T get(String name) {
    return Iterables.find(backingCollection, new HasNamePredicate<T>(name, namer), null);
}

From source file:controllers.factories.ViewModelFactory.java

private ViewModel createSpecific(Object model) {
    Reflections reflections = new Reflections("models",
            Play.application().getWrappedApplication().classloader());
    Set<Class<? extends ViewModel>> viewModelClasses = reflections.getSubTypesOf(ViewModel.class);

    List<Class<?>> modelCandidateClasses = ClassUtils.getAllSuperclasses(model.getClass());
    modelCandidateClasses.add(0, model.getClass());

    Class<?> availableModelClass = null;
    Class<? extends ViewModel> availableViewModelClass = null;
    for (final Class<?> modelSuperclass : modelCandidateClasses) {
        availableViewModelClass = Iterables.find(viewModelClasses, new Predicate<Class<? extends ViewModel>>() {
            @Override/*from   w  ww  .  j  a va 2 s.  c  o  m*/
            public boolean apply(Class<? extends ViewModel> viewModelClass) {
                return ClassUtils.getShortClassName(viewModelClass)
                        .equals(ClassUtils.getShortClassName(modelSuperclass) + "Model");
            }
        }, null);

        if (availableViewModelClass != null) {
            availableModelClass = modelSuperclass;
            break;
        }
    }

    if (availableModelClass == null) {
        return null;
    }

    try {
        Constructor<? extends ViewModel> constructor = availableViewModelClass
                .getConstructor(availableModelClass);
        return constructor.newInstance(model);
    } catch (Throwable e) {
        return null;
    }
}

From source file:org.eclipse.emf.compare.uml2.internal.postprocessor.extension.profile.UMLProfileApplicationChangeFactory.java

/**
 * {@inheritDoc}//w  ww.j a  v  a 2s  .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(ProfileApplication.class), null);
}

From source file:io.soabase.core.features.logging.LoggingReader.java

public File keyToFile(final String key) {
    LoggingFile foundFile = Iterables.find(listLoggingFiles(), new Predicate<LoggingFile>() {
        @Override//from  w w  w .  j  a va  2 s .  c  om
        public boolean apply(LoggingFile loggingFile) {
            return loggingFile.getKey().equals(key);
        }
    }, null);
    return (foundFile != null) ? foundFile.getFile() : null;
}

From source file:fr.putnami.pwt.plugin.code.client.token.evaluator.WordsTokenEvaluator.java

@Override
public Token<?> evaluate(CharacterScanner charScanner) {
    int charScanned = charScanner.read();
    if (this.wordDetector.isWordStart((char) charScanned)) {
        StringBuilder resultText = new StringBuilder();
        do {/*from   w  ww .j  av  a  2 s .  c o m*/
            resultText.append((char) charScanned);
            charScanned = charScanner.read();
        } while (this.isWordPart(charScanned));
        charScanner.unread();

        WordMatcher matcher = Iterables.find(this.wordMatchers, new WordMatcherSelector(resultText.toString()),
                null);

        TokenContent content = null;
        if (matcher != null) {
            content = matcher.getTokenContent();
        }
        if (content != null || this.defaultTokenContent != null) {
            content = content != null ? content : this.defaultTokenContent;
            return new SimpleToken<TokenContent>(charScanner.getMark(), resultText.toString(), content);
        }
        for (int i = 1; i < resultText.length(); i++) {
            charScanner.unread();
        }
    }
    charScanner.unread();
    return SimpleToken.UNDEFINED_TOKEN;
}

From source file:org.sonar.api.batch.debt.internal.DefaultDebtModel.java

@CheckForNull
public DebtCharacteristic characteristicById(int id) {
    return Iterables.find(characteristicsByKey.values(), new MatchDebtCharacteristicId(id), null);
}

From source file:de.cosmocode.commons.validation.AbstractRule.java

@Override
public T find(Iterable<T> iterable, T defaultValue) {
    Preconditions.checkNotNull(iterable, "Iterable");
    return Iterables.find(iterable, this, defaultValue);
}