/** * Read stream into array of strings. * * @param inputStream The InputStream for the file. */ protected void openInputStream(InputStream inputStream) { String textLine; // Collect input lines in an array list. List<String> lines = ListFactory.createNewList(); BufferedReader bufferedReader = null; try { bufferedReader = new BufferedReader(new UnicodeReader(inputStream, textFileEncoding)); while ((textLine = bufferedReader.readLine()) != null) { lines.add(textLine); } textFileLoaded = true; } catch (IOException e) { } finally { try { if (bufferedReader != null) bufferedReader.close(); } catch (Exception e) { } } // Convert array list to array of strings. textFileLines = new String[lines.size()]; for (int i = 0; i < lines.size(); i++) { textFileLines[i] = lines.get(i); } }
/** @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ListFactory<String> factory = new ArrayListFactory<String>(); List<String> theList = factory.newInstance(); theList.add("Ron"); theList.add("Jil"); theList.add("Amy"); theList.add("Ron"); printList(theList); theList.add(0, "Apu"); theList.add(theList.size(), "Xi"); System.out.println("First element: " + theList.first()); System.out.println("Last element: " + theList.last()); printList(theList); theList.remove("Amy"); System.out.println("After removing Amy: " + theList.last()); printList(theList); theList.removeAll("Ron"); System.out.println("After removing all Ron: " + theList.last()); printList(theList); theList.add("Mel"); theList.add(1, "Cal"); printList(theList); theList.add("Cal"); printList(theList); System.out.println("First Index of Cal: " + theList.firstIndex("Cal")); System.out.println("Last Index of Cal: " + theList.lastIndex("Cal")); System.out.println("First Index of Xi: " + theList.firstIndex("Xi")); System.out.println("Last Index of Xi: " + theList.lastIndex("Xi")); System.out.println("First Index of Li: " + theList.firstIndex("Li")); System.out.println("Last Index of Li: " + theList.lastIndex("Li")); System.out.println("Element at position 2: " + theList.get(2)); theList.set(2, "Al"); System.out.println("Element at position 2: " + theList.get(2)); printList(theList); theList.clear(); printList(theList); }
/** * @param args - not used * @throws Exception - if anything goes awry */ public static void main(String[] args) throws Exception { // Create lists to be populated by factory // remember to consider final qualifier for local vars List<ClientAccount> accounts = new ArrayList<ClientAccount>(); List<Consultant> consultants = new ArrayList<Consultant>(); List<TimeCard> timeCards = new ArrayList<TimeCard>(); ListFactory.populateLists(accounts, consultants, timeCards); DbServer db = new DbServer("jdbc:mysql://localhost/scgDB", "student", "student"); for (ClientAccount account : accounts) { db.addClient(account); } for (Consultant consultant : consultants) { db.addConsultant(consultant); } for (TimeCard tc : timeCards) { db.addTimeCard(tc); } }
@SuppressWarnings({"rawtypes", "unchecked"}) @Override public PersistentCollection<V> values() { Iterator<Map.Entry<Long, V>> entryIterator = this.entrySet().iterator(); return ListFactory.createFromIterator(new Iterators.ValueIterator(entryIterator)); }