Example usage for java.util ArrayList add

List of usage examples for java.util ArrayList add

Introduction

In this page you can find the example usage for java.util ArrayList add.

Prototype

public boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this list.

Usage

From source file:com.bright.json.JSonRequestor.java

public static void main(String[] args) {
    String fileBasename = null;//w w w  .ja  v a 2  s  . c om
    String[] zipArgs = null;
    JFileChooser chooser = new JFileChooser("/Users/panos/STR_GRID");
    try {

        chooser.setCurrentDirectory(new java.io.File("."));
        chooser.setDialogTitle("Select the input directory");

        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);

        if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
            System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
            System.out.println("getSelectedFile() : " + chooser.getSelectedFile());

            // String fileBasename =
            // chooser.getSelectedFile().toString().substring(chooser.getSelectedFile().toString().lastIndexOf(File.separator)+1,chooser.getSelectedFile().toString().lastIndexOf("."));
            fileBasename = chooser.getSelectedFile().toString()
                    .substring(chooser.getSelectedFile().toString().lastIndexOf(File.separator) + 1);
            System.out.println("Base name: " + fileBasename);

            zipArgs = new String[] { chooser.getSelectedFile().toString(),
                    chooser.getCurrentDirectory().toString() + File.separator + fileBasename + ".zip" };
            com.bright.utils.ZipFile.main(zipArgs);

        } else {
            System.out.println("No Selection ");

        }
    } catch (Exception e) {

        System.out.println(e.toString());

    }

    JTextField uiHost = new JTextField("ucs-head.brightcomputing.com");
    // TextPrompt puiHost = new
    // TextPrompt("hadoop.brightcomputing.com",uiHost);
    JTextField uiUser = new JTextField("nexus");
    // TextPrompt puiUser = new TextPrompt("nexus", uiUser);
    JTextField uiPass = new JPasswordField("system");
    // TextPrompt puiPass = new TextPrompt("", uiPass);
    JTextField uiWdir = new JTextField("/home/nexus/pp1234");
    // TextPrompt puiWdir = new TextPrompt("/home/nexus/nexus_workdir",
    // uiWdir);
    JTextField uiOut = new JTextField("foo");
    // TextPrompt puiOut = new TextPrompt("foobar123", uiOut);

    JPanel myPanel = new JPanel(new GridLayout(5, 1));
    myPanel.add(new JLabel("Bright HeadNode hostname:"));
    myPanel.add(uiHost);
    // myPanel.add(Box.createHorizontalStrut(1)); // a spacer
    myPanel.add(new JLabel("Username:"));
    myPanel.add(uiUser);
    myPanel.add(new JLabel("Password:"));
    myPanel.add(uiPass);
    myPanel.add(new JLabel("Working Directory:"));
    myPanel.add(uiWdir);
    // myPanel.add(Box.createHorizontalStrut(1)); // a spacer
    myPanel.add(new JLabel("Output Study Name ( -s ):"));
    myPanel.add(uiOut);

    int result = JOptionPane.showConfirmDialog(null, myPanel, "Please fill in all the fields.",
            JOptionPane.OK_CANCEL_OPTION);
    if (result == JOptionPane.OK_OPTION) {
        System.out.println("Input received.");

    }

    String rfile = uiWdir.getText();
    String rhost = uiHost.getText();
    String ruser = uiUser.getText();
    String rpass = uiPass.getText();
    String nexusOut = uiOut.getText();

    String[] myarg = new String[] { zipArgs[1], ruser + "@" + rhost + ":" + rfile, nexusOut, fileBasename };
    com.bright.utils.ScpTo.main(myarg);

    String cmURL = "https://" + rhost + ":8081/json";
    List<Cookie> cookies = doLogin(ruser, rpass, cmURL);
    chkVersion(cmURL, cookies);

    jobSubmit myjob = new jobSubmit();
    jobSubmit.jobObject myjobObj = new jobSubmit.jobObject();

    myjob.setService("cmjob");
    myjob.setCall("submitJob");

    myjobObj.setQueue("defq");
    myjobObj.setJobname("myNexusJob");
    myjobObj.setAccount(ruser);
    myjobObj.setRundirectory(rfile);
    myjobObj.setUsername(ruser);
    myjobObj.setGroupname("cmsupport");
    myjobObj.setPriority("1");
    myjobObj.setStdinfile(rfile + "/stdin-mpi");
    myjobObj.setStdoutfile(rfile + "/stdout-mpi");
    myjobObj.setStderrfile(rfile + "/stderr-mpi");
    myjobObj.setResourceList(Arrays.asList(""));
    myjobObj.setDependencies(Arrays.asList(""));
    myjobObj.setMailNotify(false);
    myjobObj.setMailOptions("ALL");
    myjobObj.setMaxWallClock("00:10:00");
    myjobObj.setNumberOfProcesses(1);
    myjobObj.setNumberOfNodes(1);
    myjobObj.setNodes(Arrays.asList(""));
    myjobObj.setCommandLineInterpreter("/bin/bash");
    myjobObj.setUserdefined(Arrays.asList("cd " + rfile, "date", "pwd"));
    myjobObj.setExecutable("mpirun");
    myjobObj.setArguments("-env I_MPI_FABRICS shm:tcp " + Constants.NEXUSSIM_EXEC + " -mpi -c " + rfile + "/"
            + fileBasename + "/" + fileBasename + " -s " + rfile + "/" + fileBasename + "/" + nexusOut);
    myjobObj.setModules(Arrays.asList("shared", "nexus", "intel-mpi/64"));
    myjobObj.setDebug(false);
    myjobObj.setBaseType("Job");
    myjobObj.setIsSlurm(true);
    myjobObj.setUniqueKey(0);
    myjobObj.setModified(false);
    myjobObj.setToBeRemoved(false);
    myjobObj.setChildType("SlurmJob");
    myjobObj.setJobID("Nexus test");

    // Map<String,jobSubmit.jobObject > mymap= new HashMap<String,
    // jobSubmit.jobObject>();
    // mymap.put("Slurm",myjobObj);
    ArrayList<Object> mylist = new ArrayList<Object>();
    mylist.add("slurm");
    mylist.add(myjobObj);
    myjob.setArgs(mylist);

    GsonBuilder builder = new GsonBuilder();
    builder.enableComplexMapKeySerialization();

    // Gson g = new Gson();
    Gson g = builder.create();

    String json2 = g.toJson(myjob);

    // To be used from a real console and not Eclipse
    Delete.main(zipArgs[1]);
    String message = JSonRequestor.doRequest(json2, cmURL, cookies);
    @SuppressWarnings("resource")
    Scanner resInt = new Scanner(message).useDelimiter("[^0-9]+");
    int jobID = resInt.nextInt();
    System.out.println("Job ID: " + jobID);

    JOptionPane optionPane = new JOptionPane(message);
    JDialog myDialog = optionPane.createDialog(null, "CMDaemon response: ");
    myDialog.setModal(false);
    myDialog.setVisible(true);

    ArrayList<Object> mylist2 = new ArrayList<Object>();
    mylist2.add("slurm");
    String JobID = Integer.toString(jobID);
    mylist2.add(JobID);
    myjob.setArgs(mylist2);
    myjob.setService("cmjob");
    myjob.setCall("getJob");
    String json3 = g.toJson(myjob);
    System.out.println("JSON Request No. 4 " + json3);

    cmReadFile readfile = new cmReadFile();
    readfile.setService("cmmain");
    readfile.setCall("readFile");
    readfile.setUserName(ruser);

    int fileByteIdx = 1;

    readfile.setPath(rfile + "/" + fileBasename + "/" + fileBasename + ".sum@+" + fileByteIdx);
    String json4 = g.toJson(readfile);

    String monFile = JSonRequestor.doRequest(json4, cmURL, cookies).replaceAll("^\"|\"$", "");
    if (monFile.startsWith("Unable")) {
        monFile = "";
    } else {
        fileByteIdx += countLines(monFile, "\\\\n");
        System.out.println("");
    }

    StringBuffer output = new StringBuffer();
    // Get the correct Line Separator for the OS (CRLF or LF)
    String nl = System.getProperty("line.separator");
    String filename = chooser.getCurrentDirectory().toString() + File.separator + fileBasename + ".sum.txt";
    System.out.println("Local monitoring file: " + filename);

    output.append(monFile.replaceAll("\\\\n", System.getProperty("line.separator")));

    String getJobJSON = JSonRequestor.doRequest(json3, cmURL, cookies);
    jobGet getJobObj = new Gson().fromJson(getJobJSON, jobGet.class);
    System.out.println("Job " + jobID + " status: " + getJobObj.getStatus().toString());

    while (getJobObj.getStatus().toString().equals("RUNNING")
            || getJobObj.getStatus().toString().equals("COMPLETING")) {
        try {

            getJobJSON = JSonRequestor.doRequest(json3, cmURL, cookies);
            getJobObj = new Gson().fromJson(getJobJSON, jobGet.class);
            System.out.println("Job " + jobID + " status: " + getJobObj.getStatus().toString());

            readfile.setPath(rfile + "/" + fileBasename + "/" + fileBasename + ".sum@+" + fileByteIdx);
            json4 = g.toJson(readfile);
            monFile = JSonRequestor.doRequest(json4, cmURL, cookies).replaceAll("^\"|\"$", "");
            if (monFile.startsWith("Unable")) {
                monFile = "";
            } else {

                output.append(monFile.replaceAll("\\\\n", System.getProperty("line.separator")));
                System.out.println("FILE INDEX:" + fileByteIdx);
                fileByteIdx += countLines(monFile, "\\\\n");
            }
            Thread.sleep(Constants.STATUS_CHECK_INTERVAL);
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        }

    }

    Gson gson_nice = new GsonBuilder().setPrettyPrinting().create();
    String json_out = gson_nice.toJson(getJobJSON);
    System.out.println(json_out);
    System.out.println("JSON Request No. 5 " + json4);

    readfile.setPath(rfile + "/" + fileBasename + "/" + fileBasename + ".sum@+" + fileByteIdx);
    json4 = g.toJson(readfile);
    monFile = JSonRequestor.doRequest(json4, cmURL, cookies).replaceAll("^\"|\"$", "");
    if (monFile.startsWith("Unable")) {
        monFile = "";
    } else {

        output.append(monFile.replaceAll("\\\\n", System.getProperty("line.separator")));
        fileByteIdx += countLines(monFile, "\\\\n");
    }
    System.out.println("FILE INDEX:" + fileByteIdx);

    /*
     * System.out.print("Monitoring file: " + monFile.replaceAll("\\n",
     * System.getProperty("line.separator"))); try {
     * FileUtils.writeStringToFile( new
     * File(chooser.getCurrentDirectory().toString() + File.separator +
     * fileBasename + ".sum.txt"), monFile.replaceAll("\\n",
     * System.getProperty("line.separator"))); } catch (IOException e) {
     * 
     * e.printStackTrace(); }
     */

    if (getJobObj.getStatus().toString().equals("COMPLETED")) {
        String[] zipArgs_from = new String[] { chooser.getSelectedFile().toString(),
                chooser.getCurrentDirectory().toString() + File.separator + fileBasename + "_out.zip" };
        String[] myarg_from = new String[] {
                ruser + "@" + rhost + ":" + rfile + "/" + fileBasename + "_out.zip", zipArgs_from[1], rfile,
                fileBasename };
        com.bright.utils.ScpFrom.main(myarg_from);

        JOptionPane optionPaneS = new JOptionPane("Job execution completed without errors!");
        JDialog myDialogS = optionPaneS.createDialog(null, "Job status: ");
        myDialogS.setModal(false);
        myDialogS.setVisible(true);

    } else {
        JOptionPane optionPaneF = new JOptionPane("Job execution FAILED!");
        JDialog myDialogF = optionPaneF.createDialog(null, "Job status: ");
        myDialogF.setModal(false);
        myDialogF.setVisible(true);
    }

    try {
        System.out.println("Local monitoring file: " + filename);

        BufferedWriter out = new BufferedWriter(new FileWriter(filename));
        String outText = output.toString();
        String newString = outText.replace("\\\\n", nl);

        System.out.println("Text: " + outText);
        out.write(newString);

        out.close();
        rmDuplicateLines.main(filename);
    } catch (IOException e) {
        e.printStackTrace();
    }
    doLogout(cmURL, cookies);
    System.exit(0);
}

