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.greglturnquist.embeddablesdr.Application.java

public static void main(String[] args) {
    ApplicationContext ctx = SpringApplication.run(Application.class, args);

    SystemRepository repository = ctx.getBean(SystemRepository.class);

    System system1 = new System();
    system1.setName("router101");
    system1 = repository.save(system1);/*from ww  w. jav  a  2 s  .  c  om*/

    System system2 = new System();
    system2.setName("switch405");
    system2 = repository.save(system2);

    SystemDependency dep1 = new SystemDependency();
    dep1.setDescription("WLAN");
    dep1.setTarget(system1);

    SystemDependency dep2 = new SystemDependency();
    dep2.setDescription("UPS");
    dep2.setTarget(system1);

    ArrayList<SystemDependency> dependencies1 = new ArrayList<>();
    dependencies1.add(dep1);
    dependencies1.add(dep2);
    system1.setDependencies(dependencies1);

    system1 = repository.save(system1);

    SystemDependency dep3 = new SystemDependency();
    dep3.setDescription("MUX");
    dep3.setTarget(system1);

    SystemDependency dep4 = new SystemDependency();
    dep4.setDescription("Backup Battery");
    dep4.setTarget(system2);

    ArrayList<SystemDependency> dependencies2 = new ArrayList<>();
    dependencies2.add(dep3);
    dependencies2.add(dep4);
    system2.setDependencies(dependencies2);

    system2 = repository.save(system2);

}

From source file:Person.java

public static void main(String[] args) {
    SimpleDateFormat df = new SimpleDateFormat("mm-dd-yyyy");
    ArrayList<Person> people;
    people = new ArrayList<Person>();
    try {//from  ww  w.j  av  a  2s .co m
        people.add(new Person("A", 9, df.parse("12-12-2014")));
        people.add(new Person("B", 2, df.parse("1-12-2013")));
        people.add(new Person("C", 4, df.parse("12-2-2012")));
    } catch (ParseException e) {
        e.printStackTrace();
    }

    Collections.sort(people, new CompId());
    System.out.println("BY ID");
    for (Person p : people) {
        System.out.println(p.toString());
    }

    Collections.sort(people, new CompDate(false));
    System.out.println("BY Date asc");
    for (Person p : people) {
        System.out.println(p.toString());
    }
    Collections.sort(people, new CompDate(true));
    System.out.println("BY Date desc");
    for (Person p : people) {
        System.out.println(p.toString());
    }

}

From source file:ObjectAnalyzerTest.java

public static void main(String[] args) {
    ArrayList<Integer> squares = new ArrayList<Integer>();
    for (int i = 1; i <= 5; i++)
        squares.add(i * i);
    System.out.println(new ObjectAnalyzer().toString(squares));
}

From source file:eurecom.constrained.devices.MainReasonSensorData.java

