Example usage for java.util ArrayList ArrayList

List of usage examples for java.util ArrayList ArrayList

Introduction

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

Prototype

public ArrayList() 

Source Link

Document

Constructs an empty list with an initial capacity of ten.

Usage

From source file:com.foxykeep.parcelablecodegenerator.Main.java

public static void main(String[] args) {

    File fileInputDir = new File("input");
    if (!fileInputDir.exists() || !fileInputDir.isDirectory()) {
        return;/*  w  w w .java2s.co m*/
    }

    ArrayList<FileInfo> fileInfoList = new ArrayList<FileInfo>();
    findJsonFiles(fileInputDir, null, fileInfoList);

    StringBuilder sb = new StringBuilder();

    // For each file in the input folder
    for (FileInfo fileInfo : fileInfoList) {
        String fileName = fileInfo.file.getName();
        System.out.println("Generating code for " + fileName);

        char[] buffer = new char[2048];
        sb.setLength(0);
        Reader in;
        try {
            in = new InputStreamReader(new FileInputStream(fileInfo.file), "UTF-8");
            int read;
            do {
                read = in.read(buffer, 0, buffer.length);
                if (read != -1) {
                    sb.append(buffer, 0, read);
                }
            } while (read >= 0);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return;
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }

        String content = sb.toString();
        if (content.length() == 0) {
            System.out.println("file is empty.");
            return;
        }

        try {
            JSONObject root = new JSONObject(content);

            // Classes generation
            String classPackage, className, superClassPackage, superClassName;
            boolean isSuperClassParcelable, hasSubClasses, isAbstract;

            classPackage = root.getString("package");
            className = root.getString("name");
            superClassPackage = JsonUtils.getStringFixFalseNull(root, "superClassPackage");
            superClassName = JsonUtils.getStringFixFalseNull(root, "superClassName");
            isSuperClassParcelable = root.optBoolean("isSuperClassParcelable");
            hasSubClasses = root.optBoolean("hasSubClasses");
            if (hasSubClasses) {
                isAbstract = root.optBoolean("isAbstract");
            } else {
                isAbstract = false;
            }

            JSONArray fieldJsonArray = root.optJSONArray("fields");
            ArrayList<FieldData> fieldDataList;
            if (fieldJsonArray != null) {
                fieldDataList = FieldData.getFieldsData(fieldJsonArray);
            } else {
                fieldDataList = new ArrayList<FieldData>();
            }

            // Parcelable generation
            ParcelableGenerator.generate(fileInfo.dirPath, classPackage, className, superClassPackage,
                    superClassName, isSuperClassParcelable, hasSubClasses, isAbstract, fieldDataList);
        } catch (JSONException e) {
            e.printStackTrace();
            return;
        }
    }

}

From source file:it.avalz.opendaylight.controller.examples.JsonParser.java

public static void main(String[] args) {

    String s = "{\"ids\":[\"00:00:00:00:00:00:00:01\", \"00:00:00:00:00:00:00:02\"], \"width\":200, \"height\":100}";

    JSONObject json = null;//w ww  .  ja  v a 2 s  .co  m
    try {
        json = (JSONObject) new JSONParser().parse(s);
    } catch (ParseException ex) {
        ex.printStackTrace();
    }

    System.out.println(json.get("ids"));

    JSONArray array = (JSONArray) json.get("ids");
    System.out.println(array.get(0));
    System.out.println(json.get("width"));
    System.out.println(json.get("height"));

    List<String> l = new ArrayList<String>();

    l.add("\"DROP\"");
    l.add("\"OUTPUT=2\"");
    System.out.println(l);
}

From source file:it.units.malelab.sse.Main.java

