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:org.jclouds.aws.ec2.options.internal.BaseEC2RequestOptions.java
protected Set<String> getFormValuesWithKeysPrefixedBy(final String prefix) { Set<String> values = Sets.newLinkedHashSet(); for (String key : Iterables.filter(formParameters.keySet(), new Predicate<String>() { public boolean apply(String input) { return input.startsWith(prefix); }/* w ww. j a v a 2s . c om*/ })) { values.add(formParameters.get(key).iterator().next()); } return values; }
From source file:org.opentripplanner.graph_builder.impl.StopsAlerts.java
@Override public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) { try {/*from ww w . j ava2 s .co m*/ PrintWriter pw = new PrintWriter(new File(logFile)); pw.printf("%s,%s,%s,%s\n", "stopId", "lon", "lat", "types"); for (TransitStop ts : Iterables.filter(graph.getVertices(), TransitStop.class)) { StringBuilder types = new StringBuilder(); for (IStopTester stopTester : stopTesters) { if (stopTester.fulfillDemands(ts, graph)) { if (types.length() > 0) types.append(";"); types.append(stopTester.getType()); } } if (types.length() > 0) { pw.printf("%s,%f,%f,%s\n", ts.getStopId(), ts.getCoordinate().x, ts.getCoordinate().y, types.toString()); } } pw.close(); } catch (FileNotFoundException e) { LOG.error("Failed to write StopsAlerts log file due to {}", e); e.printStackTrace(); } }
From source file:models.documentStore.AspectLexiconModel.java
public AspectLexiconModel(AspectLexicon lexicon, boolean expandChildren) { super(lexicon); if (lexicon != null) { if (lexicon.getBaseCorpus() != null) { this.baseCorpus = (DocumentCorpusModel) createViewModel(lexicon.getBaseCorpus()); }/*w w w. j a v a 2 s . c om*/ if (Iterables.size(lexicon.getDerivedStores()) == 0) { this.children = null; } else { this.children = expandChildren ? Lists.newArrayList( Iterables.transform(Iterables.filter(lexicon.getDerivedStores(), AspectLexicon.class), new Function<AspectLexicon, AspectLexiconModel>() { @Override @Nullable public AspectLexiconModel apply(@Nullable AspectLexicon input) { return new AspectLexiconModel(input, false); } })) : Lists.<AspectLexiconModel>newArrayList(); } if (lexicon.getBaseStore() instanceof AspectLexicon) { this.parent = new AspectLexiconModel((AspectLexicon) lexicon.getBaseStore(), false); } } }
From source file:pl.nort.dayoneevernote.convert.NotesConverter.java
@Override public void run() { Set<Note> notes = fetcher.getNotes(); Iterable<Note> filteredNotes = Iterables.filter(notes, filter); Iterable<Note> transformedNotes = Iterables.transform(filteredNotes, transformer); LOG.info("Matched " + Iterables.size(transformedNotes) + " of " + notes.size() + " notes"); for (Pusher pusher : pushers) { if (!pusher.push(transformedNotes)) { LOG.error("Import of some notes failed!"); }// www . j av a2 s .com } }
From source file:org.aracrown.commons.util.Exceptions.java
/** * Checks {@code throwable} for a cause of type {@code class1}. Throws new exception if found. * * @param throwable exception to check for cause type * @param class1 cause type to check * @param replacedThrowable new custom exception to throw if cause type was found * @param <X> exception type to search for * @param <Y> exception type to be re-thrown * @throws Y exception thrown if cause type was found in chain *//*from w ww . j av a 2s. c o m*/ public <X extends Throwable, Y extends Throwable> void throwNewIfContains(Throwable throwable, Class<X> class1, Y replacedThrowable) throws Y { Iterable<X> i = Iterables.filter(Throwables.getCausalChain(throwable), class1); // Do not expect null here. if (i.iterator().hasNext()) { throw replacedThrowable; } }
From source file:io.crate.operation.collect.RowsTransformer.java
public static Iterable<Row> toRowsIterable(CollectInputSymbolVisitor<?> docInputSymbolVisitor, RoutedCollectPhase collectPhase, Iterable<?> iterable) { WhereClause whereClause = collectPhase.whereClause(); if (whereClause.noMatch()) { return Collections.emptyList(); }/*from w ww . j a v a 2 s . co m*/ CollectInputSymbolVisitor.Context ctx = docInputSymbolVisitor .extractImplementations(collectPhase.toCollect()); OrderBy orderBy = collectPhase.orderBy(); if (orderBy != null) { for (Symbol symbol : orderBy.orderBySymbols()) { docInputSymbolVisitor.process(symbol, ctx); } } Input<Boolean> condition; if (whereClause.hasQuery()) { assert DataTypes.BOOLEAN.equals(whereClause.query().valueType()); //noinspection unchecked whereClause().query() is a symbol of type boolean so it must become Input<Boolean> condition = (Input<Boolean>) docInputSymbolVisitor.process(whereClause.query(), ctx); } else { condition = Literal.BOOLEAN_TRUE; } @SuppressWarnings("unchecked") Iterable<Row> rows = Iterables.filter( Iterables.transform(iterable, new ValueAndInputRow<>(ctx.topLevelInputs(), ctx.docLevelExpressions())), InputCondition.asPredicate(condition)); if (orderBy == null) { return rows; } return sortRows(Iterables.transform(rows, Row.MATERIALIZE), collectPhase); }
From source file:io.prestosql.sql.analyzer.RelationType.java
public RelationType(List<Field> fields) { requireNonNull(fields, "fields is null"); this.allFields = ImmutableList.copyOf(fields); this.visibleFields = ImmutableList.copyOf(Iterables.filter(fields, not(Field::isHidden))); int index = 0; ImmutableMap.Builder<Field, Integer> builder = ImmutableMap.builder(); for (Field field : fields) { builder.put(field, index++);/*from w w w . j a v a 2 s . c o m*/ } fieldIndexes = builder.build(); }
From source file:com.icosilune.fn.processor.FnProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(Fn.class); for (TypeElement type : Iterables.filter(elements, TypeElement.class)) { processType(type);//from w ww. j a va 2 s. c o m } if (roundEnv.processingOver()) { // generate indices. for (String packageName : packageToGeneratedTypes.keySet()) { generateIndex(packageName, packageToGeneratedTypes.get(packageName), annotations); } } // supposedly we should return false, but dunno? return true; }
From source file:org.killbill.billing.payment.api.DefaultDirectPayment.java
private static BigDecimal getAmountForType(final List<DirectPaymentTransaction> transactions, final TransactionType transactiontype) { BigDecimal result = BigDecimal.ZERO; final Iterable<DirectPaymentTransaction> filtered = Iterables.filter(transactions, new Predicate<DirectPaymentTransaction>() { @Override//from w w w . j a v a2 s . c om public boolean apply(final DirectPaymentTransaction input) { return input.getTransactionType() == transactiontype; } }); for (DirectPaymentTransaction dpt : filtered) { result = result.add(dpt.getAmount()); } return result; }
From source file:playground.michalm.taxi.data.TaxiRequests.java
public static int countRequestsWithStatus(Iterable<TaxiRequest> requests, TaxiRequestStatus status) { return Iterables.size(Iterables.filter(requests, new TaxiRequestStatusPredicate(status))); }