Example usage for java.util List get

List of usage examples for java.util List get

Introduction

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

Prototype

E get(int index);

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:DbUtilsUseMapMySQL.java

public static void main(String[] args) {
    Connection conn = null;/*  w  w w  .jav a  2 s  .  c  o  m*/
    String jdbcURL = "jdbc:mysql://localhost/octopus";
    String jdbcDriver = "com.mysql.jdbc.Driver";
    String user = "root";
    String password = "root";

    try {
        DbUtils.loadDriver(jdbcDriver);
        conn = DriverManager.getConnection(jdbcURL, user, password);

        QueryRunner qRunner = new QueryRunner();

        List mapList = (List) qRunner.query(conn, "select id, name from animals_table", new MapListHandler());

        for (int i = 0; i < mapList.size(); i++) {
            Map map = (Map) mapList.get(i);
            System.out.println("id=" + map.get("id"));
            System.out.println("name=" + map.get("name"));
            System.out.println("-----------------");
        }

        System.out.println("DbUtils_UseMap_MySQL: end.");

    } catch (SQLException e) {
        // handle the exception
        e.printStackTrace();
    } finally {
        DbUtils.closeQuietly(conn);
    }
}

From source file:com.mtea.macrotea_httpclient_study.ClientCustomContext.java

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

    HttpClient httpclient = new DefaultHttpClient();
    try {//ww w .  j  a va2  s .  c  om
        // CookieStore 
        CookieStore cookieStore = new BasicCookieStore();

        // HttpContext 
        HttpContext localContext = new BasicHttpContext();

        //HttpContextCookieStore
        localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

        HttpGet httpget = new HttpGet("http://www.google.com/");

        System.out.println("executing request " + httpget.getURI());

        // ?
        HttpResponse response = httpclient.execute(httpget, localContext);
        HttpEntity entity = response.getEntity();

        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());
        if (entity != null) {
            System.out.println("Response content length: " + entity.getContentLength());
        }

        //???cookie
        List<Cookie> cookies = cookieStore.getCookies();
        for (int i = 0; i < cookies.size(); i++) {
            System.out.println("Local cookie: " + cookies.get(i));
        }

        //
        EntityUtils.consume(entity);

        System.out.println("----------------------------------------");

    } finally {
        //??httpclient???
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:com.plexobject.testplayer.dao.hibernate.MethodStatsDaoHibernate.java

public static void main(String[] args) throws Exception {
    MethodStatsDaoHibernate dao = new MethodStatsDaoHibernate();
    createTable();/* w w  w .j av a  2s. c om*/
    for (int i = 0; i < 10; i++) {
        MethodStats method = new MethodStats("void main" + i + "(String[] args)", 2000 + i, 2000 + i, 2000 + i,
                2000 + i, false, new Date());
        dao.save(method);
    }
    /*
    */
    List<MethodStats> list = dao.findAll();
    System.out.println("Printing " + list.size() + ":\n" + list);
    if (list.size() > 0) {
        System.out.println("First " + dao.findById(list.get(0).getSignature()));
    }
}

From source file:Address.java

public static void main(String[] a) throws Exception {
        em.getTransaction().begin();/*from ww w.j a v a  2s . co m*/

        Student student = new Student();
        student.setName("Joe");
        Address address = new Address();
        address.setCity("city");
        //  em.persist(address);

        student.setAddress(address);

        em.persist(student);
        em.flush();
        em.getTransaction().commit();

        Query query = em.createQuery("SELECT e FROM Student e");
        List<Student> list = (List<Student>) query.getResultList();
        System.out.println(list.get(0).getAddress());

        em.close();
        emf.close();

        Helper.checkData();
    }

From source file:Student.java

  public static void main(String[] a) throws Exception {
  em.getTransaction().begin();// w w  w  . j  a  va  2s.  c o m
    
    
  Student student = new Student();
  student.setName("Joe");
  em.persist(student);
    
  Student student1 = new Student();
  student1.setName("Joe");
  em.persist(student1);
    
  Department dept = new Department();
  dept.setName("dept name");
  student.setDepartment(dept);
  student1.setDepartment(dept);
    
  em.flush();
    


    
    
    
  Query query = em.createQuery("SELECT e FROM Student e");
  List<Student> list = (List<Student>) query.getResultList();
  System.out.println(list.get(0).getDepartment());
    
  query = em.createQuery("SELECT d FROM Department d");
  List<Department> dList = (List<Department>) query.getResultList();
  System.out.println(dList.get(0).getStudents());
    
  em.getTransaction().commit();
  em.close();
  emf.close();
    
  Helper.checkData();
}

From source file:com.ibm.iot.auto.bluemix.samples.ui.MapView.java

public static void main(String[] args) {
    String inputFile = null;//w  w w .j ava2  s  . c  o  m
    String jobId = null;
    for (int i = 0; i < args.length; i++) {
        if ("--input_file".equalsIgnoreCase(args[i])) {
            inputFile = args[i + 1];
        } else if ("--job_id".equalsIgnoreCase(args[i])) {
            jobId = args[i + 1];
        }
    }
    if (inputFile == null) {
        inputFile = INPUT_FILE;
    }
    if (jobId == null) {
        System.err.println(
                "usage: java -jar mapview.jar --job_id <job ID> [--input_file <driving data JSON file>]");
        return;
    }

    Configuration config = null;
    try {
        config = new Configuration(CONFIG_FILE);

        InputData inputData = new InputData(inputFile);
        carProbes = inputData.getCarProbes();

        DriverService service = new DriverService(config);

        List<String> tripUuIds = service.getAllTripUuIds(jobId);
        String tripUuId = tripUuIds.get(0);
        driverBehaviorDetails = service.getAllDriverBehaviorDetails(tripUuId);

        String[] arguments = { MapView.class.getName() };
        PApplet.main(arguments);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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));
    }//w  ww .  j a  v a2  s. c  om
    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:Main.java

