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

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

Introduction

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

Prototype

@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayList() 

Source Link

Document

Creates a mutable, empty ArrayList instance (for Java 6 and earlier).

Usage

From source file:io.macgyver.server.BuildPlugins.java

public static void main(String[] args) throws IOException {

    ObjectMapper m = new ObjectMapper();

    Properties p = new Properties();
    p.load(new FileReader("../gradle.properties"));

    String version = p.getProperty("MACGYVER_VERSION");

    ObjectNode n = m.createObjectNode();
    n.put("version", version);

    ArrayNode plugins = m.createArrayNode();
    n.set("plugins", plugins);

    Pattern pattern = Pattern.compile(".*'(.+)'.*");
    File settingsGradle = new File("../settings.gradle");
    List<String> candidates = Lists.newArrayList();

    Files.readLines(settingsGradle, Charsets.UTF_8).forEach(it -> {
        Matcher matcher = pattern.matcher(it);
        if (matcher.matches()) {
            candidates.add(matcher.group(1));
        }//  w  ww . j a v a  2s. c  om
    });

    candidates.removeIf(it -> !it.startsWith("macgyver-plugin"));

    ObjectNode pi = m.createObjectNode();
    pi.put("name", "macgyver-core");
    pi.put("enabled", true);
    plugins.add(pi);
    candidates.forEach(it -> {
        ObjectNode pluginNode = m.createObjectNode();
        pluginNode.put("name", it);
        pluginNode.put("enabled", false);
        plugins.add(pluginNode);

    });

    File targetPlugins = new File("./src/main/resources/templates/plugins.json");
    System.out.println(m.writerWithDefaultPrettyPrinter().writeValueAsString(n));
    m.writerWithDefaultPrettyPrinter().writeValue(targetPlugins, n);
}

From source file:zookeeper.example.leader.LeaderSelectorExample.java

public static void main(String[] args) throws Exception {
    // all of the useful sample code is in ExampleClient.java

    System.out.println("Create " + CLIENT_QTY
            + " clients, have each negotiate for leadership and then wait a random number of seconds before letting another leader election occur.");
    System.out.println(//from  ww  w .j  av  a2s.c o  m
            "Notice that leader election is fair: all clients will become leader and will do so the same number of times.");

    List<CuratorFramework> clients = Lists.newArrayList();
    List<ExampleClient> examples = Lists.newArrayList();
    TestingServer server = new TestingServer();
    try {
        for (int i = 0; i < CLIENT_QTY; ++i) {
            CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(),
                    new ExponentialBackoffRetry(1000, 3));
            clients.add(client);

            ExampleClient example = new ExampleClient(client, PATH, "Client #" + i);
            examples.add(example);

            client.start();
            example.start();
        }

        System.out.println("Press enter/return to quit\n");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    } finally {
        System.out.println("Shutting down...");

        for (ExampleClient exampleClient : examples) {
            Closeables.closeQuietly(exampleClient);
        }
        for (CuratorFramework client : clients) {
            Closeables.closeQuietly(client);
        }

        Closeables.closeQuietly(server);
    }
}

From source file:org.apache.pulsar.client.tutorial.SampleAsyncProducerWithSchema.java

public static void main(String[] args) throws IOException {
    PulsarClient pulsarClient = PulsarClient.builder().serviceUrl("http://localhost:8080").build();

    Producer<JsonPojo> producer = pulsarClient.newProducer(JSONSchema.of(JsonPojo.class))
            .topic("persistent://my-property/use/my-ns/my-topic").sendTimeout(3, TimeUnit.SECONDS).create();

    List<CompletableFuture<MessageId>> futures = Lists.newArrayList();

    for (int i = 0; i < 10; i++) {
        final String content = "my-message-" + i;
        CompletableFuture<MessageId> future = producer.sendAsync(new JsonPojo(content));

        future.handle((v, ex) -> {//from  w  ww.j ava  2s  . com
            if (ex == null) {
                log.info("Message persisted: {}", content);
            } else {
                log.error("Error persisting message: {}", content, ex);
            }
            return null;
        });

        futures.add(future);
    }

    log.info("Waiting for async ops to complete");
    for (CompletableFuture<MessageId> future : futures) {
        future.join();
    }

    log.info("All operations completed");

    pulsarClient.close();
}

From source file:me.ellios.hedwig.zookeeper.example.leader.LeaderSelectorExample.java

