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(Iterator<? extends E> elements) 

Source Link

Document

Creates a mutable ArrayList instance containing the given elements; a very thin shortcut for creating an empty list and then calling Iterators#addAll .

Usage

From source file:ivory.app.PreprocessWt10g.java

public static void main(String[] args) throws Exception {
    Map<String, String> map = new ImmutableMap.Builder<String, String>()
            .put(PreprocessCollection.COLLECTION_NAME, "Wt10g")
            .put(PreprocessCollection.DOCNO_MAPPING, Wt10gDocnoMapping.class.getCanonicalName())
            .put(PreprocessCollection.INPUTFORMAT, SequenceFileInputFormat.class.getCanonicalName())
            .put(PreprocessCollection.TOKENIZER, GalagoTokenizer.class.getCanonicalName())
            .put(PreprocessCollection.MIN_DF, "10").build();

    List<String> s = Lists.newArrayList(args);
    for (Map.Entry<String, String> e : map.entrySet()) {
        s.add("-" + e.getKey());
        s.add(e.getValue());//from   w  w w  .  ja v  a  2  s.  c om
    }

    ToolRunner.run(new PreprocessWt10g(), s.toArray(new String[s.size()]));
}

From source file:ivory.app.PreprocessTrecCollection.java

public static void main(String[] args) throws Exception {
    Map<String, String> map = new ImmutableMap.Builder<String, String>()
            .put(PreprocessCollection.DOCNO_MAPPING, TrecDocnoMapping.class.getCanonicalName())
            .put(PreprocessCollection.INPUTFORMAT, TrecDocumentInputFormat.class.getCanonicalName())
            .put(PreprocessCollection.TOKENIZER, GalagoTokenizer.class.getCanonicalName())
            .put(PreprocessCollection.MIN_DF, "2").build();

    List<String> s = Lists.newArrayList(args);
    for (Map.Entry<String, String> e : map.entrySet()) {
        s.add("-" + e.getKey());
        s.add(e.getValue());/*from  w w  w.j  a va  2  s .c  o  m*/
    }

    ToolRunner.run(new PreprocessTrecCollection(), s.toArray(new String[s.size()]));
}

From source file:br.com.sitedoph.mahout_examples.BankMarketingClassificationMain.java

public static void main(String[] args) throws Exception {
    List<TelephoneCall> calls = Lists.newArrayList(new TelephoneCallParser("bank-full.csv"));

    double heldOutPercentage = 0.10;

    double biggestScore = 0.0;

    for (int run = 0; run < 20; run++) {
        Collections.shuffle(calls);
        int cutoff = (int) (heldOutPercentage * calls.size());
        List<TelephoneCall> testAccuracyData = calls.subList(0, cutoff);
        List<TelephoneCall> trainData = calls.subList(cutoff, calls.size());

        List<TelephoneCall> testUnknownData = new ArrayList<>();

        testUnknownData.add(getUnknownTelephoneCall(trainData));

        OnlineLogisticRegression lr = new OnlineLogisticRegression(NUM_CATEGORIES, TelephoneCall.FEATURES,
                new L1()).learningRate(1).alpha(1).lambda(0.000001).stepOffset(10000).decayExponent(0.2);

        for (int pass = 0; pass < 20; pass++) {
            for (TelephoneCall observation : trainData) {
                lr.train(observation.getTarget(), observation.asVector());
            }//from w  w w  .j a  v  a  2  s.c  om
            Auc eval = new Auc(0.5);
            for (TelephoneCall testCall : testAccuracyData) {
                biggestScore = evaluateTheCallAndGetBiggestScore(biggestScore, lr, eval, testCall);
            }
            System.out.printf("run: %-5d pass: %-5d current learning rate: %-5.4f \teval auc %-5.4f\n", run,
                    pass, lr.currentLearningRate(), eval.auc());

            for (TelephoneCall testCall : testUnknownData) {
                final double score = lr.classifyScalar(testCall.asVector());
                System.out.println(" score: " + score + " accuracy " + eval.auc() + " call fields: "
                        + testCall.getFields());
            }
        }
    }
}

From source file:ivory.app.PreprocessTrec45.java

public static void main(String[] args) throws Exception {
    Map<String, String> map = new ImmutableMap.Builder<String, String>()
            .put(PreprocessCollection.COLLECTION_NAME, "TREC_vol45")
            .put(PreprocessCollection.DOCNO_MAPPING, TrecDocnoMapping.class.getCanonicalName())
            .put(PreprocessCollection.INPUTFORMAT, TrecDocumentInputFormat.class.getCanonicalName())
            .put(PreprocessCollection.TOKENIZER, GalagoTokenizer.class.getCanonicalName())
            .put(PreprocessCollection.MIN_DF, "2").build();

    List<String> s = Lists.newArrayList(args);
    for (Map.Entry<String, String> e : map.entrySet()) {
        s.add("-" + e.getKey());
        s.add(e.getValue());//from w  ww. ja  va 2s  .  c o  m
    }

    ToolRunner.run(new PreprocessTrec45(), s.toArray(new String[s.size()]));
}

