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:nz.co.testamation.core.mock.smtp.SmtpMockServerImpl.java

@Override
public List<SmtpMessageWrapper> getReceivedEmails() {
    List<SmtpMessage> smtpMessages = (List<SmtpMessage>) new WaitForNotEmpty<>().when(new Task<Iterable>() {
        @Override//from   ww w .j a  v a  2  s. c  om
        public Iterable execute() {
            return Lists.newArrayList(simpleSmtpServer.getReceivedEmail());

        }
    }).run();

    return Lists.transform(smtpMessages, new Function<SmtpMessage, SmtpMessageWrapper>() {
        @Override
        public SmtpMessageWrapper apply(SmtpMessage smtpMessage) {
            return smtpMessageWrapperFactory.create(smtpMessage);
        }
    });

}

From source file:org.nickelproject.util.sources.S3MultiFileSource.java

private static List<String> listKeysInDirectory(final String bucketName, final String prefix) {
    final String delimiter = "/";
    final String fixedPrefix = prefix.endsWith(delimiter) ? prefix : prefix + delimiter;

    ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName)
            .withPrefix(fixedPrefix).withDelimiter(delimiter);
    ObjectListing objects = s3Client.listObjects(listObjectsRequest);
    return Lists.transform(objects.getObjectSummaries(), new Function<S3ObjectSummary, String>() {
        @Override/*  w ww.  j  a va 2 s  .  co m*/
        public String apply(@Nonnull final S3ObjectSummary input) {
            return input.getKey();
        }
    });
}

From source file:com.gwtplatform.dispatch.rest.rebind.resource.AbstractMethodGenerator.java

protected List<Parameter> resolveParameters() {
    List<JParameter> jParameters = Arrays.asList(getMethod().getParameters());

    return Lists.transform(jParameters, new Function<JParameter, Parameter>() {
        @Override/*from  w  w  w.j  ava2 s .co  m*/
        public Parameter apply(JParameter jParameter) {
            return new Parameter(jParameter);
        }
    });
}

From source file:org.jasig.portlet.survey.service.jpa.SurveyMapper.java

@Override
public List<QuestionAnswerDTO> toQuestionAnswerList(List<JpaQuestionAnswer> jpaList) {
    return Lists.transform(jpaList, new Function<JpaQuestionAnswer, QuestionAnswerDTO>() {
        @Override/*from w  w  w.  j  a v a 2 s  .  com*/
        public QuestionAnswerDTO apply(JpaQuestionAnswer jpaQuestionAnswer) {
            return toQuestionAnswer(jpaQuestionAnswer);
        }
    });
}

From source file:org.axdt.launch.AxdtCompilerTarget.java

public static File[] pathsToFileArray(List<IPath> paths) {
    List<File> list = Lists.transform(paths, new Path2File());
    return list.toArray(new File[list.size()]);
}

From source file:org.polymap.core.data.feature.recordstore.RSimpleFeature.java

@Override
public List<Object> getAttributes() {
    return Lists.transform((List<Property>) getProperties(), new Function<Property, Object>() {
        public Object apply(Property input) {
            return input.getValue();
        }/*from w  w w. j a v  a 2  s. c  om*/
    });
}

From source file:org.openscoring.service.ModelUtil.java

static private List<Field> encodeInputFields(List<InputField> inputFields) {
    Function<InputField, Field> function = new Function<InputField, Field>() {

        @Override//from   w w  w.  ja v  a 2  s .c  om
        public Field apply(InputField inputField) {
            FieldName name = inputField.getName();

            DataField dataField = (DataField) inputField.getField();

            Field field = new Field(name.getValue());
            field.setName(dataField.getDisplayName());
            field.setDataType(inputField.getDataType());
            field.setOpType(inputField.getOpType());
            field.setValues(encodeValues(dataField));

            return field;
        }
    };

    List<Field> fields = new ArrayList<>(Lists.transform(inputFields, function));

    return fields;
}

From source file:models.UserGroup.java

public static List<UserGroup> listGroupsOfUser(ObjectId uid) {
    List<UserGroup> u = null;
    try {/*w  w w . j a  va 2  s.  c o m*/
        DBCursor iobj = (DBCursor) MongoDB.getDB().getCollection(MongoDB.CUserGroup).find();
        if (iobj != null)
            u = Lists.transform(iobj.toArray(), MongoDB.getSelf().toUserGroup());
    } catch (Exception ex) {
        Logger.info("user load fail");
        ex.printStackTrace();
        Logger.info(ex.toString());
        return null;
    }
    return u;
}

From source file:com.google.template.soy.sharedpasses.render.TofuValueFactory.java

SoyValue computeForJava(SoyJavaSourceFunction srcFn, List<SoyValue> args, TofuPluginContext context) {
    List<JavaValue> javaArgs = Lists.transform(args, new Function<SoyValue, JavaValue>() {
        @Override// w  ww  . j a  v a2s. c o m
        public JavaValue apply(SoyValue soyArg) {
            return TofuJavaValue.forSoyValue(soyArg, fn.getSourceLocation());
        }
    });
    TofuJavaValue result = (TofuJavaValue) srcFn.applyForJavaSource(this, javaArgs, context);
    if (!result.hasSoyValue()) {
        throw RenderException
                .create("applyForJavaSource must return either an 'args' parameter or the result of "
                        + "JavaValueFactory method.");
    }
    return result.soyValue();
}

From source file:com.blacklocus.qs.aws.sqs.AmazonSQSMessageProvider.java

@Override
public List<Message> next() {
    try {//from   ww  w  . j  a v a2 s.c  o  m
        // receive messages from SQS
        ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(queueUrl)
                .withAttributeNames("SentTimestamp").withMaxNumberOfMessages(10);
        List<com.amazonaws.services.sqs.model.Message> sqsMessages = sqs.receiveMessage(receiveMessageRequest)
                .getMessages();
        return Lists.transform(sqsMessages, new Function<com.amazonaws.services.sqs.model.Message, Message>() {
            @Override
            public Message apply(com.amazonaws.services.sqs.model.Message input) {
                return input != null ? new AmazonSQSMessage(input) : null;
            }
        });
    } catch (Throwable t) {
        LOG.error("An error occurred while receiving an SQS message: {}", t);
        // sleep to avoid busy wait loop on a receive error
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            LOG.warn("Thread interrupted while sleeping: {}", e);
            Thread.currentThread().interrupt();
        }
        return Collections.emptyList();
    }
}