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

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

Introduction

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

Prototype

public static <F, T> Collection<T> transform(Collection<F> fromCollection, Function<? super F, T> function) 

Source Link

Document

Returns a collection that applies function to each element of fromCollection .

Usage

From source file:org.sosy_lab.cpachecker.core.reachedset.UnmodifiableReachedSetView.java

@Override
public Collection<Precision> getPrecisions() {
    return Collections2.transform(underlying.getPrecisions(), mapPrecisionFunction);
}

From source file:com.palantir.common.collect.IterableView.java

public <U> IterableView<U> transform(Function<? super T, ? extends U> function) {
    /*// w  w w .j  a  v a2s .co  m
     * Depending on the underlying delegate type, use Lists or Collections2
     * transform implementation to allow for more efficient sized
     * collections when constructing a collection from the transformed
     * result.
     */
    if (delegate() instanceof List) {
        return of(Lists.transform(castAsList(), function));
    } else if (delegate() instanceof Collection) {
        return of(Collections2.transform(castAsCollection(), function));
    }
    return of(Iterables.transform(delegate(), function));
}

From source file:org.onos.yangtools.yang.data.impl.schema.tree.AbstractRecursiveCandidateNode.java

@Override
public final Collection<DataTreeCandidateNode> getChildNodes() {
    return Collections2.transform(getData().getValue(),
            new Function<NormalizedNode<?, ?>, DataTreeCandidateNode>() {
                @Override/*from   w  w w.  j  av  a  2  s  .c o  m*/
                public DataTreeCandidateNode apply(final NormalizedNode<?, ?> input) {
                    return createChild(input);
                }
            });
}

From source file:ru.crazyproger.plugins.webtoper.nls.codeinsight.NlsCompletionContributor.java

public NlsCompletionContributor() {
    extend(CompletionType.BASIC, psiElement(NlsNameImpl.class), new CompletionProvider<CompletionParameters>() {
        @Override/* w w w  .j av  a2 s. co m*/
        protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context,
                @NotNull CompletionResultSet result) {
            Project project = parameters.getPosition().getContainingFile().getProject();
            Collection<NlsFileImpl> files = getNlsFiles(project);
            if (files.isEmpty())
                return;
            final NlsFileImpl currentFile = (NlsFileImpl) parameters.getOriginalFile();
            final Collection<NlsFileImpl> includedFiles = currentFile.getIncludedFiles();
            Collection<NlsFileImpl> filtered = Collections2.filter(files, new Predicate<NlsFileImpl>() {
                @Override
                public boolean apply(@Nullable NlsFileImpl nlsFile) {
                    assert nlsFile != null;
                    return !nlsFile.equals(currentFile) && !includedFiles.contains(nlsFile);
                }
            });

            Collection<LookupElement> lookupElements = Collections2.transform(filtered,
                    new NlsFile2LookupElementFunction());

            result.addAllElements(lookupElements);
        }
    });
}

From source file:org.sonatype.nexus.client.internal.rest.jersey.subsystem.security.JerseyPrivileges.java

@Override
public Collection<Privilege> get() {
    final PrivilegeListResourceResponse privileges;
    try {/*from   w w  w  . j  ava2 s  . c o  m*/
        privileges = getNexusClient().serviceResource("privileges").get(PrivilegeListResourceResponse.class);
    } catch (UniformInterfaceException e) {
        throw getNexusClient().convert(e);
    } catch (ClientHandlerException e) {
        throw getNexusClient().convert(e);
    }

    return Collections2.transform(privileges.getData(), new Function<PrivilegeStatusResource, Privilege>() {
        @Override
        public Privilege apply(@Nullable final PrivilegeStatusResource input) {
            return convert(input);
        }
    });
}

From source file:org.opendaylight.netconf.cli.reader.impl.ListEntryReader.java

