List of usage examples for com.google.common.collect Iterables filter
@GwtIncompatible("Class.isInstance") @CheckReturnValue public static <T> Iterable<T> filter(final Iterable<?> unfiltered, final Class<T> desiredType)
From source file:co.cask.cdap.common.HttpExceptionHandler.java
@Override public void handle(Throwable t, HttpRequest request, HttpResponder responder) { // Check if the exception is caused by Service being unavailable: this will happen during master startup if (Iterables.size(Iterables.filter(Throwables.getCausalChain(t), ServiceUnavailableException.class)) > 0) { // no need to log ServiceUnavailableException because at master startup we are waiting for services to come up responder.sendString(HttpResponseStatus.SERVICE_UNAVAILABLE, t.getMessage()); } else if (t instanceof HttpErrorStatusProvider) { logWithTrace(request, t);// ww w.j ava 2 s . com responder.sendString(HttpResponseStatus.valueOf(((HttpErrorStatusProvider) t).getStatusCode()), t.getMessage()); } else { LOG.error("Unexpected error: request={} {} user={}:", request.getMethod().getName(), request.getUri(), Objects.firstNonNull(SecurityRequestContext.getUserId(), "<null>"), t); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, Throwables.getRootCause(t).getMessage()); } }
From source file:org.eclipse.viatra.query.patternlanguage.emf.ui.validation.EMFPatternLanguageUniqueClassNameValidator.java
@Override protected boolean checkUniqueInIndex(JvmDeclaredType type, Iterable<IEObjectDescription> descriptions) { URI objectURI = EcoreUtil.getURI(type); if (objectURI.isPlatformResource()) { String project = objectURI.segment(1); return super.checkUniqueInIndex(type, Iterables.filter(descriptions, it -> { URI candidate = it.getEObjectURI(); return candidate.isPlatformResource() && !!projectHelper.isStandaloneFileURI(type, candidate) && Objects.equals(candidate.segment(1), project); }));// w w w . ja va 2 s .c o m } return true; }
From source file:com.lithium.flow.config.parsers.SubtractConfigParser.java
@Override public boolean parseLine(@Nonnull String line, @Nonnull ConfigBuilder builder) { checkNotNull(line);/*from w ww. jav a2 s . c o m*/ checkNotNull(builder); int index = line.indexOf("-="); if (index > -1 && index < line.indexOf("=")) { String key = line.substring(0, index).trim(); final String value = line.substring(index + 2).trim(); String oldValue = builder.getString(key); if (oldValue != null) { builder.setString(key, Joiner.on(" ") .join(Iterables.filter(Splitter.on(" ").split(oldValue), input -> !value.equals(input)))); return true; } } return false; }
From source file:org.jclouds.openstack.nova.ec2.xml.NovaDescribeImagesResponseHandler.java
public Set<Image> getResult() { return ImmutableSet.copyOf(Iterables.filter(contents, new Predicate<Image>() { @Override// www . j a v a2 s. c o m public boolean apply(Image image) { return image.getImageType() == ImageType.MACHINE; } })); }
From source file:org.jclouds.cloudsigma.functions.SplitNewlinesAndReturnSecondField.java
@Override public Set<String> apply(HttpResponse response) { return ImmutableSet .copyOf(Iterables.filter(Iterables.transform(super.apply(response), new Function<String, String>() { @Override/*from w w w .j a va 2 s . c om*/ public String apply(String arg0) { if (arg0 == null) return null; Iterable<String> parts = Splitter.on(' ').split(arg0); if (Iterables.size(parts) == 2) return Iterables.get(parts, 1); else if (Iterables.size(parts) == 1) return Iterables.get(parts, 0); return null; } }), Predicates.notNull())); }
From source file:com.facebook.presto.execution.SampledSplitSource.java
@Override public List<Split> getNextBatch(int maxSize) throws InterruptedException { List<Split> nextBatch = splitSource.getNextBatch(maxSize); Iterable<Split> sampleIterable = Iterables.filter(nextBatch, new Predicate<Split>() { public boolean apply(@Nullable Split input) { return ThreadLocalRandom.current().nextDouble() < sampleRatio; }/*from w w w . j a va2 s. c o m*/ }); return ImmutableList.copyOf(sampleIterable); }
From source file:org.eclipse.sirius.business.internal.contribution.ReuseHelper.java
/** * Tests whether an object contains any contribution which use elements from * another as source and contribute to the target (or any of its children). * //from w w w. java2 s . co m * @param target * the reuse target. * @param potentialSource * the potential source of reuse. * @return <code>true</code> if the target contains any contribution which * get values from the source (or any of its descendant) and put * them in the target (or any of its descendants). */ public boolean reuses(final EObject target, final EObject potentialSource) { return Iterables.any(Iterables.filter(AllContents.of(target, true), Contribution.class), new Predicate<Contribution>() { public boolean apply(Contribution input) { if (input.getSource() instanceof DirectEObjectReference && input.getTarget() instanceof DirectEObjectReference) { EObject sourceValue = ((DirectEObjectReference) input.getSource()).getValue(); EObject targetValue = ((DirectEObjectReference) input.getTarget()).getValue(); boolean fromSource = sourceValue == potentialSource || EcoreUtil.isAncestor(potentialSource, sourceValue); boolean toTarget = targetValue == target || EcoreUtil.isAncestor(target, targetValue); return fromSource && toTarget; } else { return false; } } }); }
From source file:com.seyren.core.service.live.MetricsTask.java
@Override public void run() { final List<Check> checks = checksStore.getChecks(true, true).getValues(); for (final Check check : checks) { Iterator<Metric> metricByName = Iterables.filter(metrics, new FindByName(check.getName())).iterator(); if (metricByName.hasNext()) { Metric found = metricByName.next(); CheckRunner runner = checkRunnerFactory.create(check, found.getValue()); runner.run();/*from w w w . j a v a2 s . c o m*/ } } }
From source file:org.jclouds.vcloud.functions.OrgsForNames.java
@Override public Iterable<Org> apply(Iterable<String> from) { return Iterables.filter(transform(from, new Function<String, Org>() { public Org apply(String from) { return aclient.getOrgApi().findOrgNamed(from); }//from w ww.j a v a 2 s . co m }), Predicates.notNull()); }
From source file:org.fuusio.api.nfc.SmartPosterRecord.java
public static SmartPosterRecord parse(final NdefRecord[] recordsRaw) { try {//from ww w.j av a2 s . c o m final Iterable<ParsedNdefRecord> records = getRecords(recordsRaw); final UriRecord uri = Iterables.getOnlyElement(Iterables.filter(records, UriRecord.class)); final TextRecord title = getFirstIfExists(records, TextRecord.class); final RecommendedAction action = parseRecommendedAction(recordsRaw); final String type = parseType(recordsRaw); return new SmartPosterRecord(uri, title, action, type); } catch (final NoSuchElementException e) { throw new IllegalArgumentException(e); } }