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.google.gxp.compiler.base.Util.java

/**
 * Given a function and a list, returns a list such that each element of the
 * result is the corresponding element of the input list mapped through the
 * input function.  Unlike Lists.transform the result is <em>not</em> a lazy
 * view, and null elements in the result are disallowed.  This is very
 * similar to the map function in Python and Scheme, except the parameters
 * are reversed for consistency with Lists.transform.
 *
 * @throws NullPointerException if any of resulting elements would be null.
 *//*from  ww  w  .j a  v a2  s . c o m*/
public static <K, V> ImmutableList<V> map(List<K> fromList, Function<? super K, ? extends V> function) {
    return ImmutableList.copyOf(Lists.transform(fromList, function));
}

From source file:com.anhth12.lambda.app.serving.als.AbstractALSResource.java

static List<IDValue> toIDValueResponse(List<Pair<String, Double>> pairs, int howMany, int offset) {
    List<Pair<String, Double>> sublist = selectedSublist(pairs, howMany, offset);

    return Lists.transform(sublist, new Function<Pair<String, Double>, IDValue>() {

        @Override/*  www.  jav a  2  s  .c om*/
        public IDValue apply(Pair<String, Double> f) {
            return new IDValue(f.getFirst(), f.getSecond());
        }
    });
}

From source file:com.ansorgit.plugins.bash.editor.codecompletion.CompletionProviderUtils.java

static Collection<LookupElement> createItems(Iterable<String> items, final Icon icon) {
    return Lists.transform(Lists.newArrayList(items), new Function<String, LookupElement>() {
        public LookupElement apply(String from) {
            //create a lookup string which doesn't contain typical separator characters
            String lookup = from.replaceAll("[_]", "");
            return LookupElementBuilder.create(from).withCaseSensitivity(true).withLookupString(lookup)
                    .withIcon(icon);/* w w w.j a  v a 2s.c  o  m*/
        }
    });
}

From source file:com.onboard.domain.transform.TodoTransform.java

public static TodoDTO todoToTodoDTOWithComments(Todo todo) {
    TodoDTO todoDTO = new TodoDTO();
    BeanUtils.copyProperties(todo, todoDTO);
    if (todo.getComments() != null) {
        todoDTO.setComments(Lists.transform(todo.getComments(), CommentTransform.COMMENT_TO_DTO_FUNCTION));
    }/* ww  w.  ja va 2  s  .  co  m*/
    if (todo.getSubscribers() != null) {
        todoDTO.setSubscribers(Lists.transform(todo.getSubscribers(), UserTransform.USER_TO_USERDTO_FUNCTION));
    }
    return todoDTO;
}

From source file:com.reprezen.kaizen.oasparser.jsonoverlay.gen.Template.java

public static <T> List<String> t(final T item, String... templates) {
    return Lists.transform(Lists.newArrayList(templates), new Function<String, String>() {
        @Override/* ww w.j  a  v a 2s  .co m*/
        public String apply(String template) {
            return t(template, item);
        }
    });
}

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

public static <F, T> List<T> transformToList(Collection<F> from, Function<? super F, ? extends T> function) {
    // If we have a list already we can transform it directly
    if (from instanceof List) {
        return Lists.transform((List<F>) from, function);
    }//from  ww w  .j  a va 2  s  .  com

    // There is no other good way than copying everything, meh
    List<T> result = Lists.newArrayListWithCapacity(from.size());
    for (F element : from) {
        result.add(function.apply(element));
    }
    return result;
}

From source file:com.onboard.domain.transform.AttachmentTransform.java

public static final AttachmentDTO attachmentToAttachmentDTO(Attachment attachment) {
    AttachmentDTO attachmentDTO = new AttachmentDTO();
    BeanUtils.copyProperties(attachment, attachmentDTO);
    if (attachment.getTags() != null) {
        List<TagDTO> tagDtos = Lists.transform(attachment.getTags(), TagTransform.TAG_TO_TAGDTO_FUNCTION);
        attachmentDTO.setTagDtos(tagDtos);
    }//from  w  w w. j  av  a  2s  . co  m
    return attachmentDTO;
}

From source file:org.apache.aurora.common.args.TypeUtil.java

/**
 * Gets the types that a type is type-parameterized with, in declaration order.
 *
 * @param type The type to extract type parameters from.
 * @return The types that {@code type} is parameterized with.
 *///from  www. j a v  a  2  s  .c o m
public static List<Type> getTypeParams(Type type) {
    if (type instanceof WildcardType) {
        return getTypeParams(GET_TYPE.apply(type));
    }
    return Lists.transform(Arrays.asList(((ParameterizedType) type).getActualTypeArguments()), GET_TYPE);
}

From source file:com.cloudera.science.ml.hcatalog.HCatalogSpec.java

public HCatalogSpec(final HCatSchema schema) {
    super(Lists.transform(schema.getFields(), new Function<HCatFieldSchema, FieldSpec>() {
        @Override//  ww  w .ja v a  2 s .  c om
        public FieldSpec apply(HCatFieldSchema fs) {
            return new HCatalogFieldSpec(fs, schema.getPosition(fs.getName()));
        }
    }));
    this.schema = schema;
}

From source file:org.codehaus.httpcache4j.payload.FormDataPayload.java

private static List<FormParameter> convert(final String key, List<String> values) {
    return Lists.transform(values, new Function<String, FormParameter>() {
        public FormParameter apply(String from) {
            return new FormParameter(key, from);
        }//  w  ww.  ja v  a  2  s .c o  m
    });
}