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:com.onboard.domain.transform.StoryTransform.java

public static StoryDTO storyToStoryDTO(Story story) {
    StoryDTO storyDTO = new StoryDTO();
    BeanUtils.copyProperties(story, storyDTO);
    if (story.getChildStories() != null) {
        storyDTO.setChildStoryDTOs(Lists
                .newArrayList(Lists.transform(story.getChildStories(), StoryTransform.STORY_DTO_FUNCTION)));
    }//www . j a v  a 2 s .com
    return storyDTO;
}

From source file:com.github.steveash.jg2p.util.TokenSeqUtil.java

@Nullable
public static String getWindow(List<Token> ts, int current, int windowOffset, int windowWidth) {
    List<String> ss = Lists.transform(ts, tokenToString);
    return getWindowFromStrings(ss, current, windowOffset, windowWidth);
}

From source file:com.github.tomakehurst.wiremock.recording.SnapshotRecordResult.java

public static SnapshotRecordResult idsFromMappings(List<StubMapping> stubMappings) {
    return new Ids(Lists.transform(stubMappings, new Function<StubMapping, UUID>() {
        @Override/*from  w  w  w .j  av a 2  s.  c  om*/
        public UUID apply(StubMapping input) {
            return input.getId();
        }
    }));
}

From source file:blue.lapis.pore.util.PoreCollections.java

public static <F, T> Collection<T> transform(Collection<F> from, Function<? super F, T> function) {
    if (from instanceof List) {
        return Lists.transform((List<F>) from, function);
    }//from w  w w.  j  a v  a2 s .com
    return Collections2.transform(from, function);
}

From source file:org.jpmml.sklearn.LoggerUtil.java

static public String formatNameList(List<Feature> features) {
    Function<Feature, String> function = new Function<Feature, String>() {

        @Override/*from  ww w  .  j  av a 2  s .  com*/
        public String apply(Feature feature) {

            if (feature instanceof BinaryFeature) {
                BinaryFeature binaryFeature = (BinaryFeature) feature;

                return (binaryFeature.getName()).getValue() + "=" + binaryFeature.getValue();
            }

            return (feature.getName()).getValue();
        }
    };

    List<String> ids = Lists.transform(features, function);

    if (ids.size() <= 10) {
        return ids.toString();
    }

    List<String> result = new ArrayList<>();
    result.addAll(ids.subList(0, 2));
    result.add("...");
    result.addAll(ids.subList(ids.size() - 2, ids.size()));

    return result.toString();
}

From source file:org.apache.cassandra.cql3.selection.RawSelector.java

/**
 * Converts the specified list of <code>RawSelector</code>s into a list of <code>Selectable</code>s.
 *
 * @param raws the <code>RawSelector</code>s to converts.
 * @return a list of <code>Selectable</code>s
 *//*www. j  av  a 2s  .  c  o m*/
public static List<Selectable> toSelectables(List<RawSelector> raws, final CFMetaData cfm) {
    return Lists.transform(raws, new Function<RawSelector, Selectable>() {
        public Selectable apply(RawSelector raw) {
            return raw.selectable.prepare(cfm);
        }
    });
}

From source file:org.robotframework.ide.eclipse.main.plugin.project.library.RobotToHtmlConverter.java

public String convert(final String robotStyleString) {
    final List<String> splitted1 = Splitter.on('\n').splitToList(robotStyleString);
    final List<String> wrapped = Lists.transform(splitted1, new Function<String, String>() {
        @Override//  w  ww. ja  v a2 s .c om
        public String apply(final String line) {
            final String escaped = escapeGtLtAmp(line);
            return wrapLineIntoTags(escaped);
        }
    });
    final String consecutiveParagraphsJoined = Joiner.on('\n').join(joinPargraphsToLists(wrapped))
            .replaceAll("</p>\n<p>", "\n");

    final List<String> splitted2 = Splitter.on('\n').splitToList(consecutiveParagraphsJoined);
    final List<String> spansWrappedIntoParagraphs = Lists.transform(splitted2, new Function<String, String>() {
        @Override
        public String apply(final String line) {
            return isSpan(line) ? "<p>" + line + "</p>" : line;
        }
    });
    return Joiner.on('\n').join(spansWrappedIntoParagraphs);
}

From source file:com.metamx.druid.query.Queries.java

public static void verifyAggregations(List<AggregatorFactory> aggFactories, List<PostAggregator> postAggs) {
    Preconditions.checkNotNull(aggFactories, "aggregations cannot be null");
    Preconditions.checkArgument(aggFactories.size() > 0, "Must have at least one AggregatorFactory");

    if (postAggs != null && !postAggs.isEmpty()) {
        Set<String> combinedAggNames = Sets
                .newHashSet(Lists.transform(aggFactories, new Function<AggregatorFactory, String>() {
                    @Override/*from w w  w .j  ava  2s  .com*/
                    public String apply(@Nullable AggregatorFactory input) {
                        return input.getName();
                    }
                }));

        for (PostAggregator postAgg : postAggs) {
            Set<String> dependencies = postAgg.getDependentFields();
            Set<String> missing = Sets.difference(dependencies, combinedAggNames);

            Preconditions.checkArgument(missing.isEmpty(), "Missing fields [%s] for postAggregator [%s]",
                    missing, postAgg.getName());
            combinedAggNames.add(postAgg.getName());
        }
    }
}

From source file:org.estatio.app.interactivemap.ColorMapHelper.java

public static List<Color> sortByValue(Map<Color, Integer> map) {
    List<Map.Entry<Color, Integer>> list = new LinkedList<Map.Entry<Color, Integer>>(map.entrySet());
    Collections.sort(list, new Comparator<Map.Entry<Color, Integer>>() {
        public int compare(Map.Entry<Color, Integer> o1, Map.Entry<Color, Integer> o2) {
            return o1.getValue().compareTo(o2.getValue()) * -1;
        }//from w ww .  j ava 2 s.co  m
    });

    return Lists.transform(list, mapEntryToColor);
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.util.SqlUtil.java

public static String getCommaSepBracesSingleQuoted(List<String> values) {
    Function<String, String> singleQuotedListTransform = new Function<String, String>() {
        public String apply(String input) {
            return "'" + input + "'";
        }//  w  w w.  j  a va 2 s  .  c o m
    };
    List<String> newList = Lists.transform(values, singleQuotedListTransform);
    return " " + OP_BRACE + Joiner.on(",").join(newList) + CL_BRACE + " ";
}