Example usage for com.google.common.collect Lists asList

List of usage examples for com.google.common.collect Lists asList

Introduction

In this page you can find the example usage for com.google.common.collect Lists asList.

Prototype

public static <E> List<E> asList(@Nullable E first, E[] rest) 

Source Link

Document

Returns an unmodifiable list containing the specified first element and backed by the specified array of additional elements.

Usage

From source file:pt.souplesse.spark.Server.java

public static void main(String[] args) {
    EntityManagerFactory factory = Persistence.createEntityManagerFactory("guestbook");
    EntityManager manager = factory.createEntityManager();
    JinqJPAStreamProvider streams = new JinqJPAStreamProvider(factory);
    get("/messages", (req, rsp) -> {
        rsp.type("application/json");
        return gson.toJson(streams.streamAll(manager, Message.class).collect(Collectors.toList()));
    });// ww  w.j  av a2 s  .  c  om
    post("/messages", (req, rsp) -> {
        try {
            Message msg = gson.fromJson(req.body(), Message.class);
            if (StringUtils.isBlank(msg.getMessage()) || StringUtils.isBlank(msg.getName())) {
                halt(400);
            }
            manager.getTransaction().begin();
            manager.persist(msg);
            manager.getTransaction().commit();
        } catch (JsonSyntaxException e) {
            halt(400);
        }
        rsp.type("application/json");
        return gson.toJson(streams.streamAll(manager, Message.class).collect(Collectors.toList()));
    });
    get("/comments", (req, rsp) -> {
        rsp.type("application/json");
        Map<String, List<Body>> body = new HashMap<>();
        try (CloseableHttpClient client = create().build()) {
            String url = String.format("https://api.github.com/repos/%s/events", req.queryMap("repo").value());
            log.info(url);
            body = client.execute(new HttpGet(url), r -> {
                List<Map<String, Object>> list = gson.fromJson(EntityUtils.toString(r.getEntity()), List.class);
                Map<String, List<Body>> result = new HashMap<>();
                list.stream().filter(m -> m.getOrDefault("type", "").equals("IssueCommentEvent"))
                        .map(m -> new Body(((Map<String, String>) m.get("actor")).get("login"),
                                ((Map<String, Map<String, String>>) m.get("payload")).get("comment")
                                        .get("body")))
                        .forEach(b -> result.compute(b.getLogin(), (k, v) -> v == null ? new ArrayList<>()
                                : Lists.asList(b, v.toArray(new Body[v.size()]))));
                return result;
            });
        } catch (IOException e) {
            log.error(null, e);
            halt(400, e.getMessage());
        }
        return gson.toJson(body);
    });
}

From source file:com.palantir.giraffe.file.base.SuppressedCloseable.java

public static SuppressedCloseable create(Closeable first, Closeable... others) {
    return new SuppressedCloseable(Lists.asList(first, others));
}

From source file:com.b2international.commons.ExplicitFirstOrdering.java

public static <T> ExplicitFirstOrdering<T> create(T firstValue, T... nextValues) {
    return new ExplicitFirstOrdering<T>(Lists.asList(firstValue, nextValues));
}

From source file:dagger.internal.codegen.AnnotationSpecs.java

static AnnotationSpec suppressWarnings(Suppression first, Suppression... rest) {
    checkNotNull(first);/*  ww w .  j av a  2 s.  co  m*/
    Arrays.stream(rest).forEach(Preconditions::checkNotNull);
    AnnotationSpec.Builder builder = AnnotationSpec.builder(SuppressWarnings.class);
    Lists.asList(first, rest).forEach(suppression -> builder.addMember("value", "$S", suppression));
    return builder.build();
}

From source file:de.cosmocode.commons.concurrent.Runnables.java

/**
 * Chains multiple {@link Runnable}s together.
 * //from  w  w w .  j a v a 2s  . co  m
 * @param first the first Runnable
 * @param rest zero or more additional Runnables
 * @return a Runnable which runs all given Runnables in a sequence
 * @throws NullPointerException if first or rest is null
 */
public static Runnable chain(Runnable first, Runnable... rest) {
    Preconditions.checkNotNull(first, "First");
    Preconditions.checkNotNull(rest, "Rest");
    return chain(Lists.asList(first, rest));
}

From source file:com.facebook.presto.sql.tree.QualifiedName.java

public static QualifiedName of(String first, String... rest) {
    requireNonNull(first, "first is null");
    return new QualifiedName(ImmutableList.copyOf(Lists.asList(first, rest)));
}

From source file:io.prestosql.sql.tree.QualifiedName.java

public static QualifiedName of(String first, String... rest) {
    requireNonNull(first, "first is null");
    return of(ImmutableList
            .copyOf(Lists.asList(first, rest).stream().map(Identifier::new).collect(Collectors.toList())));
}

From source file:com.facebook.buck.ide.intellij.ProjectIntegrationTestUtils.java

public static ProjectWorkspace.ProcessResult runBuckProject(Object testCase, TemporaryPaths temporaryFolder,
        String folderWithTestData, boolean verifyWorkspace, String... commandArgs) throws IOException {
    AssumeAndroidPlatform.assumeSdkIsAvailable();

    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(testCase, folderWithTestData,
            temporaryFolder);//w w  w.j  a  v  a2s.  com
    workspace.setUp();

    ProjectWorkspace.ProcessResult result = workspace
            .runBuckCommand(Lists.asList("project", commandArgs).toArray(new String[commandArgs.length + 1]));
    result.assertSuccess("buck project should exit cleanly");

    if (verifyWorkspace) {
        workspace.verify();
    }

    return result;
}

From source file:com.dangdang.ddframe.rdb.sharding.api.MasterSlaveDataSourceFactory.java

/**
 * ??./*  www  .j  a va 2s  .c  om*/
 * 
 * @param name ????
 * @param masterDataSource ??
 * @param slaveDataSource ??
 * @param otherSlaveDataSources ??
 * @return ??
 */
public static DataSource createDataSource(final String name, final DataSource masterDataSource,
        final DataSource slaveDataSource, final DataSource... otherSlaveDataSources) {
    return new MasterSlaveDataSource(name, masterDataSource,
            Lists.asList(slaveDataSource, otherSlaveDataSources));
}

From source file:com.eviware.loadui.util.collections.SafeExplicitOrdering.java

@SafeVarargs
public static <T> Ordering<T> of(T leastValue, T... remainingValuesInOrder) {
    return of(Lists.asList(leastValue, remainingValuesInOrder));
}