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:com.urswolfer.intellij.plugin.gerrit.ui.filter.GerritChangesFilters.java

public String getQuery() {
    return Joiner.on("+").skipNulls()
            .join(Iterables.transform(filters, new Function<AbstractChangesFilter, String>() {
                @Override/*w  ww  .  jav a  2  s .c o m*/
                public String apply(AbstractChangesFilter abstractChangesFilter) {
                    return abstractChangesFilter.getSearchQueryPart();
                }
            }));
}

From source file:com.ninja_squad.core.jsp.JspFunctions.java

/**
 * Transforms all the newlines into <code>&lt;br/&gt;</code>, in order for multi-line text
 * to be displayed into an HTML page. Each line of text is also XML-escaped. <br/>
 * If a null string is passed as argument, an empty string is returned.
 * @param input the string to transform//from   w w w.j  a v a  2s.  co m
 * @return the transformed string.
 */
public static String nlToBr(@Nullable String input) {
    if (input == null) {
        return "";
    }

    try {
        List<String> lines = CharStreams.readLines(new StringReader(input));
        return Joiner.on("<br/>").join(Iterables.transform(lines, ESCAPE_XML));
    } catch (IOException e) {
        throw new ShouldNeverHappenException(e);
    }
}

From source file:org.polarsys.reqcycle.types.impl.ExtensionPointReader.java

public Map<String, IType> read() {
    return Maps.uniqueIndex(Iterables.filter(Iterables.transform(
            Arrays.asList(//from   ww w . jav  a2 s  .com
                    Platform.getExtensionRegistry().getConfigurationElementsFor(Activator.PLUGIN_ID, EXT_ID)),
            new Conf2Type()), Predicates.notNull()), new Function<IType, String>() {
                public String apply(IType type) {
                    return type != null ? type.getId() : "";
                }
            });
}

From source file:org.obiba.opal.web.security.AuthorizationResource.java

@GET
public Iterable<Opal.Acl> get(@QueryParam("domain") @DefaultValue("opal") String domain,
        @QueryParam("type") SubjectType type) {
    return Iterables.transform(subjectAclService.getNodePermissions(domain, getNode(), type),
            PermissionsToAclFunction.INSTANCE);
}

From source file:controllers.DocumentsController.java

public static Iterable<UUID> fetchDocumentIds(UUID store) {
    PersistentDocumentStore storeObj = fetchResource(store, PersistentDocumentStore.class);
    return Iterables.transform(storeObj.getDocumentIds(em()), UuidUtils.uuidBytesToUUIDFunction());
}

From source file:org.estatio.dom.event.Events.java

@Programmatic
public List<Event> findBySource(final EventSource eventSource) {
    final List<EventSourceLink> links = eventSourceLinks.findBySource(eventSource);
    return Lists.newArrayList(Iterables.transform(links, EventSourceLink.Functions.event()));
}

From source file:com.flaptor.indextank.util.Intersection.java

@Override
public SkippableIterator<V> iterator() {
    return new AbstractSkippableIterator<V>() {
        private List<PeekingSkippableIterator<K>> iterators = Lists
                .newArrayList(Iterables.transform(cursors, Intersection.<K>peekingIteratorFunction()));

        @Override/*ww  w  .j  av  a  2s .  c  o  m*/
        protected V computeNext() {
            V current = null;

            while (true) {
                boolean found = true;
                for (PeekingSkippableIterator<K> it : iterators) {
                    while (it.hasNext() && current != null && transform(it.peek()).compareTo(current) < 0) {
                        advanceTo(it, current);
                        it.next();
                    }
                    if (!it.hasNext()) {
                        return endOfData();
                    }
                    if (current != null && transform(it.peek()).equals(current)) {
                        continue;
                    } else {
                        found = false;
                        current = transform(it.peek());
                    }
                }
                if (found) {
                    V r = null;
                    if (shouldUse(current, peekedItems())) {
                        r = current;
                    }
                    for (PeekingIterator<K> it : iterators) {
                        it.next();
                    }
                    if (r != null)
                        return r;
                }
            }
        }

        private List<K> peekedItems() {
            return Lists.transform(iterators, Intersection.<K>peekFunction());
        }

        @Override
        public void skipTo(int i) {
            for (PeekingSkippableIterator<K> it : iterators) {
                it.skipTo(i);
            }
        }
    };
}

From source file:org.trancecode.xproc.port.EnvironmentPort.java

public static EnvironmentPort newEnvironmentPort(final Port declaredPort, final Environment environment) {
    assert declaredPort != null;
    assert environment != null;
    LOG.trace("declaredPort = {}", declaredPort);
    LOG.trace("portBindings = {}", declaredPort.getPortBindings());

    final List<EnvironmentPortBinding> portBindings = ImmutableList.copyOf(Iterables.transform(
            declaredPort.getPortBindings(), portBinding -> portBinding.newEnvironmentPortBinding(environment)));

    final String declaredPortSelect = declaredPort.getSelect();
    LOG.trace("declaredPortSelect = {}", declaredPortSelect);
    final XPathExecutable select;
    if (declaredPortSelect != null) {
        try {//  w  ww .j  a va 2s.  c o  m
            final XPathCompiler xpathCompiler = environment.getPipelineContext().getProcessor()
                    .newXPathCompiler();
            xpathCompiler.setSchemaAware(true);
            xpathCompiler.declareNamespace(XProcXmlModel.xprocNamespace().prefix(),
                    XProcXmlModel.xprocNamespace().uri());
            xpathCompiler.declareNamespace(XProcXmlModel.xprocStepNamespace().prefix(),
                    XProcXmlModel.xprocStepNamespace().uri());
            select = xpathCompiler.compile(declaredPortSelect);
        } catch (final SaxonApiException e) {
            final XProcException error = XProcExceptions.xd0023(declaredPort.getLocation(), declaredPortSelect,
                    e.getMessage());
            error.initCause(e);
            throw error;
        }
    } else {
        select = null;
    }

    return new EnvironmentPort(declaredPort, portBindings, select);
}

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

@Inject
public StreamIdCompleter(final StreamClient streamClient) {
    super(new Supplier<Collection<String>>() {
        @Override/*w  w  w.  j  ava  2  s  .  co  m*/
        public Collection<String> get() {
            try {
                List<StreamRecord> list = streamClient.list();
                return Lists.newArrayList(Iterables.transform(list, new Function<StreamRecord, String>() {
                    @Override
                    public String apply(StreamRecord input) {
                        return input.getId();
                    }
                }));
            } catch (IOException e) {
                return Lists.newArrayList();
            } catch (UnAuthorizedAccessTokenException e) {
                return Lists.newArrayList();
            }
        }
    });
}

From source file:cosmos.results.CloseableIterable.java

public static <T> CloseableIterable<T> transform(ScannerBase scanner, Function<Entry<Key, Value>, T> func,
        Tracer t, String desc, Stopwatch sw) {
    return new CloseableIterable<T>(scanner, Iterables.transform(scanner, func), t, desc, sw);
}