From source file:com.hp.test.framework.Utlis.java

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

    ArrayList<String> runs_list = new ArrayList<String>();
    String basepath = replacelogs();
    String path = basepath + "ATU Reports\\Results";
    File directory = new File(path);
    File[] subdirs = directory.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
    for (File dir : subdirs) {
        log.info("Directory: " + dir.getName());
        runs_list.add(dir.getName());
    }//  w  w  w. java  2s. co  m

    Map<String, List<String>> runCounts = GetCountsrunsWise(runs_list, path);

    int success = replaceCounts(runCounts, path);

    if (success == 0) {
        File SourceFile = new File(path + "\\lineChart_temp.js");
        File RenameFile = new File(path + "\\lineChart.js");

        renameOriginalFile(SourceFile, RenameFile);

        File SourceFile1 = new File(path + "\\barChart_temp.js");
        File RenameFile1 = new File(path + "\\barChart.js");

        renameOriginalFile(SourceFile1, RenameFile1);

        String Reports_path = basepath + "ATU Reports\\";
        int LatestRun = Utlis.getLastRun(Reports_path);
        Utlis.getpaths(Reports_path + "\\Results\\Run_" + String.valueOf(LatestRun));
        try {
            Utlis.replaceMainTable(false, new File(Reports_path + "index.html"));
            Utlis.replaceMainTable(true, new File(Reports_path + "results\\" + "ConsolidatedPage.html"));
            Utlis.replaceMainTable(true,
                    new File(Reports_path + "Results\\Run_" + String.valueOf(LatestRun) + "CurrentRun.html"));

            fileList.add(
                    new File(Reports_path + "\\Results\\Run_" + String.valueOf(LatestRun) + "CurrentRun.html"));
            for (File f : fileList) {
                Utlis.replaceMainTable(true, f);
            }

        } catch (Exception ex) {
            log.error("Error in updating Report format" + ex.getMessage());
        }
    }

}