@Override
public List<NormalizedNode<?, ?>> readWithContext(final ListSchemaNode listNode)
        throws IOException, ReadingException {
    console.formatLn("Submit child nodes for list entry: %s, %s", listNode.getQName().getLocalName(),
            Collections2.transform(listNode.getChildNodes(), new Function<DataSchemaNode, String>() {
                @Override/*ww  w.  ja va 2  s .  c o  m*/
                public String apply(final DataSchemaNode input) {
                    return input.getQName().getLocalName();
                }
            }));

    final String listName = listNode.getQName().getLocalName();

    final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder = ImmutableMapEntryNodeBuilder
            .create();
    //        final CompositeNodeBuilder<ImmutableCompositeNode> compositeNodeBuilder = ImmutableCompositeNode.builder();
    //        compositeNodeBuilder.setQName(listNode.getQName());

    final SeparatedNodes separatedChildNodes = SeparatedNodes.separateNodes(listNode, getReadConfigNode());

    final List<NormalizedNode<?, ?>> nodes = readKeys(separatedChildNodes.getKeyNodes());
    final Map<QName, Object> qnameToValues = new HashMap<>();
    for (NormalizedNode node : nodes) {
        qnameToValues.put(node.getNodeType(), node.getValue());
    }
    builder.withNodeIdentifier(new NodeIdentifierWithPredicates(listNode.getQName(), qnameToValues));

    nodes.addAll(readMandatoryNotKeys(separatedChildNodes.getMandatoryNotKey()));
    if (!separatedChildNodes.getOthers().isEmpty()) {
        final Optional<Boolean> readNodesWhichAreNotKey = new DecisionReader().read(console,
                "Add non-key, non-mandatory nodes to list %s? [Y|N]", listName);
        if (readNodesWhichAreNotKey.isPresent() && readNodesWhichAreNotKey.get()) {
            nodes.addAll(readNotKeys(separatedChildNodes.getOthers()));
        }
    }

    if (!nodes.isEmpty()) {
        //            compositeNodeBuilder.addAll(nodes);
        builder.withValue((List) nodes);
        return Collections.<NormalizedNode<?, ?>>singletonList(
                ImmutableMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(listNode.getQName()))
                        .withChild(builder.build()).build());
        //            return Collections.<DataContainerChild<?, ?>> singletonList(compositeNodeBuilder.build());
    } else {
        return Collections.emptyList();
    }
}

From source file:org.obm.push.mail.EmailChangesComputerImpl.java

private Collection<Email> rightValueDifferences(Collection<ValueDifference<Email>> valueDifferences) {
    return Collections2.transform(valueDifferences, new RightValueDifferenceFunction());
}

From source file:com.google.devtools.build.lib.query2.RBuildFilesFunction.java

@Override
@SuppressWarnings("unchecked") // Cast from <Target> to <T>. This will only be used with <Target>.
public <T> void eval(QueryEnvironment<T> env, VariableContext<T> context, QueryExpression expression,
        List<Argument> args, Callback<T> callback) throws QueryException, InterruptedException {
    if (!(env instanceof SkyQueryEnvironment)) {
        throw new QueryException("rbuildfiles can only be used with SkyQueryEnvironment");
    }//from   w w w.  j  a va2  s. co  m
    ((SkyQueryEnvironment) env).getRBuildFiles(Collections2.transform(args, ARGUMENT_TO_PATH_FRAGMENT),
            (Callback<Target>) callback);
}

From source file:org.opendaylight.yangtools.yang.data.impl.schema.tree.AbstractRecursiveCandidateNode.java

@Nonnull
@Override//from  w w w  .  jav a2  s.com
public final Collection<DataTreeCandidateNode> getChildNodes() {
    return Collections2.transform(getData().getValue(), this::createChild);
}

From source file:com.censoredsoftware.infractions.bukkit.legacy.compat.LegacyDossier.java

@Override
public Set<Infraction> getInfractions() {
    return Sets.newHashSet(Collections2.transform(infractions, new Function<String, Infraction>() {
        @Override//from w  w w . j a v  a 2 s  . c  om
        public Infraction apply(String s) {
            return ((LegacyInfraction) DataManager.getManager().getFor(LegacyInfraction.class, s))
                    .toInfraction();
        }
    }));
}