Example usage for java.util List get

List of usage examples for java.util List get

Introduction

In this page you can find the example usage for java.util List get.

Prototype

E get(int index);

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:edu.byu.nlp.crowdsourcing.app.Baseline.java

public static void main(String[] args) throws IOException {
    new ArgumentParser(Baseline.class).parseArgs(args);
    RandomGenerator rnd = new MersenneTwister(seed);

    // Data/*from w  w  w  .ja v a 2 s.  c  om*/
    Dataset trainingData;
    Dataset heldoutData;
    // use an existing split
    if (exists(malletTrain) && exists(malletTest)) {
        trainingData = Datasets.readMallet2Labeled(malletTrain);
        heldoutData = Datasets.readMallet2Labeled(malletTest, trainingData.getInfo().getLabelIndexer(),
                trainingData.getInfo().getFeatureIndexer(), trainingData.getInfo().getInstanceIdIndexer(),
                trainingData.getInfo().getAnnotatorIdIndexer());
    }
    // create a new split
    else {
        // Read and split the data
        Dataset fullData = readData(rnd);
        List<Dataset> partitions = Datasets.split(fullData, new double[] { splitPercent, 100 - splitPercent });
        trainingData = partitions.get(0);
        heldoutData = partitions.get(1);

        // record the experimentData
        if (malletTrain != null && !malletTrain.isEmpty()) {
            Datasets.writeLabeled2Mallet(trainingData, malletTrain);
        }
        if (malletTest != null && !malletTest.isEmpty()) {
            Datasets.writeLabeled2Mallet(heldoutData, malletTest);
        }
    }

    // Train the model
    NaiveBayesClassifier model = new NaiveBayesLearner().learnFrom(trainingData);
    /*
    // Print out the data to eyeball the feature set.
    for (DatasetInstance instance : fullData.labeledData()) {
      StringBuilder str = new StringBuilder();
      for (Entry e : instance.getData().sparseEntries()) {
        str.append(fullData.getWordIndex().get(e.getIndex()));
        str.append(" ");
      }
      System.out.println(str.toString());
    }
    */

    // Compute accuracy
    System.out.println("Accuracy: " + computeAccuracy(model, heldoutData));
}

From source file:com.github.sdbg.debug.core.internal.webkit.protocol.TestMain.java

/**
 * @param args//w  w w . j av a  2s . c  o  m
 * @throws IOException
 * @throws InterruptedException
 * @throws JSONException
 */
public static void main(String[] args) throws IOException, InterruptedException {
    if (args.length != 1) {
        System.out.println("usage Main <port>");
        return;
    }

    int port = Integer.parseInt(args[0]);

    List<ChromiumTabInfo> tabs = ChromiumConnector.getAvailableTabs(port);

    //ChromiumConnector.getWebSocketURLFor(port, 1);
    URI uri = URI.create(tabs.get(0).getWebSocketDebuggerUrl());
    WebkitConnection connection = new WebkitConnection(uri);

    connection.addConnectionListener(new WebkitConnectionListener() {
        @Override
        public void connectionClosed(WebkitConnection connection) {
            System.out.println("connection closed");
        }
    });

    connection.connect();

    System.out.println("connection opened");

    // add a console listener
    connection.getConsole().addConsoleListener(new ConsoleListener() {
        @Override
        public void messageAdded(String message, String url, int line, List<CallFrame> stackTrace) {
            System.out.println("message added: " + message);
        }

        @Override
        public void messageRepeatCountUpdated(int count) {
            System.out.println("messageRepeatCountUpdated: " + count);
        }

        @Override
        public void messagesCleared() {
            System.out.println("messages cleared");
        }
    });

    // enable console events
    connection.getConsole().enable();

    // add a debugger listener
    connection.getDebugger().addDebuggerListener(new DebuggerListener() {
        @Override
        public void debuggerBreakpointResolved(WebkitBreakpoint breakpoint) {
            System.out.println("debuggerBreakpointResolved: " + breakpoint);
        }

        @Override
        public void debuggerGlobalObjectCleared() {
            System.out.println("debuggerGlobalObjectCleared");
        }

        @Override
        public void debuggerPaused(PausedReasonType reason, List<WebkitCallFrame> frames,
                WebkitRemoteObject exception) {
            System.out.println("debugger paused: " + reason);

            for (WebkitCallFrame frame : frames) {
                System.out.println("  " + frame);
            }
        }

        @Override
        public void debuggerResumed() {
            System.out.println("debugger resumed");
        }

        @Override
        public void debuggerScriptParsed(WebkitScript script) {
            System.out.println("debugger script: " + script);
        }
    });

    // enable debugger events
    connection.getDebugger().enable();

    // navigate to cheese.com
    connection.getPage().navigate("http://www.cheese.com");

    //Thread.sleep(2000);

    //connection.close();
}