From source file:ProducerTool.java

public static void main(String[] args) {
    ArrayList<ProducerTool> threads = new ArrayList();
    ProducerTool producerTool = new ProducerTool();
    String[] unknown = CommandLineSupport.setOptions(producerTool, args);
    if (unknown.length > 0) {
        System.out.println("Unknown options: " + Arrays.toString(unknown));
        System.exit(-1);/*  w w w .  j a  va 2 s  .c o  m*/
    }
    producerTool.showParameters();
    for (int threadCount = 1; threadCount <= parallelThreads; threadCount++) {
        producerTool = new ProducerTool();
        CommandLineSupport.setOptions(producerTool, args);
        producerTool.start();
        threads.add(producerTool);
    }

    while (true) {
        Iterator<ProducerTool> itr = threads.iterator();
        int running = 0;
        while (itr.hasNext()) {
            ProducerTool thread = itr.next();
            if (thread.isAlive()) {
                running++;
            }
        }
        if (running <= 0) {
            System.out.println("All threads completed their work");
            break;
        }
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
        }
    }
}

From source file:Anaphora_Resolution.ParseAllXMLDocuments.java

public static void main(String[] args)
        throws IOException, SAXException, ParserConfigurationException, TransformerException {
    //      File dataFolder = new File("DataToPort");
    //      File[] documents;
    String grammar = "grammar/englishPCFG.ser.gz";
    String[] options = { "-maxLength", "100", "-retainTmpSubcategories" };
    //LexicalizedParser lp =  new LexicalizedParser(grammar, options);
    LexicalizedParser lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz");
    ////w  w  w.j a v  a2 s .co  m
    //      if (dataFolder.isDirectory()) {
    //          documents = dataFolder.listFiles();
    //      } else {
    //          documents = new File[] {dataFolder};
    //      }
    //      int currfile = 0;
    //      int totfiles = documents.length;
    //      for (File paper : documents) {
    //          currfile++;
    //          if (paper.getName().equals(".DS_Store")||paper.getName().equals(".xml")) {
    //              currfile--;
    //              totfiles--;
    //              continue;
    //          }
    //          System.out.println("Working on "+paper.getName()+" (file "+currfile+" out of "+totfiles+").");
    //
    //          DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); // This is for XML
    //          DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    //          Document doc = docBuilder.parse(paper.getAbsolutePath());
    //
    //          NodeList textlist = doc.getElementsByTagName("text");
    //          for(int i=0; i < textlist.getLength(); i++) {
    //              Node currentnode = textlist.item(i);
    //              String wholetext = textlist.item(i).getTextContent();
    String wholetext = "How about other changes for example the ways of doing the work and \n" + "\n"
            + "Iwould say security has , there 's more pressure put on people now than there used to be because obviously , especially after Locherbie , they tightened up on security and there 's a lot more pressure now especially from the ETR and stuff like that \n"
            + "People do n't feel valued any more , they feel  I do n't know I think they feel that nobody cares about them really anyway \n";

    //System.out.println(wholetext);
    //Iterable<List<? extends HasWord>> sentences;

    ArrayList<Tree> parseTrees = new ArrayList<Tree>();
    String asd = "";
    int j = 0;
    StringReader stringreader = new StringReader(wholetext);
    DocumentPreprocessor dp = new DocumentPreprocessor(stringreader);
    @SuppressWarnings("rawtypes")
    ArrayList<List> sentences = preprocess(dp);
    for (List sentence : sentences) {
        parseTrees.add(lp.apply(sentence)); // Parsing a new sentence and adding it to the parsed tree
        ArrayList<Tree> PronounsList = findPronouns(parseTrees.get(j)); // Locating all pronouns to resolve in the sentence
        Tree corefedTree;
        for (Tree pronounTree : PronounsList) {
            parseTrees.set(parseTrees.size() - 1, HobbsResolve(pronounTree, parseTrees)); // Resolving the coref and modifying the tree for each pronoun
        }
        StringWriter strwr = new StringWriter();
        PrintWriter prwr = new PrintWriter(strwr);
        TreePrint tp = new TreePrint("penn");
        tp.printTree(parseTrees.get(j), prwr);
        prwr.flush();
        asd += strwr.toString();
        j++;
    }
    String armando = "";
    for (Tree sentence : parseTrees) {
        for (Tree leaf : Trees.leaves(sentence))
            armando += leaf + " ";
    }
    System.out.println(wholetext);

    System.out.println();
    System.out.println("......");
    System.out.println(armando);
    System.out.println("All done.");
    //              currentnode.setTextContent(asd);
    //          }
    //          TransformerFactory transformerFactory = TransformerFactory.newInstance();
    //          Transformer transformer = transformerFactory.newTransformer();
    //          DOMSource source = new DOMSource(doc);
    //          StreamResult result = new StreamResult(paper);
    //          transformer.transform(source, result);
    //
    //          System.out.println("Done");
    //      }
}

