Example usage for com.google.common.collect Iterables transform

List of usage examples for com.google.common.collect Iterables transform

Introduction

In this page you can find the example usage for com.google.common.collect Iterables transform.

Prototype

@CheckReturnValue
public static <F, T> Iterable<T> transform(final Iterable<F> fromIterable,
        final Function<? super F, ? extends T> function) 

Source Link

Document

Returns an iterable that applies function to each element of fromIterable .

Usage

From source file:org.isisaddons.wicket.fullcalendar2.cpt.ui.CalendarableCollectionAsFullCalendar2.java

@Override
protected Set<String> getCalendarNames(final Collection<ObjectAdapter> entityList) {
    return Sets.newLinkedHashSet(
            Iterables.concat(Iterables.transform(entityList, CalendarableEventProvider.GET_CALENDAR_NAMES)));
}

From source file:co.cask.cdap.cli.completer.element.StreamIdCompleter.java

@Inject
public StreamIdCompleter(final StreamClient streamClient, final CLIConfig cliConfig) {
    super(new Supplier<Collection<String>>() {
        @Override// w  w w .  jav  a2  s  .  c  o  m
        public Collection<String> get() {
            try {
                List<StreamDetail> list = streamClient.list(cliConfig.getCurrentNamespace());
                return Lists.newArrayList(Iterables.transform(list, new Function<StreamDetail, String>() {
                    @Override
                    public String apply(StreamDetail input) {
                        return input.getName();
                    }
                }));
            } catch (IOException e) {
                return Lists.newArrayList();
            } catch (UnauthorizedException e) {
                return Lists.newArrayList();
            }
        }
    });
}

From source file:datafu.pig.hash.lsh.LSHFamily.java

/**
 * Compute the family of k-hashes for a vector.
 * //from   www  . j  a v  a  2s  .  c  om
 * @param vector
 * @return An iterable of hashes
 */
public Iterable<Long> apply(final RealVector vector) {
    return Iterables.transform(hashes, new Function<LSH, Long>() {
        @Override
        public Long apply(LSH lsh) {
            return lsh.apply(vector);
        }
    });
}

From source file:co.cask.cdap.shell.completer.element.DatasetNameCompleter.java

@Inject
public DatasetNameCompleter(final DatasetClient datasetClient) {
    super(new Supplier<Collection<String>>() {
        @Override/*from w ww  .  j  ava2 s  . c o  m*/
        public Collection<String> get() {
            try {
                List<DatasetSpecification> list = datasetClient.list();
                return Lists
                        .newArrayList(Iterables.transform(list, new Function<DatasetSpecification, String>() {
                            @Override
                            public String apply(DatasetSpecification input) {
                                // TODO: hack to handle namespaced dataset names -- assumes there are no periods in dataset names
                                String[] tokens = input.getName().split("\\.");
                                return tokens[tokens.length - 1];
                            }
                        }));
            } catch (IOException e) {
                return Lists.newArrayList();
            } catch (UnAuthorizedAccessTokenException e) {
                return Lists.newArrayList();
            }
        }
    });
}

From source file:org.jclouds.aliyun.ecs.functions.ArrayToCommaSeparatedString.java

@Override
public String apply(Object input) {
    checkArgument(checkNotNull(input, "input") instanceof String[],
            "This function is only valid for array of Strings!");
    String[] names = (String[]) input;

    String arrayToCommaSeparatedString = Joiner.on(",")
            .join(Iterables.transform(Arrays.asList(names), new Function<String, String>() {
                @Override//from  w w w  .j  a v  a 2 s. co m
                public String apply(String s) {
                    return new StringBuilder(s.length() + 1).append('"').append(s).append('"').toString();
                }
            }));
    return String.format("[%s]", arrayToCommaSeparatedString);
}

From source file:com.proofpoint.cloudmanagement.service.ProvidersResource.java

@GET
@Produces(MediaType.APPLICATION_JSON)//from  w ww  .  java 2  s.  com
public Response getProviders(@Context final UriInfo uriInfo) {
    checkNotNull(uriInfo);

    return Response.ok(Iterables.transform(instanceConnectorMap.entrySet(),
            new Function<Entry<String, InstanceConnector>, Object>() {
                @Override
                public Object apply(@Nullable Entry<String, InstanceConnector> input) {
                    return new Provider(input.getKey(), input.getValue().getName(),
                            ProviderResource.constructSelfUri(uriInfo, input.getKey()));
                }
            })).build();
}

From source file:com.facebook.buck.cxx.toolchain.WindowsPreprocessor.java

@Override
public Iterable<String> localIncludeArgs(Iterable<String> includeRoots) {
    return Iterables.transform(includeRoots, WindowsPreprocessor::prependIncludeFlag);
}

From source file:com.bazaarvoice.dropwizard.caching.HttpHeaderUtils.java

/**
 * Join multiple header values with a comma. Null values are ignored. The values are transformed to string
 * with {@link ContainerResponse#getHeaderValue(Object)}.
 *//* w  ww.  ja v  a  2  s. com*/
public static String transformAndJoin(Iterable<Object> headerValues) {
    return join(Iterables.transform(headerValues, HEADER_VALUE_FORMATTER));
}

From source file:org.sonatype.nexus.orient.entity.IterableEntityAdapter.java

/**
 * Transform documents into entities./* w  ww  .  j  av a 2 s  .c o  m*/
 */
public Iterable<T> transform(final Iterable<ODocument> documents) {
    return Iterables.transform(documents, new Function<ODocument, T>() {
        @Nullable
        @Override
        public T apply(@Nullable final ODocument input) {
            return input != null ? readEntity(input) : null;
        }
    });
}

From source file:org.trancecode.concurrent.TcFutures.java

public static <T> Iterable<Future<T>> submit(final TaskExecutor executor, final Iterable<Callable<T>> tasks) {
    final Function<Callable<T>, Future<T>> submitFunction = CallableFunctions.submit(executor);
    return Iterables.transform(tasks, submitFunction);
}