From source file:com.doculibre.constellio.utils.license.ApplyLicenseUtils.java

/**
 * @param args/*from   w w w  .ja  va2 s  .  c  o  m*/
 */
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    URL licenceHeaderURL = ApplyLicenseUtils.class.getResource("LICENSE_HEADER");
    File binDir = ClasspathUtils.getClassesDir();
    File projectDir = binDir.getParentFile();
    //        File dryrunDir = new File(projectDir, "dryrun");
    File licenceFile = new File(licenceHeaderURL.toURI());
    List<String> licenceLines = readLines(licenceFile);
    //        for (int i = 0; i < licenceLines.size(); i++) {
    //            String licenceLine = licenceLines.get(i);
    //            licenceLines.set(i, " * " + licenceLine);
    //        }
    //        licenceLines.add(0, "/**");
    //        licenceLines.add(" */");

    List<File> javaFiles = (List<File>) org.apache.commons.io.FileUtils.listFiles(projectDir,
            new String[] { "java" }, true);
    for (File javaFile : javaFiles) {
        if (isValidPackage(javaFile)) {
            List<String> javaFileLines = readLines(javaFile);
            if (!javaFileLines.isEmpty()) {
                boolean modified = false;
                String firstLineTrim = javaFileLines.get(0).trim();
                if (firstLineTrim.startsWith("package")) {
                    modified = true;
                    javaFileLines.addAll(0, licenceLines);
                } else if (firstLineTrim.startsWith("/**")) {
                    int indexOfEndCommentLine = -1;
                    loop2: for (int i = 0; i < javaFileLines.size(); i++) {
                        String javaFileLine = javaFileLines.get(i);
                        if (javaFileLine.indexOf("*/") != -1) {
                            indexOfEndCommentLine = i;
                            break loop2;
                        }
                    }
                    if (indexOfEndCommentLine != -1) {
                        modified = true;
                        int i = 0;
                        loop3: for (Iterator<String> it = javaFileLines.iterator(); it.hasNext();) {
                            it.next();
                            if (i <= indexOfEndCommentLine) {
                                it.remove();
                            } else {
                                break loop3;
                            }
                            i++;
                        }
                        javaFileLines.addAll(0, licenceLines);
                    } else {
                        throw new RuntimeException(
                                "Missing end comment for file " + javaFile.getAbsolutePath());
                    }
                }

                if (modified) {
                    //                        String outputFilePath = javaFile.getPath().substring(projectDir.getPath().length());
                    //                        File outputFile = new File(dryrunDir, outputFilePath);
                    //                        outputFile.getParentFile().mkdirs();
                    //                        System.out.println(outputFile.getPath());
                    //                        FileOutputStream fos = new FileOutputStream(outputFile);
                    System.out.println(javaFile.getPath());
                    FileOutputStream fos = new FileOutputStream(javaFile);
                    IOUtils.writeLines(javaFileLines, "\n", fos);
                    IOUtils.closeQuietly(fos);
                }
            }
        }
    }
}

From source file:com.tomdoel.mpg2dcm.Mpg2Dcm.java