From source file:com.github.xbn.examples.regexutil.non_xbn.BetweenLineMarkersButSkipFirstXmpl.java

public static final void main(String[] as_1RqdTxtFilePath) {
    Iterator<String> lineItr = null;
    try {/*from w ww.  j  av  a 2s  .c  o m*/
        lineItr = FileUtils.lineIterator(new File(as_1RqdTxtFilePath[0])); //Throws npx if null
    } catch (IOException iox) {
        throw new RuntimeException("Attempting to open \"" + as_1RqdTxtFilePath[0] + "\"", iox);
    } catch (RuntimeException rx) {
        throw new RuntimeException("One required parameter: The path to the text file.", rx);
    }

    String LINE_SEP = System.getProperty("line.separator", "\n");

    ArrayList<String> alsItems = new ArrayList<String>();
    boolean bStartMark = false;
    boolean bLine1Skipped = false;
    StringBuilder sdCurrentItem = new StringBuilder();
    while (lineItr.hasNext()) {
        String sLine = lineItr.next().trim();
        if (!bStartMark) {
            if (sLine.startsWith(".START_SEQUENCE")) {
                bStartMark = true;
                continue;
            }
            throw new IllegalStateException("Start mark not found.");
        }
        if (!bLine1Skipped) {
            bLine1Skipped = true;
            continue;
        } else if (!sLine.equals(".END_SEQUENCE")) {
            sdCurrentItem.append(sLine).append(LINE_SEP);
        } else {
            alsItems.add(sdCurrentItem.toString());
            sdCurrentItem.setLength(0);
            bStartMark = false;
            bLine1Skipped = false;
            continue;
        }
    }

    for (String s : alsItems) {
        System.out.println("----------");
        System.out.print(s);
    }
}

From source file:edu.harvard.i2b2.analysis.queryClient.CRCQueryClient.java