From source file:org.apache.brooklyn.demo.SimpleCassandraCluster.java

public static void main(String[] argv) {
    List<String> args = Lists.newArrayList(argv);
    String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+");
    String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION);

    BrooklynLauncher launcher = BrooklynLauncher
            .newInstance().application(EntitySpec
                    .create(StartableApplication.class, SimpleCassandraCluster.class).displayName("Cassandra"))
            .webconsolePort(port).location(location).start();

    Entities.dumpInfo(launcher.getApplications());
}

From source file:org.apache.brooklyn.demo.KafkaClusterExample.java

public static void main(String[] argv) {
    List<String> args = Lists.newArrayList(argv);
    String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+");
    String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION);

    BrooklynLauncher launcher = BrooklynLauncher.newInstance()
            .application(new KafkaClusterExample().appDisplayName("Kafka cluster application"))
            .webconsolePort(port).location(location).start();

    Entities.dumpInfo(launcher.getApplications());
}

From source file:gtu.youtube.ListStreams.java

/**
 * List streams for the user's channel./*  ww w .  ja  va2  s.  co  m*/
 */
public static void main(String[] args) {

    // This OAuth 2.0 access scope allows for read-only access to the
    // authenticated user's account, but not other types of account access.
    List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube.readonly");

    try {
        // Authorize the request.
        Credential credential = Auth.authorize(scopes, "liststreams");

        // This object is used to make YouTube Data API requests.
        youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential)
                .setApplicationName("youtube-cmdline-liststreams-sample").build();

        // Create a request to list liveStream resources.
        YouTube.LiveStreams.List livestreamRequest = youtube.liveStreams().list("id,snippet");

        // Modify results to only return the user's streams.
        livestreamRequest.setMine(true);

        // Execute the API request and return the list of streams.
        LiveStreamListResponse returnedListResponse = livestreamRequest.execute();
        List<LiveStream> returnedList = returnedListResponse.getItems();

        // Print information from the API response.
        System.out.println("\n================== Returned Streams ==================\n");
        for (LiveStream stream : returnedList) {
            System.out.println("  - Id: " + stream.getId());
            System.out.println("  - Title: " + stream.getSnippet().getTitle());
            System.out.println("  - Description: " + stream.getSnippet().getDescription());
            System.out.println("  - Published At: " + stream.getSnippet().getPublishedAt());
            System.out.println("\n-------------------------------------------------------------\n");
        }

    } catch (GoogleJsonResponseException e) {
        System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : "
                + e.getDetails().getMessage());
        e.printStackTrace();

    } catch (IOException e) {
        System.err.println("IOException: " + e.getMessage());
        e.printStackTrace();
    } catch (Throwable t) {
        System.err.println("Throwable: " + t.getMessage());
        t.printStackTrace();
    }
}

From source file:io.cloudsoft.builds.Infrastructure.java

public static void main(String[] argv) {
    List<String> args = Lists.newArrayList(argv);
    String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+");
    String location = CommandLineUtil.getCommandLineOption(args, "--location", "monterey");

    LocalManagementContext mgmt = new LocalManagementContext();

    BrooklynLauncher.newInstance()//w ww . ja  v  a  2 s  .  co m
            .application(EntitySpecs.appSpec(Infrastructure.class).displayName("Infrastructure"))
            .webconsolePort(port).managementContext(mgmt).location(location).start();
}

From source file:ivory.app.PreprocessMedline.java

public static void main(String[] args) throws Exception {
    Map<String, String> map = new ImmutableMap.Builder<String, String>()
            .put(PreprocessCollection.COLLECTION_NAME, "Medline")
            .put(PreprocessCollection.DOCNO_MAPPING, MedlineDocnoMapping.class.getCanonicalName())
            .put(PreprocessCollection.INPUTFORMAT, MedlineCitationInputFormat.class.getCanonicalName())
            .put(PreprocessCollection.TOKENIZER, GalagoTokenizer.class.getCanonicalName())
            .put(PreprocessCollection.MIN_DF, "2").build();

    List<String> s = Lists.newArrayList(args);
    for (Map.Entry<String, String> e : map.entrySet()) {
        s.add("-" + e.getKey());
        s.add(e.getValue());//from  w w w .jav  a  2  s.  co  m
    }

    ToolRunner.run(new PreprocessMedline(), s.toArray(new String[s.size()]));
}

From source file:com.google.api.services.samples.calendar.sync.ConditionalRetrievalSample.java

public static void main(String[] args) {
    try {/*from   w w  w .j a  v a 2 s.c  o m*/
        List<String> scopes = Lists.newArrayList(CalendarScopes.CALENDAR);
        client = Utils.createCalendarClient(scopes);
        run();
    } catch (Throwable t) {
        t.printStackTrace();
        System.exit(1);
    }
}