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:org.deeplearning4j.examples.dataexamples.CSVPlotter.java

public static void main(String[] args) throws IOException, InterruptedException {
    String filename = new ClassPathResource("/DataExamples/CSVPlotData.csv").getFile().getPath();
    DataSet ds = readCSVDataset(filename);

    ArrayList<DataSet> DataSetList = new ArrayList<>();
    DataSetList.add(ds);

    plotDataset(DataSetList); //Plot the data, make sure we have the right data.

    MultiLayerNetwork net = fitStraightline(ds);

    // Get the min and max x values, using Nd4j
    NormalizerMinMaxScaler preProcessor = new NormalizerMinMaxScaler();
    preProcessor.fit(ds);/*w w  w.j  a va2 s.  c  o  m*/
    int nSamples = 50;
    INDArray x = Nd4j.linspace(preProcessor.getMin().getInt(0), preProcessor.getMax().getInt(0), nSamples)
            .reshape(nSamples, 1);
    INDArray y = net.output(x);
    DataSet modeloutput = new DataSet(x, y);
    DataSetList.add(modeloutput);

    plotDataset(DataSetList); //Plot data and model fit.
}

From source file:contractEditor.contractHOST1.java

public static void main(String[] args) {

    JSONObject obj = new JSONObject();
    obj.put("name", "HOST1");
    obj.put("context", "VM-deployment");

    //obj.put("Context", new Integer);

    HashMap serviceDescription = new HashMap();
    serviceDescription.put("location", "France");
    serviceDescription.put("certificate", "true");
    serviceDescription.put("volume", "100_GB");
    serviceDescription.put("price", "6_euro");

    obj.put("serviceDescription", serviceDescription);

    HashMap gauranteeTerm = new HashMap();
    gauranteeTerm.put("availability", "more_98_percentage");
    obj.put("gauranteeTerm", gauranteeTerm);

    //Constraint1

    HashMap host_rule1 = new HashMap();
    HashMap VM_rule1 = new HashMap();
    host_rule1.put("ID", "HOST1");
    VM_rule1.put("purpose", "test");

    ArrayList rule1 = new ArrayList();
    rule1.add("prohibition");
    rule1.add(host_rule1);// ww  w  .  j  a v  a  2  s . c  o  m
    rule1.add(VM_rule1);

    ArrayList policyInConstraint1 = new ArrayList();
    policyInConstraint1.add(rule1);

    ArrayList creationConstraint1 = new ArrayList();
    creationConstraint1.add("other");
    creationConstraint1.add("true");
    creationConstraint1.add("true");
    creationConstraint1.add(policyInConstraint1);

    ArrayList totalConstraint = new ArrayList();
    totalConstraint.add(creationConstraint1);

    obj.put("creationConstraint", totalConstraint);

    try {

        FileWriter file = new FileWriter("confSP" + File.separator + "Host1.json");
        file.write(obj.toJSONString());
        file.flush();
        file.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.print(obj);

    /*
            
    JSONParser parser = new JSONParser();
            
    try {
            
    Object obj2 = parser.parse(new FileReader("confSP\\confHost1.json"));
            
    JSONObject jsonObject = (JSONObject) obj2;
            
        HashMap serviceDescription2=(HashMap) jsonObject.get("serviceDescription");
                 
        method.printHashMap(serviceDescription2);
                
                
        HashMap gauranteeTerm2=(HashMap) jsonObject.get("gauranteeTerm");
                 
        method.printHashMap(gauranteeTerm2);
                
                
                
        ArrayList creationConstraint=(ArrayList) jsonObject.get("creationConstraint");
                
        method.printArrayList(creationConstraint);
            
            
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } catch (ParseException e) {
    e.printStackTrace();
    }
            
            
            
            
            
    */

}

From source file:contractEditor.contractHOST2.java

public static void main(String[] args) {

    JSONObject obj = new JSONObject();
    obj.put("name", "HOST2");
    obj.put("context", "VM-deployment");

    //obj.put("Context", new Integer);

    HashMap serviceDescription = new HashMap();
    serviceDescription.put("location", "UK");
    serviceDescription.put("certificate", "false");
    serviceDescription.put("volume", "200_GB");
    serviceDescription.put("price", "5_euro");

    obj.put("serviceDescription", serviceDescription);

    HashMap gauranteeTerm = new HashMap();
    gauranteeTerm.put("availability", "more_99_percentage");
    obj.put("gauranteeTerm", gauranteeTerm);

    //Constraint1

    HashMap host_rule1 = new HashMap();
    HashMap VM_rule1 = new HashMap();
    host_rule1.put("ID", "HOST2");
    VM_rule1.put("data", "private");

    ArrayList rule1 = new ArrayList();
    rule1.add("prohibition");
    rule1.add(host_rule1);/*from   ww w . ja  v a2s .c  om*/
    rule1.add(VM_rule1);

    ArrayList policyInConstraint1 = new ArrayList();
    policyInConstraint1.add(rule1);

    ArrayList creationConstraint1 = new ArrayList();
    creationConstraint1.add("other");
    creationConstraint1.add("true");
    creationConstraint1.add("true");
    creationConstraint1.add(policyInConstraint1);

    ArrayList totalConstraint = new ArrayList();
    totalConstraint.add(creationConstraint1);

    obj.put("creationConstraint", totalConstraint);

    try {

        FileWriter file = new FileWriter("confSP" + File.separator + "Host2.json");
        file.write(obj.toJSONString());
        file.flush();
        file.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.print(obj);

    /*
            
    JSONParser parser = new JSONParser();
            
    try {
            
    Object obj2 = parser.parse(new FileReader("confSP\\confHost1.json"));
            
    JSONObject jsonObject = (JSONObject) obj2;
            
        HashMap serviceDescription2=(HashMap) jsonObject.get("serviceDescription");
                 
        method.printHashMap(serviceDescription2);
                
                
        HashMap gauranteeTerm2=(HashMap) jsonObject.get("gauranteeTerm");
                 
        method.printHashMap(gauranteeTerm2);
                
                
                
        ArrayList creationConstraint=(ArrayList) jsonObject.get("creationConstraint");
                
        method.printArrayList(creationConstraint);
            
            
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } catch (ParseException e) {
    e.printStackTrace();
    }
            
            
            
            
            
    */

}

From source file:contractEditor.contractHOST3.java

public static void main(String[] args) {

    JSONObject obj = new JSONObject();
    obj.put("name", "HOST3");
    obj.put("context", "VM-deployment");

    //obj.put("Context", new Integer);

    HashMap serviceDescription = new HashMap();
    serviceDescription.put("location", "China");
    serviceDescription.put("certificate", "false");
    serviceDescription.put("volume", "70_GB");
    serviceDescription.put("price", "4_euro");

    obj.put("serviceDescription", serviceDescription);

    HashMap gauranteeTerm = new HashMap();
    gauranteeTerm.put("availability", "more_97_percentage");
    obj.put("gauranteeTerm", gauranteeTerm);

    //Constraint1

    HashMap host_rule1 = new HashMap();
    HashMap VM_rule1 = new HashMap();
    host_rule1.put("ID", "HOST3");
    VM_rule1.put("application", "internal");

    ArrayList rule1 = new ArrayList();
    rule1.add("prohibition");
    rule1.add(host_rule1);/*from   w w w  .j a  v  a2 s  . c  o  m*/
    rule1.add(VM_rule1);

    ArrayList policyInConstraint1 = new ArrayList();
    policyInConstraint1.add(rule1);

    ArrayList creationConstraint1 = new ArrayList();
    creationConstraint1.add("other");
    creationConstraint1.add("true");
    creationConstraint1.add("true");
    creationConstraint1.add(policyInConstraint1);

    ArrayList totalConstraint = new ArrayList();
    totalConstraint.add(creationConstraint1);

    obj.put("creationConstraint", totalConstraint);

    try {

        FileWriter file = new FileWriter("confSP" + File.separator + "Host3.json");
        file.write(obj.toJSONString());
        file.flush();
        file.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.print(obj);

    /*
            
    JSONParser parser = new JSONParser();
            
    try {
            
    Object obj2 = parser.parse(new FileReader("confSP\\confHost1.json"));
            
    JSONObject jsonObject = (JSONObject) obj2;
            
        HashMap serviceDescription2=(HashMap) jsonObject.get("serviceDescription");
                 
        method.printHashMap(serviceDescription2);
                
                
        HashMap gauranteeTerm2=(HashMap) jsonObject.get("gauranteeTerm");
                 
        method.printHashMap(gauranteeTerm2);
                
                
                
        ArrayList creationConstraint=(ArrayList) jsonObject.get("creationConstraint");
                
        method.printArrayList(creationConstraint);
            
            
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } catch (ParseException e) {
    e.printStackTrace();
    }
            
            
            
            
            
    */

}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<Integer> ids = new ArrayList<>();

    int total = ids.size(); // total will be zero

    System.out.println("ArrayList size is  " + total);
    System.out.println("ArrayList elements are   " + ids);

    ids.add(new Integer(10)); // Adding an Integer object.
    ids.add(20); // Autoboxing
    ids.add(30); // Autoboxing

    total = ids.size(); // total will be 3

    System.out.println("ArrayList size is  " + total);
    System.out.println("ArrayList elements are   " + ids);

    ids.clear();//  w  ww.  j  a  v  a  2s .c  o  m

    total = ids.size(); // total will be 0
    System.out.println("ArrayList size is  " + total);
    System.out.println("ArrayList elements are   " + ids);
}

From source file:org.jfree.chart.demo.PerformanceTest1.java

public static void main(String args[]) {
    ArrayList<Double> arraylist = new ArrayList<Double>();
    for (int i = 0; i < 4000; i++)
        arraylist.add(new Double(Math.random()));

    int j = 0;/* w w w  .ja v a  2 s .c o  m*/
    for (int k = 0; k < 20000; k++) {
        long l = System.currentTimeMillis();
        for (int i1 = 0; i1 < 0xf4240; i1++)
            j += i1;

        long l1 = System.currentTimeMillis();
        System.out.println(k + " --> " + (l1 - l) + " (" + Runtime.getRuntime().freeMemory() + " / "
                + Runtime.getRuntime().totalMemory() + ")");
    }

}

From source file:MainClass.java

public static void main(String[] a) {
    ArrayList<Employee> emps = new ArrayList<Employee>();

    Employee emp1 = new Employee("A", "G");
    Employee emp2 = new Employee("T", "A");
    Employee emp3 = new Employee("K", "J");

    emps.add(emp1);
    emps.add(emp2);/*from   w w  w. ja va  2  s .c  om*/
    emps.add(emp3);

    System.out.println(emps);

    emps.remove(emp2);

    System.out.println(emps);
}

From source file:edu.stanford.junction.props2.PropDaemon.java

/**
 * Conveniance runner for PropDaemon//w ww.j  a v a2s .  c o  m
 * Expects two arguments: junction-url propName
 */
public static void main(String[] args) {
    if (args.length != 2) {
        System.out.println("Usage: PROGRAM junction-url propName");
        System.exit(0);
    }
    final String urlStr = args[0];
    final String propName = args[1];

    JunctionActor actor = new JunctionActor("prop-daemon") {
        public void onActivityJoin() {
            System.out.println("Joined activity!");
        }

        public void onActivityCreate() {
            System.out.println("Created activity!");
        }

        public void onMessageReceived(MessageHeader header, JSONObject msg) {
            System.out.println("Got message!");
        }

        public List<JunctionExtra> getInitialExtras() {
            ArrayList<JunctionExtra> l = new ArrayList<JunctionExtra>();
            l.add(new PropDaemon(propName));
            return l;
        }
    };

    try {
        URI uri = new URI(urlStr);
        SwitchboardConfig sb = JunctionMaker.getDefaultSwitchboardConfig(uri);
        JunctionMaker jxMaker = JunctionMaker.getInstance(sb);
        Junction jx = jxMaker.newJunction(uri, actor);
    } catch (URISyntaxException e) {
        System.err.println("Failed to parse url!");
        e.printStackTrace(System.err);
    } catch (JunctionException e) {
        System.err.println("Failed to connect to junction activity!");
        e.printStackTrace(System.err);
    } catch (Exception e) {
        System.err.println("Failed to connect to junction activity!");
        e.printStackTrace(System.err);
    }
}

From source file:com.claresco.tinman.servlet.XapiServletUtility.java

public static void main(String[] args) {
    ArrayList<String> theData = new ArrayList<String>();
    theData.add("aldfjaklfja");
    theData.add("duo");

    System.out.println(createJsonArray(theData));

    try {//from ww w. j a  v  a 2  s  . c  om
        System.out.println(decodeBase64("dGVzdDpwYXNzd29yZA=="));
    } catch (Exception e) {

    }

    String st = "Basic dGVzdDpwYXNzd29yZA==";
    System.out.println(st.substring(5));

    System.out.println(encodeBase64("cremebrulee#$%:Comeatmebro***"));

    System.out.println(createHeaderString(theData));
}

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 {/* w  w w  . j a v a2s  .c o  m*/
            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();
        }
    }
}