public static void main(String[] args) throws Exception {
    PDORequestMessageModel pdoFactory = new PDORequestMessageModel();
    String conceptPath = new String(
            "\\RPDR\\Labtests\\LAB\\(LLB16) Chemistry\\(LLB21) General Chemistries\\CA");

    ArrayList<String> paths = new ArrayList<String>();
    // paths.add(conceptPath);

    conceptPath = new String("\\RPDR\\Labtests\\LAB\\(LLB16) Chemistry\\(LLB21) General Chemistries\\GGT");
    paths.add(conceptPath);

    // conceptPath = new String(
    // "\\RPDR\\Labtests\\LAB\\(LLB16) Chemistry\\(LLB21) General Chemistries\\GGT"
    // );//from  ww w.  j a v  a 2  s.c o m
    // paths.add(conceptPath);
    ArrayList<String> ppaths = new ArrayList<String>();
    conceptPath = new String("\\Providers\\BWH");
    // ppaths.add(conceptPath);

    String xmlStr = pdoFactory.requestXmlMessage(null, "1545", new Integer(1), new Integer(20), false);
    String result = sendPDOQueryRequestREST(xmlStr);

    // FileWriter fwr = new FileWriter("c:\\testdir\\response.txt");
    // fwr.write(result);
    log.debug(result);

    PDOItem set = new PDOItem();
    set.fullPath = "\\RPDR\\Labtests\\LAB\\(LLB16) Chemistry\\(LLB21) General Chemistries\\CA";
    set.hasValueDisplayProperty = true;
    PDOValueData valdp = new PDOValueData();
    valdp.left = 0.0;
    valdp.right = 8.4;
    valdp.color = "red";
    valdp.height = "Very Low";
    set.valDisplayProperties.add(valdp);

    valdp = new PDOValueData();
    valdp.left = 8.4;
    valdp.right = 8.9;
    valdp.color = "gold";
    valdp.height = "Low";
    set.valDisplayProperties.add(valdp);

    valdp = new PDOValueData();
    valdp.left = 8.9;
    valdp.right = 10.0;
    valdp.color = "green";
    valdp.height = "Medium";
    set.valDisplayProperties.add(valdp);

    valdp = new PDOValueData();
    valdp.left = 10.0;
    valdp.right = 10.6;
    valdp.color = "gold";
    valdp.height = "Tall";
    set.valDisplayProperties.add(valdp);

    valdp = new PDOValueData();
    valdp.left = 10.6;
    valdp.right = Integer.MAX_VALUE;
    valdp.color = "red";
    valdp.height = "Very Tall";
    set.valDisplayProperties.add(valdp);
    set.tableType = "fact";

    TimelineRow row = new TimelineRow();
    row.pdoItems.add(set);
    row.displayName = "Calcium (Group:CA)";

    ArrayList<TimelineRow> rows = new ArrayList<TimelineRow>();
    rows.add(row);

    set = new PDOItem();
    set.fullPath = "\\RPDR\\Labtests\\LAB\\(LLB16) Chemistry\\(LLB21) General Chemistries\\GGT";
    set.hasValueDisplayProperty = true;
    valdp = new PDOValueData();
    valdp.left = 0.0;
    valdp.right = 1.0;
    valdp.color = "red";
    valdp.height = "Very Low";
    set.valDisplayProperties.add(valdp);

    valdp = new PDOValueData();
    valdp.left = 1.0;
    valdp.right = 19.0;
    valdp.color = "gold";
    valdp.height = "Low";
    set.valDisplayProperties.add(valdp);

    valdp = new PDOValueData();
    valdp.left = 19.0;
    valdp.right = 34.0;
    valdp.color = "green";
    valdp.height = "Medium";
    set.valDisplayProperties.add(valdp);

    valdp = new PDOValueData();
    valdp.left = 34.0;
    valdp.right = 82.0;
    valdp.color = "gold";
    valdp.height = "Tall";
    set.valDisplayProperties.add(valdp);

    valdp = new PDOValueData();
    valdp.left = 82.0;
    valdp.right = Integer.MAX_VALUE;
    valdp.color = "red";
    valdp.height = "Very Tall";
    set.valDisplayProperties.add(valdp);
    set.tableType = "fact";

    row = new TimelineRow();
    row.pdoItems.add(set);
    row.displayName = "Gamma Glutamyltrans (Group:GGT)";

    rows.add(row);

    // testWritelld(result, rows, true);
    testWriteTableFile(result);
}

From source file:it.unimi.di.big.mg4j.tool.URLMPHVirtualDocumentResolver.java