public static void main(String[] args) {
    try {/*from w  ww .  j  av a 2s .  com*/
        final Options helpOptions = new Options();
        helpOptions.addOption("h", false, "Print help for this application");

        final DefaultParser parser = new DefaultParser();
        final CommandLine commandLine = parser.parse(helpOptions, args);

        if (commandLine.hasOption('h')) {
            final String helpHeader = "Converts an mpeg2 video file to Dicom\n\n";
            String helpFooter = "\nPlease report issues at github.com/tomdoel/mpg2dcm";

            final HelpFormatter helpFormatter = new HelpFormatter();
            helpFormatter.printHelp("Mpg2Dcm mpegfile dicomfile", helpHeader, helpOptions, helpFooter, true);

        } else {
            final List<String> remainingArgs = commandLine.getArgList();
            if (remainingArgs.size() < 2) {
                throw new org.apache.commons.cli.ParseException("ERROR : Not enough arguments specified.");
            }

            final String mpegFileName = remainingArgs.get(0);
            final String dicomFileName = remainingArgs.get(1);
            final File mpegFile = new File(mpegFileName);
            final File dicomOutputFile = new File(dicomFileName);
            MpegFileConverter.convert(mpegFile, dicomOutputFile);
        }
    } catch (org.apache.commons.cli.ParseException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.ohalo.cn.awt.JFreeChartTest.java

public static void main(String[] args) throws Exception {
    JFreeChartTest test = new JFreeChartTest();
    List<JFreeChart> charts = test.printHardDiskCharts();

    JPanel mainPanel = new JPanel();
    JFreeChart chart = charts.get(0);
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(400, 300));
    panel.add(chartPanel, BorderLayout.CENTER);
    mainPanel.add(panel, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(20, 20, 10, 10), 0, 0));

    chart = charts.get(1);// ww  w. j  a v a  2  s  . c o m
    panel = new JPanel();
    ChartPanel chartPanel2 = new ChartPanel(chart);
    chartPanel2.setPreferredSize(new Dimension(400, 300));
    panel.setLayout(new BorderLayout());
    panel.add(chartPanel2, BorderLayout.CENTER);
    mainPanel.add(panel, new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0));

    chart = charts.get(2);
    panel = new JPanel();
    ChartPanel chartPanel3 = new ChartPanel(chart);
    chartPanel3.setPreferredSize(new Dimension(400, 300));
    panel.setLayout(new BorderLayout());
    panel.add(chartPanel3, BorderLayout.CENTER);
    mainPanel.add(panel, new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0));

    chart = charts.get(3);
    panel = new JPanel();
    ChartPanel chartPanel4 = new ChartPanel(chart);
    chartPanel4.setPreferredSize(new Dimension(400, 300));
    panel.setLayout(new BorderLayout());
    panel.add(chartPanel4, BorderLayout.CENTER);

    mainPanel.add(panel, new GridBagConstraints(1, 1, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(10, 10, 20, 20), 0, 0));

    JDialog dialog = new JDialog(new JFrame(), true);
    dialog.setTitle("?");
    dialog.setSize(850, 650);
    dialog.getContentPane().add(mainPanel);
    dialog.setVisible(true);
}

From source file:com.doculibre.constellio.utils.izpack.UsersXmlFileUtils.java

public static void main(String[] argv) {
    createEmptyUsersFile();/*w  ww  .ja  v  a 2  s  .co  m*/

    ConstellioUser dataUser = new ConstellioUser("admin", "lol", ConstellioSpringUtils.getDefaultLocale());
    dataUser.setFirstName("System");
    dataUser.setLastName("Administrator");
    dataUser.getRoles().add(Roles.ADMIN);

    addUserTo(dataUser);

    List<ConstellioUser> users = readUsers();

    Assert.assertEquals(1, users.size());

    ConstellioUser user = users.get(0);

    Assert.assertTrue(user.checkPassword("lol"));

    //        Assert.assertEquals(1, user.getRoles());

    Assert.assertTrue(user.isAdmin());
    System.out.println("Succes!" + DEFAULT_USERS_FILE);

}

From source file:Main.java

License:asdf

public static void main(String[] args) {
    int howManyWords = 2;
    List<String> listOfWords = new ArrayList<>();
    Random random = new Random();
    listOfWords.addAll(Arrays.asList(randomMessages));
    List<String> selectedRandomMessages = new ArrayList<>();
    for (int i = 0; i < howManyWords; i++) {
        int randomNumber = random.nextInt(listOfWords.size());
        String randomItem = listOfWords.get(randomNumber);
        selectedRandomMessages.add(randomItem);
        listOfWords.remove(randomItem);//from  w w w.j  ava  2 s  . c  o m
    }
    System.out.println(selectedRandomMessages);
}

From source file:com.jdom.word.playdough.model.gamepack.GamePackFileGenerator.java