public static void main(String args[]) {
    List<Integer> dataList = new ArrayList<Integer>();
    for (int i = 0; i < 10; i++) {
        dataList.add(i);/*from www  .  j a v  a 2s. co  m*/
    }
    Collections.shuffle(dataList);
    int[] num = new int[dataList.size()];
    for (int i = 0; i < dataList.size(); i++) {
        num[i] = dataList.get(i);
    }
    System.out.println(Arrays.toString(num));
}

From source file:com.termmed.sampling.ConceptsWithMoreThanThreeRoleGroups.java

/**
 * The main method./*  w ww .java2  s.com*/
 *
 * @param args the arguments
 * @throws Exception the exception
 */
public static void main(String[] args) throws Exception {
    System.out.println("Starting...");
    Map<String, Set<String>> groupsMap = new HashMap<String, Set<String>>();
    File relsFile = new File(
            "/Users/alo/Downloads/SnomedCT_RF2Release_INT_20160131-1/Snapshot/Terminology/sct2_Relationship_Snapshot_INT_20160131.txt");
    BufferedReader br2 = new BufferedReader(new FileReader(relsFile));
    String line2;
    int count2 = 0;
    while ((line2 = br2.readLine()) != null) {
        // process the line.
        count2++;
        if (count2 % 10000 == 0) {
            //System.out.println(count2);
        }
        List<String> columns = Arrays.asList(line2.split("\t", -1));
        if (columns.size() >= 6) {
            if (columns.get(2).equals("1") && !columns.get(6).equals("0")) {
                if (!groupsMap.containsKey(columns.get(4))) {
                    groupsMap.put(columns.get(4), new HashSet<String>());
                }
                groupsMap.get(columns.get(4)).add(columns.get(6));
            }
        }
    }
    System.out.println("Relationship groups loaded");
    Gson gson = new Gson();
    System.out.println("Reading JSON 1");
    File crossoverFile1 = new File("/Users/alo/Downloads/crossover_role_to_group.json");
    String contents = FileUtils.readFileToString(crossoverFile1, "utf-8");
    Type collectionType = new TypeToken<Collection<ControlResultLine>>() {
    }.getType();
    List<ControlResultLine> lineObject = gson.fromJson(contents, collectionType);
    Set<String> crossovers1 = new HashSet<String>();
    for (ControlResultLine loopResult : lineObject) {
        crossovers1.add(loopResult.conceptId);
    }
    System.out.println("Crossovers 1 loaded, " + lineObject.size() + " Objects");

    System.out.println("Reading JSON 2");
    File crossoverFile2 = new File("/Users/alo/Downloads/crossover_group_to_group.json");
    String contents2 = FileUtils.readFileToString(crossoverFile2, "utf-8");
    List<ControlResultLine> lineObject2 = gson.fromJson(contents2, collectionType);
    Set<String> crossovers2 = new HashSet<String>();
    for (ControlResultLine loopResult : lineObject2) {
        crossovers2.add(loopResult.conceptId);
    }
    System.out.println("Crossovers 2 loaded, " + lineObject2.size() + " Objects");

    Set<String> foundConcepts = new HashSet<String>();
    int count3 = 0;
    BufferedWriter writer = new BufferedWriter(
            new FileWriter(new File("ConceptsWithMoreThanThreeRoleGroups.csv")));
    ;
    for (String loopConcept : groupsMap.keySet()) {
        if (groupsMap.get(loopConcept).size() > 3) {
            writer.write(loopConcept);
            writer.newLine();
            foundConcepts.add(loopConcept);
            count3++;
        }
    }
    writer.close();
    System.out.println("Found " + foundConcepts.size() + " concepts");

    int countCrossover1 = 0;
    for (String loopConcept : foundConcepts) {
        if (crossovers1.contains(loopConcept)) {
            countCrossover1++;
        }
    }
    System.out.println(countCrossover1 + " are present in crossover_role_to_group");

    int countCrossover2 = 0;
    for (String loopConcept : foundConcepts) {
        if (crossovers2.contains(loopConcept)) {
            countCrossover2++;
        }
    }
    System.out.println(countCrossover2 + " are present in crossover_group_to_group");

    System.out.println("Done");
}

From source file:DbUtilsUseBeanMySQL.java

public static void main(String[] args) {
    Connection conn = null;/* w w w  .  j  a v a 2 s.  co  m*/
    String jdbcURL = "jdbc:mysql://localhost/octopus";
    String jdbcDriver = "com.mysql.jdbc.Driver";
    String user = "root";
    String password = "root";

    try {
        DbUtils.loadDriver(jdbcDriver);
        conn = DriverManager.getConnection(jdbcURL, user, password);

        QueryRunner qRunner = new QueryRunner();
        List beans = (List) qRunner.query(conn, "select id, name from animals_table",
                new BeanListHandler(Employee.class));

        for (int i = 0; i < beans.size(); i++) {
            Employee bean = (Employee) beans.get(i);
            bean.print();
        }
    } catch (SQLException e) {
        // handle the exception
        e.printStackTrace();
    } finally {
        DbUtils.closeQuietly(conn);
    }
}