public static void main(final String[] arg) throws JSAPException, IOException {
    final SimpleJSAP jsap = new SimpleJSAP(URLMPHVirtualDocumentResolver.class.getName(),
            "Builds a URL document resolver from a sequence of URIs, extracted typically using ScanMetadata, using a suitable function. You can specify that the list is sorted, in which case it is possible to generate a resolver that occupies less space.",
            new Parameter[] {
                    new Switch("sorted", 's', "sorted",
                            "URIs are sorted: use a monotone minimal perfect hash function."),
                    new Switch("iso", 'i', "iso",
                            "Use ISO-8859-1 coding internally (i.e., just use the lower eight bits of each character)."),
                    new FlaggedOption("bufferSize", JSAP.INTSIZE_PARSER, "64Ki", JSAP.NOT_REQUIRED, 'b',
                            "buffer-size", "The size of the I/O buffer used to read terms."),
                    new FlaggedOption("class", MG4JClassParser.getParser(), JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED,
                            'c', "class",
                            "A class used to create the function from URIs to their ranks; defaults to it.unimi.dsi.sux4j.mph.MHWCFunction for non-sorted inputs, and to it.unimi.dsi.sux4j.mph.TwoStepsLcpMonotoneMinimalPerfectHashFunction for sorted inputs."),
                    new FlaggedOption("width", JSAP.INTEGER_PARSER, Integer.toString(Long.SIZE),
                            JSAP.NOT_REQUIRED, 'w', "width",
                            "The width, in bits, of the signatures used to sign the function from URIs to their rank."),
                    new FlaggedOption("termFile", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'o',
                            "offline",
                            "Read terms from this file (without loading them into core memory) instead of standard input."),
                    new FlaggedOption("uniqueUris", JSAP.INTSIZE_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED,
                            'U', "unique-uris",
                            "Force URIs to be unique by adding random garbage at the end of duplicates; the argument is an upper bound for the number of URIs that will be read, and will be used to create a Bloom filter."),
                    new UnflaggedOption("resolver", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED,
                            JSAP.NOT_GREEDY, "The filename for the resolver.") });

    JSAPResult jsapResult = jsap.parse(arg);
    if (jsap.messagePrinted())
        return;//from w w w .  j  av a  2  s.c  om

    final int bufferSize = jsapResult.getInt("bufferSize");
    final String resolverName = jsapResult.getString("resolver");
    //final Class<?> tableClass = jsapResult.getClass( "class" );
    final boolean iso = jsapResult.getBoolean("iso");
    String termFile = jsapResult.getString("termFile");

    BloomFilter<Void> filter = null;
    final boolean uniqueURIs = jsapResult.userSpecified("uniqueUris");
    if (uniqueURIs)
        filter = BloomFilter.create(jsapResult.getInt("uniqueUris"));

    final Collection<? extends CharSequence> collection;
    if (termFile == null) {
        ArrayList<MutableString> termList = new ArrayList<MutableString>();
        final ProgressLogger pl = new ProgressLogger();
        pl.itemsName = "URIs";
        final LineIterator termIterator = new LineIterator(
                new FastBufferedReader(new InputStreamReader(System.in, "UTF-8"), bufferSize), pl);

        pl.start("Reading URIs...");
        MutableString uri;
        while (termIterator.hasNext()) {
            uri = termIterator.next();
            if (uniqueURIs)
                makeUnique(filter, uri);
            termList.add(uri.copy());
        }
        pl.done();

        collection = termList;
    } else {
        if (uniqueURIs) {
            // Create temporary file with unique URIs
            final ProgressLogger pl = new ProgressLogger();
            pl.itemsName = "URIs";
            pl.start("Copying URIs...");
            final LineIterator termIterator = new LineIterator(
                    new FastBufferedReader(new InputStreamReader(new FileInputStream(termFile)), bufferSize),
                    pl);
            File temp = File.createTempFile(URLMPHVirtualDocumentResolver.class.getName(), ".uniqueuris");
            temp.deleteOnExit();
            termFile = temp.toString();
            final FastBufferedOutputStream outputStream = new FastBufferedOutputStream(
                    new FileOutputStream(termFile), bufferSize);
            MutableString uri;
            while (termIterator.hasNext()) {
                uri = termIterator.next();
                makeUnique(filter, uri);
                uri.writeUTF8(outputStream);
                outputStream.write('\n');
            }
            pl.done();
            outputStream.close();
        }
        collection = new FileLinesCollection(termFile, "UTF-8");
    }
    LOGGER.debug("Building function...");
    final int width = jsapResult.getInt("width");
    if (jsapResult.getBoolean("sorted"))
        BinIO.storeObject(
                new URLMPHVirtualDocumentResolver(
                        new ShiftAddXorSignedStringMap(collection.iterator(),
                                new TwoStepsLcpMonotoneMinimalPerfectHashFunction<CharSequence>(collection,
                                        iso ? TransformationStrategies.prefixFreeIso()
                                                : TransformationStrategies.prefixFreeUtf16()),
                                width)),
                resolverName);
    else
        BinIO.storeObject(
                new URLMPHVirtualDocumentResolver(new ShiftAddXorSignedStringMap(collection.iterator(),
                        new MWHCFunction<CharSequence>(collection,
                                iso ? TransformationStrategies.iso() : TransformationStrategies.utf16()),
                        width)),
                resolverName);
    LOGGER.debug(" done.");
}

From source file:mmllabvsdextractfeature.MMllabVSDExtractFeature.java

/**
 * @param args the command line arguments
 *//*from   w ww.j a v a2 s. co m*/