/**
 * Usage: java GamePackFileGenerator <input file> <output directory>
 * //from   w  w w. j a  va 2s . c o  m
 * @param args
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    File dictionaryFile = new File(args[0]);

    // Validate arguments first
    if (!dictionaryFile.isFile()) {
        throw new IllegalArgumentException("The specified file does not seem to be a valid file ["
                + dictionaryFile.getAbsolutePath() + "]!");
    }

    File outputDir = new File(args[1]);
    if (!outputDir.isDirectory()) {
        throw new IllegalArgumentException("The specified directory does not seem to be a valid directory ["
                + outputDir.getAbsolutePath() + "]!");
    }

    Set<String> words = GamePackFileGenerator.readWordsFromDictionaryFile(dictionaryFile);

    GamePackFileGenerator generator = new GamePackFileGenerator(words);
    List<Properties> properties = generator.generateGamePacks(20);

    for (int i = 0; i < properties.size(); i++) {
        Properties current = properties.get(i);
        File outputFile = new File(outputDir, i + ".properties");
        PropertiesUtil.writePropertiesFile(current, outputFile);
    }
}

From source file:com.tomdoel.mpg2dcm.Xml2Dicom.java

public static void main(String[] args) {
    try {/*w ww  .  jav  a2  s.c  om*/
        final Options helpOptions = new Options();
        helpOptions.addOption("h", false, "Print help for this application");

        final DefaultParser parser = new DefaultParser();
        final CommandLine commandLine = parser.parse(helpOptions, args);

        if (commandLine.hasOption('h')) {
            final String helpHeader = "Converts an endoscopic xml and video files to Dicom\n\n";
            String helpFooter = "\nPlease report issues at github.com/tomdoel/mpg2dcm";

            final HelpFormatter helpFormatter = new HelpFormatter();
            helpFormatter.printHelp("Xml2Dcm xml-file dicom-output-path", helpHeader, helpOptions, helpFooter,
                    true);

        } else {
            final List<String> remainingArgs = commandLine.getArgList();
            if (remainingArgs.size() < 2) {
                throw new org.apache.commons.cli.ParseException("ERROR : Not enough arguments specified.");
            }

            final String xmlInputFileName = remainingArgs.get(0);
            final String dicomOutputPath = remainingArgs.get(1);
            EndoscopicXmlToDicomConverter.convert(new File(xmlInputFileName), dicomOutputPath);
        }
    } catch (org.apache.commons.cli.ParseException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:io.s4.comm.util.JSONUtil.java

public static void main(String[] args) {
    Map<String, Object> outerMap = new HashMap<String, Object>();

    outerMap.put("doubleValue", 0.3456d);
    outerMap.put("integerValue", 175647);
    outerMap.put("longValue", 0x0000005000067000l);
    outerMap.put("stringValue", "Hello there");

    Map<String, Object> innerMap = null;
    List<Map<String, Object>> innerList1 = new ArrayList<Map<String, Object>>();

    innerMap = new HashMap<String, Object>();
    innerMap.put("name", "kishore");
    innerMap.put("count", 1787265);
    innerList1.add(innerMap);/*from  ww  w.j  av a  2s  .  c  o  m*/
    innerMap = new HashMap<String, Object>();
    innerMap.put("name", "fred");
    innerMap.put("count", 11);
    innerList1.add(innerMap);

    outerMap.put("innerList1", innerList1);

    List<Integer> innerList2 = new ArrayList<Integer>();
    innerList2.add(65);
    innerList2.add(2387894);
    innerList2.add(456);

    outerMap.put("innerList2", innerList2);

    JSONObject jsonObject = toJSONObject(outerMap);

    String flatJSONString = null;
    try {
        System.out.println(jsonObject.toString(3));
        flatJSONString = jsonObject.toString();
        Object o = jsonObject.get("innerList1");
        if (!(o instanceof JSONArray)) {
            System.out.println("Unexpected type of list " + o.getClass().getName());
        } else {
            JSONArray jsonArray = (JSONArray) o;
            o = jsonArray.get(0);
            if (!(o instanceof JSONObject)) {
                System.out.println("Unexpected type of map " + o.getClass().getName());
            } else {
                JSONObject innerJSONObject = (JSONObject) o;
                System.out.println(innerJSONObject.get("name"));
            }
        }
    } catch (JSONException je) {
        je.printStackTrace();
    }

    if (!flatJSONString.equals(toJsonString(outerMap))) {
        System.out.println("JSON strings don't match!!");
    }

    Map<String, Object> map = getMapFromJson(flatJSONString);

    Object o = map.get("doubleValue");
    if (!(o instanceof Double)) {
        System.out.println("Expected type Double, got " + o.getClass().getName());
        Double doubleValue = (Double) o;
        if (doubleValue != 0.3456d) {
            System.out.println("Expected 0.3456, got " + doubleValue);
        }
    }

    o = map.get("innerList1");
    if (!(o instanceof List)) {
        System.out.println("Expected implementation of List, got " + o.getClass().getName());
    } else {
        List innerList = (List) o;
        o = innerList.get(0);
        if (!(o instanceof Map)) {
            System.out.println("Expected implementation of Map, got " + o.getClass().getName());
        } else {
            innerMap = (Map) o;
            System.out.println(innerMap.get("name"));
        }
    }
    System.out.println(map);
}