List of usage examples for com.google.common.collect Iterables transform
@CheckReturnValue public static <F, T> Iterable<T> transform(final Iterable<F> fromIterable, final Function<? super F, ? extends T> function)
From source file:com.pets.core.petstore.domain.mappers.PetModelMapper.java
public static PetModel transform(Pet pet) { if (pet == null) { return null; }/*from w w w . j a va 2s .c o m*/ PetModel petModel = new PetModel(pet.getId()); petModel.setName(pet.getName()).setStatus(pet.getStatus() == null ? null : pet.getStatus().toString()) .setCategoryName(pet.getCategory() == null ? null : pet.getCategory().getName()); List<Tag> tags = pet.getTags(); if (tags != null) { final List<String> tagNames = Lists .newArrayList(Iterables.transform(pet.getTags(), new Function<Tag, String>() { @Override public String apply(final Tag tag) { return tag.getName(); } })); petModel.setTagNames(tagNames); } // Do some business logic (that should have been on the server side) // and filter out non-valid photo URLs List<String> urls = pet.getPhotoUrls(); if (urls != null) { final List<String> photoUrls = Lists.newArrayList(Iterables.filter(urls, new Predicate<String>() { @Override public boolean apply(String url) { return url.startsWith("http://") || url.startsWith("https://"); } })); petModel.setPhotoUrls(photoUrls); } return petModel; }
From source file:org.apache.marmotta.platform.core.webservices.resource.ResourceWebServiceHelper.java
public static String appendMetaTypes(List<String> datamimes) { return Joiner.on(',').join(Iterables.transform(datamimes, new Function<String, String>() { @Override/*from www . j a v a2 s. c om*/ public String apply(String input) { return input + ";rel=meta"; } })); }
From source file:com.google.devtools.build.xcode.util.Interspersing.java
/** * Prepends {@code what} to each string in {@code sequence}, returning a lazy sequence of the * same length./*from ww w . j a v a2s .c o m*/ */ public static Iterable<String> prependEach(final String what, Iterable<String> sequence) { Preconditions.checkNotNull(what); return Iterables.transform(sequence, new Function<String, String>() { @Override public String apply(String input) { return what + input; } }); }
From source file:com.google.googlejavaformat.java.FormatterException.java
public static FormatterException fromJavacDiagnostics( Iterable<Diagnostic<? extends JavaFileObject>> diagnostics) { return new FormatterException(Iterables.transform(diagnostics, d -> toFormatterDiagnostic(d))); }
From source file:gg.uhc.fancyfreeze.commands.FunctionUtil.java
public static Iterable<String> getNamesOfAllOnline() { return Iterables.transform(Bukkit.getOnlinePlayers(), GET_PLAYER_NAME); }
From source file:uk.ac.ed.inf.ace.utils.Utilities.java
public static <C> Iterable<C> extractConfigs(Iterable<JAXBElement<? extends C>> configs) { if (configs == null) { return null; }//from w ww. j a va2 s .c o m return Iterables.transform(configs, new Function<JAXBElement<? extends C>, C>() { @Override public C apply(JAXBElement<? extends C> element) { return element.getValue(); } }); }
From source file:com.atlassian.jira.rest.client.api.domain.EntityHelper.java
public static Iterable<String> toNamesList(Iterable<? extends NamedEntity> items) { return Iterables.transform(items, GET_ENTITY_NAME_FUNCTION); }
From source file:org.sonar.server.computation.component.ComponentTreeBuilder.java
private static Iterable<Component> buildChildren(final BatchReportReader reportReader, final BatchReport.Component component) { return Iterables.transform(component.getChildRefList(), new Function<Integer, Component>() { @Override/*from w w w . j a va 2 s . co m*/ public Component apply(@Nonnull Integer componentRef) { BatchReport.Component component = reportReader.readComponent(componentRef); return newComponent(reportReader, component); } }); }
From source file:com.yahoo.yqlplus.engine.internal.java.backends.java.Chooser.java
public Iterable<List<T>> chooseN(int n, List<T> input) { if (n == input.size()) { final List<List<T>> result = Lists.newArrayListWithCapacity(1); final List<T> copy = Lists.newArrayList(input); result.add(copy);/*from www. j a v a2 s .com*/ return result; } else if (n == 1) { return Iterables.transform(input, new Function<T, List<T>>() { @Override public List<T> apply(T input) { final List<T> res = Lists.newArrayListWithCapacity(1); res.add(input); return res; } }); } else if (n > input.size()) { return ImmutableList.of(); } else { // should use an exact sized list, or better yet don't materialize the list List<List<T>> output = Lists.newArrayList(); chooseN(n, 0, Lists.<T>newArrayListWithCapacity(n), input, output); return output; } }
From source file:com.google.inject.Asserts.java
/** * Returns the String that would appear in an error message for this chain of classes * as modules./* ww w . ja va 2 s . c om*/ */ public static String asModuleChain(Class... classes) { return Joiner.on(" -> ").appendTo(new StringBuilder(" (via modules: "), Iterables.transform(ImmutableList.copyOf(classes), new Function<Class, String>() { @Override public String apply(Class input) { return input.getName(); } })).append(")").toString(); }