public static void main(String[] args) throws IOException {
    Random random = new Random(1);
    VirtualMachine vm = new VirtualMachine(4, 4, 400);
    List<Map<Boolean, List<String>>> datasets = new ArrayList<>();
    datasets.add(Util.loadStrings("/home/eric/Documenti/esperimenti/datasets/Bills-Date.txt", random));
    datasets.add(Util.loadStrings("/home/eric/Documenti/esperimenti/datasets/Log-IP.txt", random));
    datasets.add(Util.loadStrings("/home/eric/Documenti/esperimenti/datasets/Twitter-URL.txt", random));

    Evaluator evaluator = new Evaluator(vm, datasets, 1, 10);

    MyGeneticAlgorithm ga = new MyGeneticAlgorithm(new OnePointCrossover<Integer>(), 0.2, new BinaryMutation(),
            0.6, new TournamentSelection(10), evaluator);
    MyGeneticAlgorithm.setRandomGenerator(new JDKRandomGenerator(1));

    List<Chromosome> chromosomes = new ArrayList<>();
    for (int i = 0; i < 2000; i++) {
        chromosomes.add(new OperationsChromosome(evaluator));
    }//from  www.  jav a2 s. com
    Population population = new ElitisticListPopulation(chromosomes, chromosomes.size(), 0.99);
    Population finalPopulation = ga.evolve(population, new FixedGenerationCount(10000));
    List<Operation> operations = ((OperationsChromosome) finalPopulation.getFittestChromosome())
            .getOperations();
    for (int i = 0; i < operations.size(); i++) {
        System.out.printf("%4d: %s\n", i, operations.get(i));
    }

}

From source file:com.mirth.connect.plugins.datatypes.ncpdp.test.NCPDPTest.java