public static void main(String[] args) throws Exception {
    // all of the useful sample code is in ExampleClient.java

    System.out.println("Create " + CLIENT_QTY
            + " clients, have each negotiate for leadership and then wait a random number of seconds before letting another leader election occur.");
    System.out.println(/*from   w  w  w.j  av  a 2  s .c o  m*/
            "Notice that leader election is fair: all clients will become leader and will do so the same number of times.");

    List<CuratorFramework> clients = Lists.newArrayList();
    List<ExampleClient> examples = Lists.newArrayList();
    TestingServer server = new TestingServer();
    try {
        for (int i = 0; i < CLIENT_QTY; ++i) {
            CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(),
                    new ExponentialBackoffRetry(1000, 3));
            clients.add(client);

            ExampleClient example = new ExampleClient(client, PATH, "Client #" + i);
            examples.add(example);

            client.start();
            example.start();
        }

        System.out.println("Press enter/return to quit\n");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    } finally {
        System.out.println("Shutting down...");

        for (ExampleClient exampleClient : examples) {
            exampleClient.close();
        }
        for (CuratorFramework client : clients) {
            client.close();
        }

        server.close();
    }
}

From source file:org.apache.nutch.crawl.SeedGenerator.java

public static void main(String[] args) throws Exception {
    String urlFormat = "http://oumen.com/detail.php?atid={{{1000,4460}}}";
    String[] urlParts = urlFormat.split("\\{\\{\\{\\d+\\,\\d+\\}\\}\\}");
    String[] placeholders = StringUtils.substringsBetween(urlFormat, "{{{", "}}}");

    ArrayList<ArrayList<Integer>> ranges = Lists.newArrayList();
    for (int i = 0; i < placeholders.length; ++i) {
        int min = Integer.parseInt(StringUtils.substringBefore(placeholders[i], ","));
        int max = Integer.parseInt(StringUtils.substringAfter(placeholders[i], ","));

        ranges.add(Lists.newArrayList(min, max));
    }// w  ww  .  jav  a2  s  .  co m

    // we can support only one placeholder right now

    StringBuilder content = new StringBuilder();
    for (int i = ranges.get(0).get(0); i <= ranges.get(0).get(1); ++i) {
        String url = urlParts[0] + i;
        if (urlParts.length > 1) {
            url += urlParts[1];
        }

        content.append(url);
        content.append("\n");
    }

    String tidyDomain = NetUtil.getTopLevelDomain(urlFormat);
    String file = StringUtils.substringBefore(tidyDomain, ".").toLowerCase().replaceAll("[^a-z]", "_");

    file = "/tmp/" + file + ".txt";
    FileUtils.writeStringToFile(new File(file), content.toString(), "utf-8");

    System.out.println("url seed results are saved in : " + file);
}

From source file:org.apache.spark.examples.streaming.QueueStream.java

public static void main(String[] args) throws Exception {
    final SparkConf sparkConf = new SparkConf().setAppName("QueueStream");

    // Create the context
    final JavaStreamingContext ssc = new JavaStreamingContext(sparkConf, new Duration(1000));

    // Create the queue through which RDDs can be pushed to a QueueInputDStream
    final Queue<JavaRDD<Integer>> rddQueue = new LinkedList<>();

    // Create and push some RDDs into the queue
    final List<Integer> list = Lists.newArrayList();
    for (int i = 0; i < 1000; i++) {
        list.add(i);/*  w  w w .  j  av  a2 s.co m*/
    }

    for (int i = 0; i < 30; i++) {
        rddQueue.add(ssc.sparkContext().parallelize(list));
    }

    // Create the QueueInputDStream and use it do some processing
    final JavaDStream<Integer> inputStream = ssc.queueStream(rddQueue);
    final JavaPairDStream<Integer, Integer> mappedStream = inputStream.mapToPair(i -> new Tuple2<>(i % 10, 1));
    final JavaPairDStream<Integer, Integer> reducedStream = mappedStream.reduceByKey((i1, i2) -> i1 + i2);

    reducedStream.print();
    ssc.start();
    ssc.awaitTermination();
}

From source file:faststore.dataserver.server.LeaderSelectorExample.java

