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

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

Introduction

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

Prototype

@CheckReturnValue
public static <F, T> List<T> transform(List<F> fromList, Function<? super F, ? extends T> function) 

Source Link

Document

Returns a list that applies function to each element of fromList .

Usage

From source file:org.sonatype.nexus.plugins.siesta.EchoResource.java

@GET
@Path("/multiple")
@Produces({ APPLICATION_XML, APPLICATION_JSON })
public List<String> get(@QueryParam("foo") List<String> foo) {
    return Lists.transform(foo, new Function<String, String>() {
        public String apply(final String value) {
            return "foo=" + value;
        }//from ww w. j  ava  2s . co m
    });
}

From source file:org.funcito.example.guava.MyClass.java

protected static void demoListTransforms(List<MyClass> list) {
    List<String> strList1 = Lists.transform(list, getMyString);
    List<String> strList2 = Lists.transform(list, getMyStringF2);
    List<Integer> intList = Lists.transform(list, getOther);

    printValues("func1", strList1);
    printValues("func2", strList2);
    printValues("otherFunc", intList);
}

From source file:gobblin.data.management.copy.replication.DataFlowTopology.java

@Override
public String toString() {
    Function<DataFlowPath, String> func = new Function<DataFlowPath, String>() {
        @Override/*from   w  ww  . j  av a 2 s. c o  m*/
        public String apply(DataFlowPath t) {
            return t.toString();
        }
    };

    return Objects.toStringHelper(this.getClass())
            .add("dataFlows:", Joiner.on(",").join(Lists.transform(this.dataFlowPaths, func))).toString();
}

From source file:org.jasig.portal.io.xml.layout.FragmentLayoutsDataFunction.java

@Override
public Iterable<? extends IPortalData> apply(IPortalDataType input) {
    final List<FragmentDefinition> fragments = this.configurationLoader.getFragments();

    final List<IPortalData> portalData = Lists.transform(fragments,
            new Function<FragmentDefinition, IPortalData>() {
                @Override/*from w  w w.j a  v a2  s  .com*/
                public IPortalData apply(FragmentDefinition fragmentDefinition) {
                    return new SimpleStringPortalData(fragmentDefinition.getOwnerId(),
                            fragmentDefinition.getName(), fragmentDefinition.getDescription());
                }
            });

    return portalData;
}

From source file:io.druid.query.groupby.orderby.OrderByColumnSpec.java

public static List<OrderByColumnSpec> ascending(String... dimension) {
    return Lists.transform(Arrays.asList(dimension), new Function<String, OrderByColumnSpec>() {
        @Override/*from w w w.  j  a  va  2  s  .c  o  m*/
        public OrderByColumnSpec apply(@Nullable String input) {
            return asc(input);
        }
    });
}

From source file:org.sonarsource.sonarlint.core.container.storage.StoragePluginIndexProvider.java

@Override
public List<PluginReference> references() {
    Path pluginReferencesPath = storageManager.getPluginReferencesPath();
    if (!Files.exists(pluginReferencesPath)) {
        return Collections.emptyList();
    }/*from   www . jav  a2  s .com*/
    org.sonarsource.sonarlint.core.proto.Sonarlint.PluginReferences protoReferences = ProtobufUtil.readFile(
            pluginReferencesPath, org.sonarsource.sonarlint.core.proto.Sonarlint.PluginReferences.parser());
    return Lists.transform(protoReferences.getReferenceList(),
            input -> new PluginReference().setHash(input.getHash()).setFilename(input.getFilename()));
}

From source file:org.sonatype.nexus.plugins.siesta.internal.ValidationResponseExceptionMapper.java

@Override
protected List<ValidationErrorXO> getValidationErrors(final ValidationResponseException exception) {
    ValidationResponse response = exception.getResponse();
    List<ValidationMessage> errors = response.getErrors();
    if (!errors.isEmpty()) {
        return Lists.transform(errors, new Function<ValidationMessage, ValidationErrorXO>() {
            // FIXME: While guava api allows for nulls, the data here should never be null so can simplify
            @Nullable/*from w w  w.ja  v a2s.c  o  m*/
            @Override
            public ValidationErrorXO apply(@Nullable final ValidationMessage message) {
                if (message != null) {
                    return new ValidationErrorXO(message.getKey(), message.getMessage());
                }
                return null;
            }
        });
    }

    return Lists.newArrayList(new ValidationErrorXO(exception.getMessage()));
}

From source file:com.yahoo.druid.emitter.ComposingEmitterModule.java

@Provides
@ManageLifecycle//from w  w w.  j a  va 2  s .c o  m
@Named("composing")
public Emitter getEmitter(ComposingEmitterConfig config, final Injector injector) {
    log.info("Creating Composing Emitter with %s", config.getEmitters());

    List<Emitter> emitters = Lists.transform(config.getEmitters(), new Function<String, Emitter>() {
        @Override
        public Emitter apply(String s) {
            return injector.getInstance(Key.get(Emitter.class, Names.named(s)));
        }
    });

    return new ComposingEmitter(emitters);
}

From source file:org.apache.druid.query.aggregation.cardinality.CardinalityAggregatorFactory.java

private static List<String> makeRequiredFieldNamesFromFields(List<DimensionSpec> fields) {
    return ImmutableList.copyOf(Lists.transform(fields, new Function<DimensionSpec, String>() {
        @Override/*  w  w w  .  ja v a 2  s. c o m*/
        public String apply(DimensionSpec input) {
            return input.getDimension();
        }
    }));
}

From source file:intec.sli.iwstudy.teamcalendar.app.web.service.CustomEventsManager.java

@Override
public Iterable<DHXEv> getEvents() {
    List<Event> events = eventService.list();
    List<DHXEv> dhxEvents = Lists.transform(events, new Function<Event, DHXEv>() {
        @Override/*  ww w.j a  va2 s . c  o m*/
        public DHXEv apply(Event input) {
            return new DHXEvent(input.getId(), input.getFrom(), input.getTo(), input.getText());
        }
    });
    return dhxEvents;
}