public static void main(String[] args) {
    //String sensor_data = WSUtils.queryWebServiceJSON(RASPBERRYPI_WEATHER_LUMINOSITY);
    String sensor_data = ReadFile.readContentFile(SENSOR_DATA_FILE);
    ConvertRaspberrySensorData converter = new ConvertRaspberrySensorData();
    Model model;//www . j av  a 2 s.  c  o  m
    try {
        model = converter.convertRaspberrySensorDataToRDF(sensor_data, M3_RULES_PATH);

        //load the M2M measurement
        M2MAppGeneric m2mappli = new M2MAppGeneric(model);

        //load domain specific datasets and ontologies
        ReadFile.enrichJenaModelOntologyDataset(m2mappli.model, M3_ONTOLOGY_PATH);//no need
        ReadFile.enrichJenaModelOntologyDataset(m2mappli.model, TRANSPORT_ONTOLOGY_PATH);
        ReadFile.enrichJenaModelOntologyDataset(m2mappli.model, TRANSPORT_DATASET_PATH);
        ReadFile.enrichJenaModelOntologyDataset(m2mappli.model, WEATHER_ONTOLOGY_PATH);
        ReadFile.enrichJenaModelOntologyDataset(m2mappli.model, WEATHER_DATASET_PATH);

        //variable in the sparql query
        ArrayList<VariableSparql> var = new ArrayList<VariableSparql>();
        var.add(new VariableSparql("inferTypeUri", Var.NS_M3 + "WeatherLuminosity", false));
        var.add(new VariableSparql("typeRecommendedUri", Var.NS_TRANSPORT_ONTOLOGY + "SafetyDevice", false));//SafetyDevice

        Model inf = m2mappli.reasonWithJenaRules(LOR_FILE_PATH);//reasoner for jena rules //Var.LINKED_OPEN_RULES
        ExecuteSparqlGeneric reqSenml = new ExecuteSparqlGeneric(inf, SPARQL_QUERY_WEATHER_SAFETY_DEVICES_PATH);

        ArrayList<ResultSensorDataReasoning> resultAfterReasoning = reqSenml.getSelectResultAnsParseIt(var);
        for (int i = 0; i < resultAfterReasoning.size(); i++) {
            System.out.println(resultAfterReasoning.get(i).toString());
        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {

    Class.forName(DRIVER);// w  ww  . j  a  v  a 2s .com
    Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);

    Statement statement = connection.createStatement();
    ResultSet resultSet = statement.executeQuery("SELECT * FROM users");

    ResultSetMetaData metadata = resultSet.getMetaData();
    int columnCount = metadata.getColumnCount();

    ArrayList<String> columns = new ArrayList<String>();
    for (int i = 1; i < columnCount; i++) {
        String columnName = metadata.getColumnName(i);
        columns.add(columnName);
    }

    while (resultSet.next()) {
        for (String columnName : columns) {
            String value = resultSet.getString(columnName);
            System.out.println(columnName + " = " + value);
        }
    }
}

From source file:flashcrawler.FlashCrawler.java

/**
 * @param args the command line arguments
 *///from   w  w w  .j a  v  a  2s  .  c o  m
public static void main(String[] args) throws FileNotFoundException {
    Scanner scn = new Scanner(new File("input.txt"));
    ArrayList<String> ins = new ArrayList();
    while (scn.hasNextLine()) {
        String input = scn.nextLine();
        ins.add(input);
    }

    String URL;
    PrintWriter writer = null;
    writer = new PrintWriter(new FileOutputStream(new File("error-log.txt"), true));

    String File;
    for (String name : ins) {
        File offlinePath = new File("/games/" + name + ".swf");
        String onlinePath = "http://wsh.gamib.com/x/" + name + "/" + name + ".swf";
        System.out.println("Downloading " + onlinePath + " into " + offlinePath);
        URL url = null;
        try {
            System.out.println("...");
            url = new URL(onlinePath);
        } catch (MalformedURLException ex) {
            System.out.println("Failed to create url object");
            writer.println("Error when creating url: " + onlinePath + "\tname");
        }
        try {
            System.out.println("...");
            FileUtils.copyURLToFile(url, offlinePath);
            System.out.println("Success.");
        } catch (IOException ex) {
            System.out.println("Error when downloading game: " + offlinePath);
            writer.println("Error when downloading game: " + offlinePath);
        }

    }
    writer.close();
    System.out.println("Process complete!");
}

From source file:contractEditor.contractHOST4.java

public static void main(String[] args) {

    JSONObject obj = new JSONObject();
    obj.put("name", "HOST4");
    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", "3_euro");

    obj.put("serviceDescription", serviceDescription);

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

    //Constraint1

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

    obj.put("creationConstraint", totalConstraint);

    try {// w w  w  .  j  a v a2s.c o  m

        FileWriter file = new FileWriter("confSP" + File.separator + "Host4.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: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() {
            {/*w w w.ja  v a  2s.  c om*/
                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);
}

From source file:ArrayListDemo.java

public static void main(String[] argv) {
    ArrayList al = new ArrayList();

    // Create a source of Objects
    StructureDemo source = new StructureDemo(15);

    // Add lots of elements to the ArrayList...
    al.add(source.getDate());
    al.add(source.getDate());/*  www.jav  a 2 s .  co  m*/
    al.add(source.getDate());

    // First print them out using a for loop.
    System.out.println("Retrieving by index:");
    for (int i = 0; i < al.size(); i++) {
        System.out.println("Element " + i + " = " + al.get(i));
    }
}

From source file:Main.java

public static void main(String[] args) {
    ResourceBundle bundle = ResourceBundle.getBundle("hello", Locale.US);
    Enumeration<String> keys = bundle.getKeys();
    ArrayList<String> temp = new ArrayList<String>();

    for (Enumeration<String> e = keys; keys.hasMoreElements();) {
        String key = e.nextElement();
        if (key.startsWith("java2s")) {
            temp.add(key);
        }/* ww  w.j  av  a  2 s .  c o  m*/
    }

    String[] result = new String[temp.size()];

    for (int i = 0; i < temp.size(); i++) {
        result[i] = bundle.getString(temp.get(i));
    }
    System.out.println(Arrays.toString(result));
}