public static void main(String[] args) throws IOException {
    // TODO code application logic here
    MMllabVSDExtractFeature hello = new MMllabVSDExtractFeature();
    FileStructer metdata = new FileStructer();
    //Utility utilityClassIni = new Utility();
    FrameStructer frameStructer = new FrameStructer();

    /*
    Flow :
            
    1. Read  metdata file
    2. Untar folder:
        -1 Shot content 25 frame
        -1 folder 50 shot
    Process with 1 shot:
        - Resize All image 1 shot --> delete orginal.
        - Extract feature 25 frame
        - Pooling Max and aveg.
        - Delete Image, feature
        - zip file Feature 
    3. Delete File.
                
    */

    // Load metadata File
    String dir = "/media/data1";
    String metadataFileDir = "/media/data1/metdata/devel2011-new.lst";
    ArrayList<FileStructer> listFileFromMetadata = metdata.readMetadata(metadataFileDir);

    //        String test = utilityClass.readTextFile("C:\\Users\\tiendv\\Downloads\\VSD_devel2011_1.shot_1.RKF_1.Frame_1.txt");
    //        ArrayList <String> testFeatureSave = utilityClass.SplitUsingTokenizerWithLineArrayList(test, " ");
    //        utilityClass.writeToFile("C:\\Users\\tiendv\\Downloads\\VSD_devel2011_1.shot_1.txt", testFeatureSave);
    //        System.out.println(test);

    for (int i = 0; i < listFileFromMetadata.size(); i++) {

        Utility utilityClass = new Utility();
        //Un zip file
        String folderName = listFileFromMetadata.get(i).getWholeFolderName();
        String nameZipFile = dir + "/" + folderName + "/" + listFileFromMetadata.get(i).getNameZipFileName()
                + ".tar";
        nameZipFile = nameZipFile.replaceAll("\\s", "");
        String outPutFolder = dir + "/" + folderName + "/" + listFileFromMetadata.get(i).getNameZipFileName();
        outPutFolder = outPutFolder.replaceAll("\\s", "");
        utilityClass.unTarFolder(UNTARSHFILE, nameZipFile, outPutFolder + "_");

        // Resize all image in folder has been unzip
        utilityClass.createFolder(CREADFOLDER, outPutFolder);
        utilityClass.resizeWholeFolder(outPutFolder + "_", outPutFolder, resizeWidth, resizeHeight);
        utilityClass.deleteWholeFolder(DELETEFOLDER, outPutFolder + "_");
        // Read all file from Folder has been unzip

        ArrayList<FrameStructer> allFrameInZipFolder = new ArrayList<>();
        allFrameInZipFolder = frameStructer.getListFileInZipFolder(outPutFolder);
        System.out.println(allFrameInZipFolder.size());
        // sort with shot ID
        Collections.sort(allFrameInZipFolder, FrameStructer.frameIDNo);

        // Loop with 1 shot
        int indexFrame = 0;
        for (int n = 0; n < allFrameInZipFolder.size() / 25; n++) {
            // Process with 1 
            ArrayList<String> nameAllFrameOneShot = new ArrayList<>();
            String shotAndFolderName = new String();
            for (; indexFrame < Math.min((n + 1) * 25, allFrameInZipFolder.size()); indexFrame++) {
                String imageForExtract = outPutFolder + "/" + allFrameInZipFolder.get(indexFrame).toFullName()
                        + ".jpg";
                shotAndFolderName = allFrameInZipFolder.get(indexFrame).shotName();
                String resultNameAfterExtract = outPutFolder + "/"
                        + allFrameInZipFolder.get(indexFrame).toFullName() + ".txt";
                nameAllFrameOneShot.add(resultNameAfterExtract);
                // extract and Delete image file --> ouput image'feature
                utilityClass.excuteFeatureExtractionAnImage(EXTRACTFEATUREANDDELETESOURCEIMAGESHFILE, "0",
                        CUDAOVERFEATPATH, imageForExtract, resultNameAfterExtract);
            }
            // Pooling 

            //                    DenseMatrix64F resultMaTrixFeatureOneShot = utilityClass.buidEJMLMatrixFeatureOneShot(nameAllFrameOneShot);
            //                    utilityClass.savePoolingFeatureOneShotWithEJMLFromMatrix(resultMaTrixFeatureOneShot,outPutFolder,shotAndFolderName);

            utilityClass.buidPoolingFileWithOutMatrixFeatureOneShot(nameAllFrameOneShot, outPutFolder,
                    shotAndFolderName);
            // Save A file 

            for (int frameCount = 0; frameCount < nameAllFrameOneShot.size(); frameCount++) { // Delete feature extract file
                utilityClass.deletefile(DELETEFILE, nameAllFrameOneShot.get(frameCount));
            }
            // Release one shot data
            nameAllFrameOneShot.clear();
            System.out.print("The end of one's shot" + "\n" + n);
        }
        // Delete zip file
        utilityClass.deletefile(DELETEFILE, nameZipFile);

        // Zip Whole Folder

        /**
         * Extract 1 shot
         * Resize 25 frame with the same shotid --> delete orgra.
         * Extract 25 frame --> feature file --->delete 
         * 
         */

    }

}

From source file:org.apache.s4.client.Adapter.java

@SuppressWarnings("static-access")
public static void main(String args[]) throws IOException, InterruptedException {

    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c"));

    options.addOption(/*www.ja  v a2 s  . c  om*/
            OptionBuilder.withArgName("instanceid").hasArg().withDescription("instance id").create("i"));

    options.addOption(
            OptionBuilder.withArgName("configtype").hasArg().withDescription("configuration type").create("t"));

    options.addOption(OptionBuilder.withArgName("userconfig").hasArg()
            .withDescription("user-defined legacy data adapter configuration file").create("d"));

    CommandLineParser parser = new GnuParser();
    CommandLine commandLine = null;

    try {
        commandLine = parser.parse(options, args);
    } catch (ParseException pe) {
        System.err.println(pe.getLocalizedMessage());
        System.exit(1);
    }

    int instanceId = -1;
    if (commandLine.hasOption("i")) {
        String instanceIdStr = commandLine.getOptionValue("i");
        try {
            instanceId = Integer.parseInt(instanceIdStr);
        } catch (NumberFormatException nfe) {
            System.err.println("Bad instance id: %s" + instanceIdStr);
            System.exit(1);
        }
    }

    if (commandLine.hasOption("c")) {
        coreHome = commandLine.getOptionValue("c");
    }

    String configType = "typical";
    if (commandLine.hasOption("t")) {
        configType = commandLine.getOptionValue("t");
    }

    String userConfigFilename = null;
    if (commandLine.hasOption("d")) {
        userConfigFilename = commandLine.getOptionValue("d");
    }

    File userConfigFile = new File(userConfigFilename);
    if (!userConfigFile.isFile()) {
        System.err.println("Bad user configuration file: " + userConfigFilename);
        System.exit(1);
    }

    File coreHomeFile = new File(coreHome);
    if (!coreHomeFile.isDirectory()) {
        System.err.println("Bad core home: " + coreHome);
        System.exit(1);
    }

    if (instanceId > -1) {
        System.setProperty("instanceId", "" + instanceId);
    } else {
        System.setProperty("instanceId", "" + S4Util.getPID());
    }

    String configBase = coreHome + File.separatorChar + "conf" + File.separatorChar + configType;
    String configPath = configBase + File.separatorChar + "client-adapter-conf.xml";
    File configFile = new File(configPath);
    if (!configFile.exists()) {
        System.err.printf("adapter config file %s does not exist\n", configPath);
        System.exit(1);
    }

    // load adapter config xml
    ApplicationContext coreContext;
    coreContext = new FileSystemXmlApplicationContext("file:" + configPath);
    ApplicationContext context = coreContext;

    Adapter adapter = (Adapter) context.getBean("client_adapter");

    ApplicationContext appContext = new FileSystemXmlApplicationContext(
            new String[] { "file:" + userConfigFilename }, context);

    Map<?, ?> inputStubBeanMap = appContext.getBeansOfType(InputStub.class);
    Map<?, ?> outputStubBeanMap = appContext.getBeansOfType(OutputStub.class);

    if (inputStubBeanMap.size() == 0 && outputStubBeanMap.size() == 0) {
        System.err.println("No user-defined input/output stub beans");
        System.exit(1);
    }

    ArrayList<InputStub> inputStubs = new ArrayList<InputStub>(inputStubBeanMap.size());
    ArrayList<OutputStub> outputStubs = new ArrayList<OutputStub>(outputStubBeanMap.size());

    // add all input stubs
    for (Map.Entry<?, ?> e : inputStubBeanMap.entrySet()) {
        String beanName = (String) e.getKey();
        System.out.println("Adding InputStub " + beanName);
        inputStubs.add((InputStub) e.getValue());
    }

    // add all output stubs
    for (Map.Entry<?, ?> e : outputStubBeanMap.entrySet()) {
        String beanName = (String) e.getKey();
        System.out.println("Adding OutputStub " + beanName);
        outputStubs.add((OutputStub) e.getValue());
    }

    adapter.setInputStubs(inputStubs);
    adapter.setOutputStubs(outputStubs);

}

