List of usage examples for com.google.common.collect Iterables find
@Nullable public static <T> T find(Iterable<? extends T> iterable, Predicate<? super T> predicate, @Nullable T defaultValue)
From source file:ru.ksu.niimm.cll.mocassin.crawl.arxiv.ArxivDAOFacadeImpl.java
/** * {@inheritDoc}//from ww w. j ava 2 s . c om */ @Override public InputStream loadPDF(ArticleMetadata metadata) { Link pdfLink = Iterables.find(metadata.getLinks(), new PdfLinkPredicate(), null); if (pdfLink == null || (pdfLink.getHref() == null || pdfLink.getHref().length() == 0)) { logger.warn("Article metadata with id='{}' doesn't include PDF link; empty stream will be returned", metadata.getId()); return null; } InputStream inputStream = null; try { URL sourceUrl = new URL(pdfLink.getHref()); inputStream = loadFromUrl(sourceUrl, PDF_CONTENT_TYPE); } catch (MalformedURLException e) { logger.error("Failed to prepare source URL from: {}", pdfLink.getHref(), e); } catch (IOException e) { logger.error("Failed to get the source of {}", metadata.getId(), e); } if (isUseProxy) { Authenticator.setDefault(null); } return inputStream; }
From source file:org.onos.yangtools.yang.data.impl.codec.SchemaTracker.java
private Optional<SchemaNode> tryFindGroupings(final SchemaContext ctx, final QName qname) { return Optional .<SchemaNode>fromNullable(Iterables.find(ctx.getGroupings(), new SchemaNodePredicate(qname), null)); }
From source file:org.eclipse.incquery.runtime.api.impl.BaseQuerySpecification.java
@Override public PAnnotation getFirstAnnotationByName(String annotationName) { return Iterables.find(annotations, new AnnotationNameTester(annotationName), null); }
From source file:org.gradle.plugins.ide.idea.internal.IdeaScalaConfigurer.java
private static Map<String, ProjectLibrary> resolveScalaCompilerLibraries(Collection<Project> scalaProjects, boolean useScalaSdk) { Map<String, ProjectLibrary> scalaCompilerLibraries = Maps.newHashMap(); for (Project scalaProject : scalaProjects) { IdeaModule ideaModule = scalaProject.getExtensions().getByType(IdeaModel.class).getModule(); Iterable<File> files = getIdeaModuleLibraryDependenciesAsFiles(ideaModule); ProjectLibrary library = createScalaSdkLibrary(scalaProject, files, useScalaSdk, ideaModule); if (library != null) { ProjectLibrary duplicate = Iterables.find(scalaCompilerLibraries.values(), Predicates.equalTo(library), null); scalaCompilerLibraries.put(scalaProject.getPath(), duplicate == null ? library : duplicate); }//from ww w .j av a 2 s . co m } return scalaCompilerLibraries; }
From source file:org.onos.yangtools.yang.data.impl.codec.SchemaTracker.java
private Optional<SchemaNode> tryFindRpc(final SchemaContext ctx, final QName qname) { return Optional.<SchemaNode>fromNullable( Iterables.find(ctx.getOperations(), new SchemaNodePredicate(qname), null)); }
From source file:org.jclouds.location.suppliers.all.ZoneToRegionToProviderOrJustProvider.java
private Map<String, Location> setParentOfZoneToRegionOrProvider(Set<String> zoneIds, Set<? extends Location> locations) { // mutable, so that we can query current state when adding. safe as its temporary Map<String, Location> zoneIdToParent = Maps.newLinkedHashMap(); Location provider = Iterables.find(locations, LocationPredicates.isProvider(), null); if (locations.size() == 1 && provider != null) { for (String zone : zoneIds) zoneIdToParent.put(zone, provider); } else {/*from www. ja va2 s.c o m*/ // note that we only call regionIdToZoneIdsSupplier if there are region locations present // they cannot be, if the above is true Map<String, Supplier<Set<String>>> regionIdToZoneIds = regionIdToZoneIdsSupplier.get(); for (Location region : Iterables.filter(locations, LocationPredicates.isRegion())) { provider = region.getParent(); if (regionIdToZoneIds.containsKey(region.getId())) { for (String zoneId : regionIdToZoneIds.get(region.getId()).get()) zoneIdToParent.put(zoneId, region); } else { logger.debug("no zones configured for region: %s", region); } } } SetView<String> orphans = Sets.difference(zoneIds, zoneIdToParent.keySet()); if (orphans.size() > 0) { // any unmatched zones should have their parents set to the provider checkState(provider != null, "cannot configure zones %s as we need a parent, and the only available location [%s] is not a provider", zoneIds, locations); for (String orphanedZoneId : orphans) zoneIdToParent.put(orphanedZoneId, provider); } checkState(zoneIdToParent.keySet().containsAll(zoneIds), "orphaned zones: %s ", Sets.difference(zoneIds, zoneIdToParent.keySet())); return zoneIdToParent; }
From source file:ru.ksu.niimm.cll.mocassin.frontend.server.QueryServiceImpl.java
private List<ResultDescription> convertToResultDescriptions(List<ArticleMetadata> ontologyElements) { List<ResultDescription> resultDescriptions = new ArrayList<ResultDescription>(); for (ArticleMetadata ontologyElement : ontologyElements) { ResultDescription rd = new ResultDescription(); rd.setDocumentUri(ontologyElement.getId()); rd.setViewerUri(ontologyElement.getCurrentSegmentUri() != null ? ontologyElement.getCurrentSegmentUri() : ontologyElement.getId()); List<Link> links = ontologyElement.getLinks(); Link pdfLink = Iterables.find(links, new Link.PdfLinkPredicate(), Link.nullPdfLink()); rd.setPdfUri(pdfLink.getHref()); Set<Author> authors = ontologyElement.getAuthors(); List<String> authorNames = new ArrayList<String>(); for (Author author : authors) { authorNames.add(author.getName()); }/*from w w w.ja va 2s .com*/ rd.setAuthors(authorNames); String articleTitle = ontologyElement.getCurrentSegmentTitle() != null ? String.format("%s (%s)", ontologyElement.getTitle(), ontologyElement.getCurrentSegmentTitle()) : ontologyElement.getTitle(); rd.setTitle(articleTitle); resultDescriptions.add(rd); } return resultDescriptions; }
From source file:com.netflix.exhibitor.core.config.EncodedConfigParser.java
/** * Return the value for the given field or null * * @param field field to check//from w ww . jav a 2 s . c o m * @return value or null */ public String getValue(final String field) { FieldValue fieldValue = Iterables.find(fieldValues, new Predicate<FieldValue>() { @Override public boolean apply(FieldValue fv) { return fv.getField().equals(field); } }, null); return (fieldValue != null) ? fieldValue.getValue() : null; }
From source file:com.slimgears.slimsignal.apt.MetaFields.java
private static <P extends PropertyInfo> P findAnnotatedField(Iterable<? extends P> fields, final Class annotationClass) { return (P) Iterables.find(fields, input -> input.getAnnotation(annotationClass) != null, null); }
From source file:org.onos.yangtools.yang.data.impl.codec.SchemaTracker.java
private Optional<SchemaNode> tryFindNotification(final SchemaContext ctx, final QName qname) { return Optional.<SchemaNode>fromNullable( Iterables.find(ctx.getNotifications(), new SchemaNodePredicate(qname), null)); }