List of usage examples for java.util List add
boolean add(E e);
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)); }// ww w.j a v a 2 s.co m 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<Character> ll = new LinkedList<Character>(); for (char n = 'A'; n <= 'Z'; n++) ll.add(n); Collections.shuffle(ll);// w w w. j a v a2s.c o m for (Character x : ll) System.out.print(x + " "); Collections.sort(ll); for (Character x : ll) System.out.print(x + " "); System.out.println("Searching for F."); int i = Collections.binarySearch(ll, 'F'); if (i >= 0) { System.out.println("Found at index " + i); System.out.println("Object is " + ll.get(i)); } }
From source file:Level.java
public static void main(String[] args) { Person one = new Person(Level.HIGH, "A"); Person two = new Person(Level.MEDIUM, "B"); Person three = new Person(Level.LOW, "C"); Person four = new Person(Level.HIGH, "D"); Person five = new Person(Level.MEDIUM, "E"); Person six = new Person(Level.LOW, "F"); Person seven = new Person(Level.LOW, "G"); List<Person> persons = new ArrayList<Person>(); persons.add(one); persons.add(two);//from w ww. jav a2s . c o m persons.add(three); persons.add(four); persons.add(five); persons.add(six); persons.add(seven); Collections.sort(persons, new Comparator<Person>() { @Override public int compare(Person person1, Person person2) { if (person1.getSeverity() == person2.getSeverity()) { return person1.getName().compareTo(person2.getName()); } else { return person1.getSeverity().compareTo(person2.getSeverity()); } } }); for (Person person : persons) { System.out.println(person.getName() + " " + person.getSeverity()); } }
From source file:AlternateAuthenticationExample.java
public static void main(String[] args) throws Exception { HttpClient client = new HttpClient(); client.getState().setCredentials(new AuthScope("myhost", 80, "myrealm"), new UsernamePasswordCredentials("username", "password")); // Suppose the site supports several authetication schemes: NTLM and Basic // Basic authetication is considered inherently insecure. Hence, NTLM authentication // is used per default // This is to make HttpClient pick the Basic authentication scheme over NTLM & Digest List authPrefs = new ArrayList(3); authPrefs.add(AuthPolicy.BASIC); authPrefs.add(AuthPolicy.NTLM);/*from w w w . j av a 2 s . co m*/ authPrefs.add(AuthPolicy.DIGEST); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); GetMethod httpget = new GetMethod("http://myhost/protected/auth-required.html"); try { int status = client.executeMethod(httpget); // print the status and response System.out.println(httpget.getStatusLine()); System.out.println(httpget.getResponseBodyAsString()); } finally { // release any connection resources used by the method httpget.releaseConnection(); } }
From source file:Main.java
public static void main(String[] args) { List<Person> list = new ArrayList<Person>(); for (int i = 10; i > 0; i--) { list.add(new Person(i, "name" + String.valueOf(i), new Date())); }/*from w w w .ja va2 s. c o m*/ System.out.println(list); Collections.sort(list); System.out.println(list); }
From source file:ValidateExampleV1.java
public static void main(String args[]) { int i = 35;/* w w w . j a v a 2 s . co m*/ Validate.isTrue(i > 30); // Passes ok // Validate.isTrue(i > 40, "Invalid value: ", i); // throws custom Exception List data = new ArrayList(); // Validate.notEmpty(data, "Collection cannot be empty"); // throws custom Exception data.add(null); Validate.noNullElements(data, "Collection contains null elements"); // throws custom Exception }
From source file:Main.java
public static void main(String args[]) { List<Character> ll = new LinkedList<Character>(); for (char n = 'A'; n <= 'F'; n++) ll.add(n); System.out.println("Here is the original list: "); for (Character x : ll) System.out.print(x + " "); Collections.reverse(ll);// w ww . j a v a 2 s .c o m System.out.println("Here is the reversed list: "); for (Character x : ll) System.out.print(x + " "); Collections.rotate(ll, 2); for (Character x : ll) System.out.print(x + " "); Collections.shuffle(ll); System.out.println("Here is the randomized list:"); for (Character x : ll) System.out.print(x + " "); }
From source file:postenergy.PostHttpClient.java
public static void main(String[] args) { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://iplant.dk/addData.php?n=mindass"); try {//from ww w.j a v a2 s . com List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("?n", "=mindass")); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); if (line.startsWith("Input:")) { String key = line.substring(6); // do something with the key System.out.println("key:" + key); } } } catch (IOException e) { System.out.println("There was an error: " + e); } }
From source file:EntityToD2RHelpers.java
public static void main(String[] args) throws Exception { List<String> people = new ArrayList<String>(); people.add("Mark Watson"); List<String> places = new ArrayList<String>(); places.add("Sedona"); new EntityToD2RHelpers("http://example.com", "testdata/databaseinfo.txt", people, places, new PrintWriter("testdata/gen_rdf.nt")); //new EntityToD2RHelpers("http://example.com", "testdata/databaseinfo.txt", people, places, new PrintWriter(System.out)); }
From source file:MovingPlanets.java
public static void main(String args[]) { String names[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto" }; List planets = new ArrayList(); for (int i = 0, n = names.length; i < n; i++) { planets.add(names[i]); }/*ww w. j a v a2s .c om*/ ListIterator lit = planets.listIterator(); String s; lit.next(); lit.next(); s = (String) lit.next(); lit.remove(); lit.next(); lit.next(); lit.next(); lit.add(s); lit.next(); // Gets back just added lit.previous(); lit.previous(); s = (String) lit.previous(); lit.remove(); lit.next(); lit.next(); lit.add(s); Iterator it = planets.iterator(); while (it.hasNext()) { System.out.println(it.next()); } }