From source file:edu.harvard.i2b2.explorer.serviceClient.PDOQueryClient.java

public static void main(String[] args) throws Exception {
    PDORequestMessageModel pdoFactory = new PDORequestMessageModel();
    String conceptPath = new String(
            "\\RPDR\\Labtests\\LAB\\(LLB16) Chemistry\\(LLB21) General Chemistries\\CA");

    ArrayList<String> paths = new ArrayList<String>();
    // paths.add(conceptPath);

    conceptPath = new String("\\RPDR\\Labtests\\LAB\\(LLB16) Chemistry\\(LLB21) General Chemistries\\GGT");
    paths.add(conceptPath);

    // conceptPath = new
    // String("\\RPDR\\Labtests\\LAB\\(LLB16) Chemistry\\(LLB21) General Chemistries\\GGT");
    // paths.add(conceptPath);
    ArrayList<String> ppaths = new ArrayList<String>();
    conceptPath = new String("\\Providers\\BWH");
    // ppaths.add(conceptPath);

    String xmlStr = pdoFactory.requestXmlMessage(null, "1545", new Integer(1), new Integer(20), false, "");
    String result = sendPDOQueryRequestREST(xmlStr);

    // FileWriter fwr = new FileWriter("c:\\testdir\\response.txt");
    // fwr.write(result);
    log.debug(result);/* ww  w .  j  a  va  2s.c o m*/

    PDOItem set = new PDOItem();
    set.fullPath = "\\RPDR\\Labtests\\LAB\\(LLB16) Chemistry\\(LLB21) General Chemistries\\CA";
    set.hasValueDisplayProperty = true;
    PDOValueModel valdp = new PDOValueModel();
    valdp.left = 0.0;
    valdp.right = 8.4;
    valdp.color = "red";
    valdp.height = "Very Low";
    set.valDisplayProperties.add(valdp);

    valdp = new PDOValueModel();
    valdp.left = 8.4;
    valdp.right = 8.9;
    valdp.color = "gold";
    valdp.height = "Low";
    set.valDisplayProperties.add(valdp);

    valdp = new PDOValueModel();
    valdp.left = 8.9;
    valdp.right = 10.0;
    valdp.color = "green";
    valdp.height = "Medium";
    set.valDisplayProperties.add(valdp);

    valdp = new PDOValueModel();
    valdp.left = 10.0;
    valdp.right = 10.6;
    valdp.color = "gold";
    valdp.height = "Tall";
    set.valDisplayProperties.add(valdp);

    valdp = new PDOValueModel();
    valdp.left = 10.6;
    valdp.right = Integer.MAX_VALUE;
    valdp.color = "red";
    valdp.height = "Very Tall";
    set.valDisplayProperties.add(valdp);
    set.tableType = "fact";

    TimelineRow row = new TimelineRow();
    row.pdoItems.add(set);
    row.displayName = "Calcium (Group:CA)";

    ArrayList<TimelineRow> rows = new ArrayList<TimelineRow>();
    rows.add(row);

    set = new PDOItem();
    set.fullPath = "\\RPDR\\Labtests\\LAB\\(LLB16) Chemistry\\(LLB21) General Chemistries\\GGT";
    set.hasValueDisplayProperty = true;
    valdp = new PDOValueModel();
    valdp.left = 0.0;
    valdp.right = 1.0;
    valdp.color = "red";
    valdp.height = "Very Low";
    set.valDisplayProperties.add(valdp);

    valdp = new PDOValueModel();
    valdp.left = 1.0;
    valdp.right = 19.0;
    valdp.color = "gold";
    valdp.height = "Low";
    set.valDisplayProperties.add(valdp);

    valdp = new PDOValueModel();
    valdp.left = 19.0;
    valdp.right = 34.0;
    valdp.color = "green";
    valdp.height = "Medium";
    set.valDisplayProperties.add(valdp);

    valdp = new PDOValueModel();
    valdp.left = 34.0;
    valdp.right = 82.0;
    valdp.color = "gold";
    valdp.height = "Tall";
    set.valDisplayProperties.add(valdp);

    valdp = new PDOValueModel();
    valdp.left = 82.0;
    valdp.right = Integer.MAX_VALUE;
    valdp.color = "red";
    valdp.height = "Very Tall";
    set.valDisplayProperties.add(valdp);
    set.tableType = "fact";

    row = new TimelineRow();
    row.pdoItems.add(set);
    row.displayName = "Gamma Glutamyltrans (Group:GGT)";

    rows.add(row);

    // testWritelld(result, rows, true);
    testWriteTableFile(result);
}