public static void main(String[] args) throws Exception {
    String testMessage = "";
    ArrayList<String> testFiles = new ArrayList<String>();
    testFiles.add("C:\\NCPDP_51_B1_Request.txt");
    testFiles.add("C:\\NCPDP_51_B1_Request_v2.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v4.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v5.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v6.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v7.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v8.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v9.txt");
    testFiles.add("C:\\NCPDP_51_B2_Request.txt");
    testFiles.add("C:\\NCPDP_51_B2_Request_v2.txt");
    testFiles.add("C:\\NCPDP_51_B2_Response.txt");
    testFiles.add("C:\\NCPDP_51_B2_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_B2_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_B3_Request.txt");
    testFiles.add("C:\\NCPDP_51_B3_Response.txt");
    testFiles.add("C:\\NCPDP_51_B3_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_B3_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_E1_Request.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v4.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v5.txt");
    testFiles.add("C:\\NCPDP_51_N1_Request.txt");
    testFiles.add("C:\\NCPDP_51_N2_Request.txt");
    testFiles.add("C:\\NCPDP_51_P1_Request.txt");
    testFiles.add("C:\\NCPDP_51_P1_Response.txt");
    testFiles.add("C:\\NCPDP_51_P1_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_P1_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_P2_Request.txt");
    testFiles.add("C:\\NCPDP_51_P2_Response.txt");
    testFiles.add("C:\\NCPDP_51_P3_Request.txt");
    testFiles.add("C:\\NCPDP_51_P3_Response.txt");
    testFiles.add("C:\\NCPDP_51_P3_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_P4_Request.txt");
    testFiles.add("C:\\NCPDP_51_P4_Response.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_1.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_2.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_3.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_4.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_5.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_6.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_7.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_8.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_9.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_10.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_11.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_12.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_13.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_14.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_15.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_16.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_17.txt");

    for (String testFile : testFiles) {
        testMessage = new String(FileUtils.readFileToByteArray(new File(testFile)));
        System.out.println("Processing test file:" + testFile);

        try {/*from  w  w  w . j a  v a 2 s. c om*/
            long totalExecutionTime = 0;
            int iterations = 1;
            for (int i = 0; i < iterations; i++) {
                totalExecutionTime += runTest(testMessage);
            }

            //System.out.println("Execution time average: " + totalExecutionTime/iterations + " ms");
        }
        // System.out.println(new X12Serializer().serialize("SEG*1*2**4*5"));
        catch (SAXException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:de.tu.darmstadt.lt.ner.preprocessing.SentenceToCRFWriter.java

public static void main(String[] args) throws UIMAException, IllegalArgumentException, IOException {
    LineIterator sentIt = FileUtils.lineIterator(new File(args[0]), "UTF-8");
    List<String> sentences = new ArrayList<String>();
    StringBuilder sb = new StringBuilder();
    int index = 0;
    while (sentIt.hasNext()) {
        String line = sentIt.nextLine().toString().trim().split("\t")[1];
        if (line.equals("")) {
            continue;
        }/*w ww  .j  a  v  a  2s  .  c  o  m*/
        sentences.add(line);
    }
    GermaNERMain.sentenceToCRFFormat(sentences, args[1], "de");
}

From source file:AdderTask.java

public static void main(String[] args) {
    final int PHASE_COUNT = 2;
    Phaser phaser = new Phaser() {
        public boolean onAdvance(int phase, int parties) {
            System.out.println(/*w w  w.j a v  a  2  s . c  om*/
                    "Phase:" + phase + ", Parties:" + parties + ",  Arrived:" + this.getArrivedParties());
            boolean terminatePhaser = false;
            if (phase >= PHASE_COUNT - 1 || parties == 0) {
                terminatePhaser = true;
            }

            return terminatePhaser;
        }
    };
    List<Integer> list = Collections.synchronizedList(new ArrayList<Integer>());
    int ADDER_COUNT = 3;
    phaser.bulkRegister(ADDER_COUNT + 1);
    for (int i = 1; i <= ADDER_COUNT; i++) {
        String taskName = "Task  #" + i;
        AdderTask task = new AdderTask(taskName, phaser, list);
        task.start();
    }
    while (!phaser.isTerminated()) {
        phaser.arriveAndAwaitAdvance();
    }
    int sum = 0;
    for (Integer num : list) {
        sum = sum + num;
    }
    System.out.println("Sum = " + sum);
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

    KeyPair pair = generateRSAKeyPair();

    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    bOut.write(generateV1Certificate(pair).getEncoded());
    bOut.close();//from ww w .  j  ava2s .  c  om

    InputStream in = new ByteArrayInputStream(bOut.toByteArray());

    CertificateFactory fact = CertificateFactory.getInstance("X.509", "BC");

    X509Certificate x509Cert;
    Collection collection = new ArrayList();

    while ((x509Cert = (X509Certificate) fact.generateCertificate(in)) != null) {
        collection.add(x509Cert);
    }

    Iterator it = collection.iterator();
    while (it.hasNext()) {
        System.out.println("version: " + ((X509Certificate) it.next()).getVersion());
    }
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    writer.setPdfVersion(PdfWriter.VERSION_1_5);
    document.open();//ww w. j  a  v a 2  s.com
    PdfLayer a1 = new PdfLayer("answer 1", writer);
    a1.setOn(false);

    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
    PdfContentByte cb = writer.getDirectContent();
    cb.beginText();
    cb.setTextMatrix(50, 790);
    cb.setLeading(24);
    cb.setFontAndSize(bf, 18);
    cb.newlineShowText("This is a question?");
    cb.beginLayer(a1);
    cb.setRGBColorFill(0xFF, 0x00, 0x00);
    cb.newlineShowText("This is the answer");
    cb.resetRGBColorFill();
    cb.endLayer();
    cb.endText();

    ArrayList stateOn = new ArrayList();
    stateOn.add("ON");
    stateOn.add(a1);
    PdfAction actionOn = PdfAction.setOCGstate(stateOn, true);
    ArrayList stateOff = new ArrayList();
    stateOff.add("OFF");
    stateOff.add(a1);
    PdfAction actionOff = PdfAction.setOCGstate(stateOff, true);
    ArrayList stateToggle = new ArrayList();
    stateToggle.add("Toggle");
    stateToggle.add(a1);
    PdfAction actionToggle = PdfAction.setOCGstate(stateToggle, true);
    Phrase p = new Phrase("Change the state of the answers:");
    Chunk on = new Chunk(" on ").setAction(actionOn);
    p.add(on);
    Chunk off = new Chunk("/ off ").setAction(actionOff);
    p.add(off);
    Chunk toggle = new Chunk("/ toggle").setAction(actionToggle);
    p.add(toggle);
    document.add(p);
    document.close();
}

From source file:carolina.pegaLatLong.Teste.java

public static void main(String[] args) throws MalformedURLException, IOException, ParseException {
    List<InformacoesTxt> listaInfo = new ArrayList<InformacoesTxt>();
    //        String json = "";
    //        InputStream in = null;
    //      /*from   ww  w .  ja  va 2 s.c  o  m*/
    //
    //        URL ul;
    //        
    //            ul = new URL("https://maps.googleapis.com/maps/api/geocode/json?address=10115,germany");
    //            HttpURLConnection conn = (HttpURLConnection) ul.openConnection();
    //           // conn.setRequestMethod("GET");
    //            //conn.setRequestProperty("Accept", "application/json");
    //            BufferedReader bf = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    //            String pega = "";
    //            String result = "";
    //            while((pega = bf.readLine()) != null){
    //                result+=pega;
    //            }
    //            System.err.println(result);
    //            
    //            org.json.simple.parser.JSONParser parser = new org.json.simple.parser.JSONParser();
    //            Object obj = parser.parse(result);
    //            
    //            JSONObject tudo = (JSONObject) obj; 
    //            
    //            JSONArray jsonObject1 = (JSONArray) tudo.get("results");
    //            JSONObject jsonObject2 = (JSONObject)jsonObject1.get(0);
    //            JSONObject jsonObject3 = (JSONObject)jsonObject2.get("geometry");
    //            JSONObject location = (JSONObject) jsonObject3.get("location");
    //
    //            System.out.println( "Lat = "+location.get("lat"));
    //            System.out.println( "Lng = "+location.get("lng"));
    //
    //        String caminho = "externfiles\\emitente3.txt";
    //        FileInputStream file = new FileInputStream(caminho);
    //        InputStreamReader input = new InputStreamReader(file, java.nio.charset.StandardCharsets.ISO_8859_1);
    //        BufferedReader br = new BufferedReader(input);
    //        String pega = "";
    //        String mostra = "";
    //        System.err.println(mostra);
    //        int cont = 0;
    //        // Nome do Emitente,CNPJ,IE,Endereo,Bairro,CEP,Cidade,UF,Pais,
    //        while ((pega = br.readLine()) != null) {
    //            if (cont > 0) {
    //                String neew = LatLong.removerAcentos(pega.toLowerCase());
    //                String vet[] = neew.split(";");
    //                InformacoesTxt info = new InformacoesTxt();
    //                info.setEndereco(vet[0]);
    //                info.setCep(vet[2]);
    //                info.setBairro(vet[1]);
    //                info.setCidade(vet[3]);
    //                info.setUf(vet[4]);
    //                info.setPais(vet[5]);
    //                listaInfo.add(info);
    //            }
    //            cont++;
    //        }
    //
    //        //System.err.println("Tudo: " + cont);
    //        for (InformacoesTxt informacoes : listaInfo) {
    //
    //            System.out.println("Endereo: " + informacoes.getEndereco());
    //            System.out.println("Bairro: " + informacoes.getBairro());
    //            System.out.println("CEP: " + informacoes.getCep());
    //            System.out.println("Cidade: " + informacoes.getCidade());
    //            System.out.println("UF: " + informacoes.getUf());
    //            System.out.println("Pais: " + informacoes.getPais() + "\n");
    //
    //        }

    //        JPanel painel = new JPanel();
    //        JRadioButton btnEncontrados = new JRadioButton("Encontrados");
    //        JRadioButton btnNaoEncontrados = new JRadioButton("No encontrados");
    //        JRadioButton btnEncontradosMais = new JRadioButton("Mais de um encontrados");
    //        JRadioButton btnTudo = new JRadioButton("Tudo");
    //        ButtonGroup btnGroup = new ButtonGroup();
    //        btnGroup.add(btnTudo);
    //        btnGroup.add(btnEncontrados);
    //        btnGroup.add(btnNaoEncontrados);
    //        btnGroup.add(btnEncontradosMais);
    //
    //        painel.add(btnTudo);
    //        painel.add(btnEncontrados);
    //        painel.add(btnNaoEncontrados);
    //        painel.add(btnEncontradosMais);
    //        JOptionPane.showMessageDialog(null, painel);

    int a = 2;
    int b = 3;
    String teste = (a > b) ? "A maior que b" : "B maior que A";
    JOptionPane.showMessageDialog(null, teste);
}

From source file:com.vethrfolnir.TestJsonAfterUnmarshal.java

public static void main(String[] args) throws Exception {
    ArrayList<TestThing> tsts = new ArrayList<>();

    for (int i = 0; i < 21; i++) {

        final int nr = i;
        tsts.add(new TestThing() {
            {//from   www .ja v a2s.  c o m
                id = 1028 * nr + 256;
                name = "Name-" + nr;
            }
        });
    }

    ObjectMapper mp = new ObjectMapper();
    mp.setVisibilityChecker(mp.getDeserializationConfig().getDefaultVisibilityChecker()
            .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)
            .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
            .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withSetterVisibility(JsonAutoDetect.Visibility.NONE));

    mp.configure(SerializationFeature.INDENT_OUTPUT, true);

    ByteArrayOutputStream br = new ByteArrayOutputStream();
    mp.writeValue(System.err, tsts);
    mp.writeValue(br, tsts);

    ByteArrayInputStream in = new ByteArrayInputStream(br.toByteArray());
    tsts = mp.readValue(in, new TypeReference<ArrayList<TestThing>>() {
    });

    System.err.println();
    System.out.println("Got: " + tsts);
}