List of usage examples for com.google.common.collect Iterators transform
public static <F, T> Iterator<T> transform(final Iterator<F> fromIterator, final Function<? super F, ? extends T> function)
From source file:org.locationtech.geogig.ql.cli.QLTestHelper.java
public SimpleFeatureCollection selectAndAssert(String query, Set<String> expectedFids, String... expectedAttributes) { SimpleFeatureCollection result = select(query); Set<String> fids = newHashSet(Iterators .transform(new FeatureIteratorIterator<SimpleFeature>(result.features()), (f) -> f.getID())); assertEquals(expectedFids, fids);/* w w w .jav a2 s .c o m*/ if (expectedAttributes != null && expectedAttributes.length > 0) { Set<String> returnedAtts = newTreeSet( Lists.transform(result.getSchema().getAttributeDescriptors(), (a) -> a.getLocalName())); Set<String> expectedAtts = new TreeSet<>(Arrays.asList(expectedAttributes)); assertEquals(expectedAtts, returnedAtts); } return result; }
From source file:org.apache.calcite.adapter.elasticsearch.Scrolling.java
/** * Combines lazily multiple {@link ElasticsearchJson.Result} into a single iterator of * {@link ElasticsearchJson.SearchHit}./*from w ww . j a v a 2s . c o m*/ */ private static Iterator<ElasticsearchJson.SearchHit> flatten(Iterator<ElasticsearchJson.Result> results) { final Iterator<Iterator<ElasticsearchJson.SearchHit>> inputs = Iterators.transform(results, input -> input.searchHits().hits().iterator()); return Iterators.concat(inputs); }
From source file:com.dangdang.ddframe.rdb.sharding.api.fixture.ShardingRuleMockBuilder.java
public ShardingRule build() { final DataSourceRule dataSourceRule = new DataSourceRule( ImmutableMap.of("db0", Mockito.mock(DataSource.class), "db1", Mockito.mock(DataSource.class))); Collection<TableRule> tableRules = Lists.newArrayList( Iterators.transform(autoIncrementColumnMap.keySet().iterator(), new Function<String, TableRule>() { @Override/* w ww. jav a 2s . co m*/ public TableRule apply(final String input) { TableRule.TableRuleBuilder builder = TableRule.builder(input) .actualTables(Collections.singletonList(input)).dataSourceRule(dataSourceRule); for (String each : autoIncrementColumnMap.get(input)) { builder.autoIncrementColumns(each); } return builder.build(); } })); if (tableRules.isEmpty()) { tableRules.add(new TableRule.TableRuleBuilder("mock").actualTables(Collections.singletonList("mock")) .dataSourceRule(dataSourceRule).build()); } return new ShardingRule.ShardingRuleBuilder().dataSourceRule(dataSourceRule) .idGenerator(IncrementIdGenerator.class).tableRules(tableRules).databaseShardingStrategy( new DatabaseShardingStrategy(shardingColumns, new NoneDatabaseShardingAlgorithm())) .build(); }
From source file:io.crate.metadata.RoutineInfos.java
private Iterator<RoutineInfo> builtInAnalyzers() { return Iterators.transform(ftResolver.getBuiltInAnalyzers().iterator(), new Function<String, RoutineInfo>() { @Nullable/*from ww w .j a v a2s .co m*/ @Override public RoutineInfo apply(@Nullable String input) { return new RoutineInfo(input, RoutineType.ANALYZER.getName()); } }); }
From source file:org.ow2.sirocco.cloudmanager.api.openstack.server.resources.nova.functions.queries.AbstractQuery.java
@Override public QueryParams apply(org.ow2.sirocco.cloudmanager.api.openstack.commons.resource.JaxRsRequestInfo input) { if (RequestHelper.getQueryParameters(input).size() == 0) { return null; }/* w ww . j a va 2s .co m*/ // let's get all parameters and map to the sirocco model... Map<String, List<String>> params = RequestHelper.getQueryParameters(input); final Map<String, String> p = Maps.transformValues(params, new Function<List<String>, String>() { @Override public String apply(List<String> input) { return input.get(0); } }); List<Query> filter = Lists.newArrayList( Iterators.filter(Iterators.transform(p.keySet().iterator(), new Function<String, Query>() { @Override public Query apply(String key) { Query q = getQuery(key.toLowerCase()); q.name = getSiroccoParamName(key.toLowerCase()); q.operator = "="; q.value = getSiroccoParamValue(key, p.get(key)); return q; } }), new Predicate<Query>() { // do not keep query with null names. It means that there is no mapping between openstack and sirocco... @Override public boolean apply(ServerListQuery.Query input) { return input.name != null; } })); List<String> f = Lists.transform(filter, new Function<Query, String>() { @Override public String apply(ServerListQuery.Query input) { return input.toString(); } }); LOG.info("Query list : " + f); return new QueryParams.Builder().filters(f).build(); }
From source file:org.locationtech.geogig.api.porcelain.CleanOp.java
/** * @see java.util.concurrent.Callable#call() *//*from ww w .j a v a 2 s .co m*/ protected WorkingTree _call() { if (path != null) { // check that is a valid path NodeRef.checkValidPath(path); Optional<NodeRef> ref = command(FindTreeChild.class).setParent(workingTree().getTree()) .setChildPath(path).call(); Preconditions.checkArgument(ref.isPresent(), "pathspec '%s' did not match any tree", path); Preconditions.checkArgument(ref.get().getType() == TYPE.TREE, "pathspec '%s' did not resolve to a tree", path); } final Iterator<DiffEntry> unstaged = command(DiffWorkTree.class).setFilter(path).call(); final Iterator<DiffEntry> added = Iterators.filter(unstaged, new Predicate<DiffEntry>() { @Override public boolean apply(@Nullable DiffEntry input) { return input.changeType().equals(ChangeType.ADDED); } }); Iterator<String> addedPaths = Iterators.transform(added, new Function<DiffEntry, String>() { @Override public String apply(DiffEntry input) { return input.newPath(); } }); workingTree().delete(addedPaths); return workingTree(); }
From source file:com.cloudera.exhibit.avro.AvroObsDescriptor.java
@Override public Iterator<Field> iterator() { return Iterators.transform(schema.getFields().iterator(), new Function<Schema.Field, Field>() { @Override/*from ww w .j a va2 s . c om*/ public Field apply(Schema.Field f) { return new Field(f.name(), getFieldType(f.schema())); } }); }
From source file:io.druid.java.util.common.guava.FunctionalIterator.java
public <RetType> FunctionalIterator<RetType> transformCat(Function<T, Iterator<RetType>> fn) { return new FunctionalIterator<>(Iterators.concat(Iterators.transform(delegate, fn))); }
From source file:org.apache.nifi.processors.kite.JSONFileReader.java
@Override public void initialize() { Preconditions.checkState(state.equals(ReaderWriterState.NEW), "A reader may not be opened more than once - current state:%s", state); Preconditions.checkArgument(Schema.Type.RECORD.equals(schema.getType()), "Schemas for JSON files should be record"); this.iterator = Iterators.transform(JsonUtil.parser(incoming), new Function<JsonNode, E>() { @Override/*from www . ja v a2 s . c o m*/ @SuppressWarnings("unchecked") public E apply(@Nullable JsonNode node) { return (E) JsonUtil.convertToAvro(model, node, schema); } }); this.state = ReaderWriterState.OPEN; }
From source file:org.eclipselabs.agrum.services.model.plugin.parser.ModelParser.java
/** * To get an iterator on each state of the state machine * @param s - the state machine//from w w w . j ava2 s .c o m * @return the iterator */ private static Iterator<State> StateIterator(StateMachine s) { Predicate<Object> allStates = Predicates.instanceOf(State.class); Iterator<EObject> result = Iterators.filter(s.eAllContents(), allStates); Iterator<State> states = Iterators.transform(result, new com.google.common.base.Function<EObject, State>() { @Override public State apply(EObject arg0) { return (State) arg0; } }); return states; }