public static void main(String[] args) throws Exception {
    // all of the useful sample code is in ExampleClient.java

    System.out.println("Create " + CLIENT_QTY
            + " clients, have each negotiate for leadership and then wait a random number of seconds before letting another leader election occur.");
    System.out.println(//ww  w  . j ava  2s. com
            "Notice that leader election is fair: all clients will become leader and will do so the same number of times.");

    List<CuratorFramework> clients = Lists.newArrayList();
    List<ExampleClient> examples = Lists.newArrayList();
    //        TestingServer           faststore.dataserver.server = new TestingServer();
    try {
        for (int i = 0; i < CLIENT_QTY; ++i) {
            CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181",
                    new ExponentialBackoffRetry(1000, 3));
            clients.add(client);

            ExampleClient example = new ExampleClient(client, PATH, "Client #" + i);
            examples.add(example);

            client.start();
            example.start();
        }

        System.out.println("Press enter/return to quit\n");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    } finally {
        System.out.println("Shutting down...");

        for (ExampleClient exampleClient : examples) {
            CloseableUtils.closeQuietly(exampleClient);
        }
        for (CuratorFramework client : clients) {
            CloseableUtils.closeQuietly(client);
        }

        //            CloseableUtils.closeQuietly(faststore.dataserver.server);
    }
}

From source file:samples.ExampleCreateIssuesAsynchronous.java

public static void main(String[] args) throws IOException {
    final AsynchronousJiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
    final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, "admin",
            "admin");

    try {/*from   w  w  w  . j  av  a  2s  .co  m*/
        final List<Promise<BasicIssue>> promises = Lists.newArrayList();
        final IssueRestClient issueClient = restClient.getIssueClient();

        System.out.println("Sending issue creation requests...");
        for (int i = 0; i < 100; i++) {
            final String summary = "NewIssue#" + i;
            final IssueInput newIssue = new IssueInputBuilder("TST", 1L, summary).build();
            System.out.println("\tCreating: " + summary);
            promises.add(issueClient.createIssue(newIssue));
        }

        System.out.println("Collecting responses...");
        final Iterable<BasicIssue> createdIssues = transform(promises,
                new Function<Promise<BasicIssue>, BasicIssue>() {
                    @Override
                    public BasicIssue apply(Promise<BasicIssue> promise) {
                        return promise.claim();
                    }
                });

        System.out.println("Created issues:\n" + Joiner.on("\n").join(createdIssues));
    } finally {
        restClient.close();
    }
}

From source file:com.poc.zookeeper.leader.LeaderSelectorExample.java

public static void main(String[] args) throws Exception {
    // all of the useful sample code is in ExampleClient.java

    System.out.println("Create " + CLIENT_QTY
            + " clients, have each negotiate for leadership and then wait a random number of seconds before letting another leader election occur.");
    System.out.println(/*from   w  w w  .  ja  va  2 s.  c o m*/
            "Notice that leader election is fair: all clients will become leader and will do so the same number of times.");

    List<CuratorFramework> clients = Lists.newArrayList();
    List<ExampleClient> examples = Lists.newArrayList();
    TestingServer server = new TestingServer(2181);
    try {
        for (int i = 0; i < CLIENT_QTY; ++i) {
            CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(),
                    new ExponentialBackoffRetry(1000, 3));
            clients.add(client);

            ExampleClient example = new ExampleClient(client, PATH, "Client #" + i);
            examples.add(example);

            client.start();
            example.start();
        }

        System.out.println("Press enter/return to quit\n");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    } finally {
        System.out.println("Shutting down...");

        for (ExampleClient exampleClient : examples) {
            CloseableUtils.closeQuietly(exampleClient);
        }
        for (CuratorFramework client : clients) {
            CloseableUtils.closeQuietly(client);
        }

        CloseableUtils.closeQuietly(server);
    }
}

From source file:zookeeper.curator.leader.LeaderSelectorExample.java

public static void main(String[] args) throws Exception {
    // all of the useful sample code is in ExampleClient.java

    System.out.println("Create " + CLIENT_QTY
            + " clients, have each negotiate for leadership and then wait a random number of seconds before letting another leader election occur.");
    System.out.println(/*from w w  w . j  a  v  a 2 s .  com*/
            "Notice that leader election is fair: all clients will become leader and will do so the same number of times.");

    List<CuratorFramework> clients = Lists.newArrayList();
    List<ExampleClient> examples = Lists.newArrayList();
    TestingServer server = new TestingServer();
    try {
        for (int i = 0; i < CLIENT_QTY; ++i) {
            CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(),
                    new ExponentialBackoffRetry(1000, 3));
            clients.add(client);

            ExampleClient example = new ExampleClient(client, PATH, "Client #" + i);
            examples.add(example);

            client.start();
            example.start();
        }

        System.out.println("Press enter/return to quit\n");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    } finally {
        System.out.println("Shutting down...");

        for (ExampleClient exampleClient : examples) {
            CloseableUtils.closeQuietly(exampleClient);
        }
        for (CuratorFramework client : clients) {
            CloseableUtils.closeQuietly(client);
        }

        CloseableUtils.closeQuietly(server);
    }
}