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:it.f2informatica.core.gateway.EntityToModelConverter.java
public Iterable<T> convertIterable(Iterable<S> sourceIterable) { return Iterables.transform(sourceIterable, new Function<S, T>() { @Override//www .ja va 2s .co m public T apply(S source) { return convert(source); } }); }
From source file:com.yahoo.yqlplus.engine.internal.code.CodeFormatter.java
public static String emitLiteral(Object value) { if (value instanceof Enum) { Enum val = (Enum) value; return String.format("%s.%s", val.getDeclaringClass().getName(), val.name()); } else if (value instanceof Long) { return String.format("%dL", (Long) value); } else if (value instanceof Float) { // the cast here silences the IDE, obviously it's being cast right back to Object in the call return String.format("%ff", (Float) value); } else if (value instanceof Number) { return value.toString(); }/*from w w w. jav a2 s. c o m*/ if (value.getClass().isArray()) { // the only kind of array we support is array of object Object[] arr = (Object[]) value; if (arr.length == 0) { return "new Object[0]"; } else { return String.format("new Object[%d] { %s }", arr.length, Joiner.on(", ") .join(Iterables.transform(Arrays.asList(arr), new Function<Object, Object>() { @Nullable @Override public Object apply(Object input) { return emitLiteral(input); } }))); } } StringWriter out = new StringWriter(); try { // we're relying on the fact that Java and JSON literals for scalar types look the same JsonGenerator gen = JSON_FACTORY.createGenerator(out); gen.writeObject(value); gen.flush(); return out.toString(); } catch (IOException e) { // should never happen with a stringwriter throw new RuntimeException(e); } }
From source file:org.jclouds.vcloud.director.v1_5.VCloudDirectorException.java
private static String message(Error error, String from) { Iterable<String> words = Iterables.transform(Splitter.on('_').split(error.getMinorErrorCode()), new Function<String, String>() { @Override//from w ww.jav a2 s .co m public String apply(String input) { return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, input); } }); return String.format(MSG_FMT, Joiner.on(' ').join(words), error.getMajorErrorCode(), from, error.getMessage()); }
From source file:org.jclouds.aliyun.ecs.domain.options.DeleteKeyPairOptions.java
public DeleteKeyPairOptions keyPairNames(String... keyPairNames) { String keyPairNamesAsString = Joiner.on(",") .join(Iterables.transform(Arrays.asList(keyPairNames), new Function<String, String>() { @Override//from w w w. j a v a 2 s . c o m public String apply(String s) { return new StringBuilder(s.length() + 1).append('"').append(s).append('"').toString(); } })); queryParameters.put(KEYPAIR_NAMES_PARAM, String.format("[%s]", keyPairNamesAsString)); return this; }
From source file:com.atlassian.jira.rest.client.api.domain.EntityHelper.java
@SuppressWarnings("unused") public static <T> Iterable<String> toStringIdList(Iterable<IdentifiableEntity<T>> items) { return Iterables.transform(items, new Function<IdentifiableEntity<T>, String>() { @Override/*from w w w . java2 s .c om*/ public String apply(IdentifiableEntity<T> from) { return from.getId() == null ? null : from.getId().toString(); } }); }
From source file:org.jclouds.virtualbox.functions.MacAddressToBSD.java
@Override public String apply(String macAddress) { checkArgument(macAddress.length() == 17); return Joiner.on(":") .join(Iterables.transform(Splitter.on(":").split(macAddress), new Function<String, String>() { @Override//from w ww . ja v a 2 s.com public String apply(String addressPart) { if (addressPart.equals("00")) return "0"; if (addressPart.startsWith("0")) return addressPart.substring(1); return addressPart; } })); }
From source file:org.eclipse.xtext.linking.lazy.LazyLinkingTestLanguageScopeProvider.java
public IScope scope_Property(Type t, EReference ref) { return new SimpleScope(IScope.NULLSCOPE, Iterables.transform(t.getExtends().getProperties(), new Function<Property, IEObjectDescription>() { @Override// ww w . j av a2 s . com public IEObjectDescription apply(Property param) { return EObjectDescription.create(QualifiedName.create(param.getName()), param); } })); }
From source file:org.jclouds.elasticstack.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines.java
@Override public String apply(Iterable<Map<String, String>> from) { return Joiner.on("\n\n").join(Iterables.transform(from, new Function<Map<String, String>, String>() { @Override/*www.jav a 2 s . c o m*/ public String apply(Map<String, String> from) { return Joiner.on('\n').withKeyValueSeparator(" ") .join(Maps.transformValues(from, new Function<String, String>() { @Override public String apply(String from) { return from.replace("\n", "\\n"); } })); } })); }
From source file:org.trancecode.concurrent.TcFutures.java
public static <T> Iterable<Future<T>> submit(final ExecutorService executor, final Iterable<Callable<T>> tasks) { final Function<Callable<T>, Future<T>> submitFunction = CallableFunctions.submit(executor); return Iterables.transform(tasks, submitFunction); }
From source file:net.hillsdon.reviki.wiki.macros.SearchMacro.java
@Override protected Collection<String> getPages(final String remainder) throws Exception { String query = escapeQueryForSearch(remainder); return ImmutableList .copyOf(Iterables.transform(_searchEngine.search(query, false, true), SearchMatch.TO_PAGE_NAME)); }