List of usage examples for java.util ArrayList ArrayList
public ArrayList()
From source file:math2605.gn_qua.java
/** * @param args the command line arguments *//*from ww w . j a v a 2 s . com*/ public static void main(String[] args) { //get file name System.out.println("Please enter a file name:"); Scanner scanner = new Scanner(System.in); String fileName = scanner.nextLine(); List<String[]> pairs = new ArrayList<>(); //get coordinate pairs and add to arraylist try { BufferedReader br = new BufferedReader(new FileReader(fileName)); String line; while ((line = br.readLine()) != null) { String[] pair = line.split(","); pairs.add(pair); } br.close(); } catch (Exception e) { System.out.println(e.getMessage()); } System.out.println("Please enter the value of a:"); double a = scanner.nextInt(); System.out.println("Please enter the value of b:"); double b = scanner.nextInt(); System.out.println("Please enter the value of c:"); double c = scanner.nextInt(); //init B, vector with 3 coordinates RealMatrix B = new Array2DRowRealMatrix(3, 1); B.setEntry(0, 0, a); B.setEntry(1, 0, b); B.setEntry(2, 0, c); System.out.println("Please enter the number of iteration for the Gauss-newton:"); //init N, number of iterations int N = scanner.nextInt(); //init r, vector of residuals RealMatrix r = new Array2DRowRealMatrix(pairs.size(), 1); setR(pairs, a, b, c, r); //init J, Jacobian of r RealMatrix J = new Array2DRowRealMatrix(pairs.size(), 3); setJ(pairs, a, b, c, r, J); System.out.println("J"); System.out.println(J); System.out.println("r"); System.out.println(r); RealMatrix sub = findQR(J, r); for (int i = N; i > 0; i--) { B = B.subtract(sub); double B0 = B.getEntry(0, 0); double B1 = B.getEntry(1, 0); double B2 = B.getEntry(2, 0); //CHANGE ABC TO USE B0, B1, B2 setR(pairs, B0, B1, B2, r); setJ(pairs, B0, B1, B2, r, J); } System.out.println("B"); System.out.println(B.toString()); }
From source file:flashcrawler.FlashCrawler.java
/** * @param args the command line arguments *//* www .j a v a 2 s . 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:cooccurrence.emf.java
public static void main(String args[]) { String path = ""; String writePath = ""; BufferedReader br = null;/* w ww .j a v a2 s . c om*/ ArrayList<String> files = new ArrayList<>(); listFilesForFolder(new File(path), files); for (String filePath : files) { System.out.println(filePath); String fileName = new File(filePath).getName(); //data structure to store the PPMI matrix in the file HashMap<String, HashMap<String, Double>> cooccur = new HashMap<>(); readFileContents(filePath, cooccur); //reading the file and storing the content in the hashmap //Because Matrices are identified by row and col id, the following //lists maps id to corresponding string. Note that matrix is symmetric. ArrayList<String> rowStrings = new ArrayList<>(cooccur.keySet()); ArrayList<String> colStrings = new ArrayList<>(cooccur.keySet()); //creating matrix with given dimensions and initializing it to 0 RealMatrix matrixR = MatrixUtils.createRealMatrix(rowStrings.size(), colStrings.size()); //populating the matrices based on the co-occur hashmap populateMatrixR(matrixR, cooccur, rowStrings, colStrings); } }
From source file:TestReadCustData.java
public static void main(String[] args) { AgentLoader.loadAgentFromClasspath("avaje-ebeanorm-agent", "debug=1"); List<Customer> lCust = new ArrayList<>(); try {/*from w w w. j a va 2 s . c o m*/ List<String> s = Files.readAllLines(Paths.get("customer.txt"), Charsets.ISO_8859_1); for (String s1 : s) { if (!s1.startsWith("GRUP")) { Customer c = new Customer(); try { c.setId(Long.parseLong(s1.split("~")[3])); } catch (ArrayIndexOutOfBoundsException arrex) { c.setId(Long.parseLong(s1.split("~")[3])); } try { c.setNama(s1.split("~")[4]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNama(""); } try { c.setShipto(s1.split("~")[9]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setShipto(""); } try { c.setKota(s1.split("~")[12]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setKota(""); } try { c.setProvinsi(s1.split("~")[13]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setProvinsi(""); } try { c.setKodePos(s1.split("~")[14]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setKodePos(""); } try { c.setNamaArea(s1.split("~")[2]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNamaArea(""); } try { c.setDKLK(s1.split("~")[15]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setDKLK(""); } try { c.setCreditLimit(Long.parseLong(s1.split("~")[16])); } catch (ArrayIndexOutOfBoundsException arrex) { c.setCreditLimit(new Long(0)); } try { c.setNpwp(s1.split("~")[11]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNpwp(""); } try { c.setNamaWajibPajak(s1.split("~")[10]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNamaWajibPajak(""); } try { c.setCreationDate(s1.split("~")[6]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setCreationDate(""); } try { c.setLastUpdateBy(s1.split("~")[17]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setLastUpdateBy(""); } try { c.setLastUpdateDate(s1.split("~")[18]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setLastUpdateDate(""); } lCust.add(c); } } for (Customer c : lCust) { Customer cc = Ebean.find(Customer.class, c.getId()); if (cc != null) { cc = c; Ebean.update(cc); } System.out.print(c.getId()); System.out.print(" | "); System.out.print(c.getNama()); System.out.print(" | "); System.out.print(c.getShipto()); System.out.print(" | "); System.out.print(c.getNpwp()); System.out.print(" | "); System.out.print(c.getNamaWajibPajak()); System.out.println(); } } catch (IOException ex) { Logger.getLogger(TestReadCustData.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:math2605.gn_log.java
/** * @param args the command line arguments *///from ww w . j av a2 s . c o m public static void main(String[] args) { //get file name System.out.println("Please enter a file name:"); Scanner scanner = new Scanner(System.in); String fileName = scanner.nextLine(); List<String[]> pairs = new ArrayList<>(); //get coordinate pairs and add to arraylist try { BufferedReader br = new BufferedReader(new FileReader(fileName)); String line; while ((line = br.readLine()) != null) { String[] pair = line.split(","); pairs.add(pair); } br.close(); } catch (Exception e) { } System.out.println("Please enter the value of a:"); double a = scanner.nextInt(); System.out.println("Please enter the value of b:"); double b = scanner.nextInt(); System.out.println("Please enter the value of c:"); double c = scanner.nextInt(); //init B, vector with 3 coordinates RealMatrix B = new Array2DRowRealMatrix(3, 1); B.setEntry(0, 0, a); B.setEntry(1, 0, b); B.setEntry(2, 0, c); System.out.println("Please enter the number of iteration for the Gauss-newton:"); //init N, number of iterations int N = scanner.nextInt(); //init r, vector of residuals RealMatrix r = new Array2DRowRealMatrix(); setR(pairs, a, b, c, r); //init J, Jacobian of r RealMatrix J = new Array2DRowRealMatrix(); setJ(pairs, a, b, c, r, J); System.out.println("J"); System.out.println(J); System.out.println("r"); System.out.println(r); RealMatrix sub = findQR(J, r); for (int i = N; i > 0; i--) { B = B.subtract(sub); double B0 = B.getEntry(0, 0); double B1 = B.getEntry(1, 0); double B2 = B.getEntry(2, 0); //CHANGE ABC TO USE B0, B1, B2 setR(pairs, B0, B1, B2, r); setJ(pairs, B0, B1, B2, r, J); } System.out.println("B"); System.out.println(B.toString()); }
From source file:StringBuilderTester.java
public static void main(String[] args) { List list = new ArrayList(); list.add("I"); list.add("play"); list.add("Bourgeois"); list.add("guitars"); list.add("and"); list.add("Huber"); list.add("banjos"); System.out.println(StringBuilderTester.appendItems(list)); }
From source file:math2605.gn_exp.java
/** * @param args the command line arguments *//*from ww w .j a va2 s . com*/ public static void main(String[] args) { //get file name System.out.println("Please enter a file name:"); Scanner scanner = new Scanner(System.in); String fileName = scanner.nextLine(); List<String[]> pairs = new ArrayList<>(); //get coordinate pairs and add to arraylist try { BufferedReader br = new BufferedReader(new FileReader(fileName)); String line; while ((line = br.readLine()) != null) { String[] pair = line.split(","); pairs.add(pair); } br.close(); } catch (Exception e) { } System.out.println("Please enter the value of a:"); double a = scanner.nextInt(); System.out.println("Please enter the value of b:"); double b = scanner.nextInt(); System.out.println("Please enter the value of c:"); double c = scanner.nextInt(); //init B, vector with 3 coordinates RealMatrix B = new Array2DRowRealMatrix(3, 1); B.setEntry(0, 0, a); B.setEntry(1, 0, b); B.setEntry(2, 0, c); System.out.println("Please enter the number of iteration for the Gauss-newton:"); //init N, number of iterations int N = scanner.nextInt(); //init r, vector of residuals RealMatrix r = new Array2DRowRealMatrix(); setR(pairs, a, b, c, r); //init J, Jacobian of r RealMatrix J = new Array2DRowRealMatrix(); setJ(pairs, a, b, c, r, J); System.out.println("J"); System.out.println(J); System.out.println("r"); System.out.println(r); RealMatrix sub = findQR(J, r); for (int i = N; i > 0; i--) { B = B.subtract(sub); double B0 = B.getEntry(0, 0); double B1 = B.getEntry(1, 0); double B2 = B.getEntry(2, 0); //CHANGE ABC TO USE B0, B1, B2 setR(pairs, B0, B1, B2, r); setJ(pairs, B0, B1, B2, r, J); } System.out.println("B"); System.out.println(B.toString()); }
From source file:ArrayListComboBoxModel.java
public static void main(String args[]) { JFrame frame = new JFrame("ArrayListComboBoxModel"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ArrayList<Object> arrayList = new ArrayList<Object>(); arrayList.add("A"); arrayList.add("B"); arrayList.add("C"); ArrayListComboBoxModel model = new ArrayListComboBoxModel(arrayList); JComboBox comboBox = new JComboBox(model); frame.add(comboBox, BorderLayout.NORTH); frame.setSize(300, 225);/* www . ja va 2 s . com*/ frame.setVisible(true); }
From source file:net.anymeta.Test.java
/** * @param args//from ww w. j a va 2 s .co m */ public static void main(String[] arg) throws AnyMetaRegistryException, AnyMetaException, JSONException { HashMap<String, Object> args; // Load the API AnyMetaAPI api = AnyMetaAPI.fromRegistry("pluto.local"); // Get information for the currently logged in user. JSONObject o = (JSONObject) api.doMethod("anymeta.user.info"); System.out.println("Logged in as " + o.getString("title")); // args = new HashMap<String, Object>(); args.put("q_kind", "PERSON"); JSONArray a = (JSONArray) api.doMethod("query.execute", args); System.out.println(a.toString()); System.out.println(a.length()); // Lookup an RFID tag. args = new HashMap<String, Object>(); ArrayList<String> ids = new ArrayList<String>(); ids.add("65"); ids.add("94"); args.put("ids", ids); args.put("predicate", "KNOWS"); o = (JSONObject) api.doMethod("contact.link", args); System.out.println(o.toString()); // Upload an image args = new HashMap<String, Object>(); args.put("mime", "image/jpeg"); args.put("data", "@C:\\bla.jpg"); o = (JSONObject) api.doMethod("anymeta.attachment.create", args); System.out.println(o.toString()); }
From source file:eu.seaclouds.platform.planner.core.PlannerClient.java
public static void main(String[] args) throws IOException { ArrayList<NameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair("aam", "test http healper")); String content = new HttpHelper("http://localhost:8080").getRequest("/plan", params); System.out.println(content);/*from w w w . j a va 2 s.c o m*/ content = new HttpHelper("http://localhost:8080").postRequest("/plan", params); System.out.println("POST!!!! " + content); // CloseableHttpClient httpclient = HttpClients.createDefault(); // // // HttpGet hhtpGet = new HttpGet("http://localhost:8080/plan?aam=qwerty"); // // // CloseableHttpResponse response2 = httpclient.execute(hhtpGet); // //// HttpPost httpPost = new HttpPost("http://targethost/login"); //// List <NameValuePair> nvps = new ArrayList <NameValuePair>(); //// nvps.add(new BasicNameValuePair("username", "vip")); //// nvps.add(new BasicNameValuePair("password", "secret")); //// httpPost.setEntity(new UrlEncodedFormEntity(nvps)); //// CloseableHttpResponse response2 = httpclient.execute(httpPost); // // try { // //System.out.println(response2.getStatusLine()); // HttpEntity entity2 = response2.getEntity(); // // do something useful with the response body // // and ensure it is fully consumed // // String content = new Scanner(entity2.getContent()).useDelimiter("\\Z").next(); // System.out.println(content); // // EntityUtils.consume(entity2); // } finally { // response2.close(); // } }