List of usage examples for java.util ListIterator previous
E previous();
From source file:MainClass.java
public static void main(String args[]) { ArrayList<String> al = new ArrayList<String>(); al.add("C");//from ww w.j a v a 2 s . c om al.add("A"); al.add("E"); al.add("B"); al.add("D"); al.add("F"); System.out.print("Original contents of al: "); Iterator<String> itr = al.iterator(); while (itr.hasNext()) { String element = itr.next(); System.out.print(element + " "); } System.out.println(); ListIterator<String> litr = al.listIterator(); while (litr.hasNext()) { String element = litr.next(); litr.set(element + "+"); } // Now, display the list backwards. System.out.print("Modified list backwards: "); while (litr.hasPrevious()) { String element = litr.previous(); System.out.print(element + " "); } }
From source file:IteratorDemo.java
public static void main(String args[]) { ArrayList<String> al = new ArrayList<String>(); al.add("C");/*from w ww. ja v a2 s . c om*/ al.add("A"); al.add("E"); al.add("B"); al.add("D"); al.add("F"); Iterator<String> itr = al.iterator(); while (itr.hasNext()) { String element = itr.next(); System.out.print(element + " "); } ListIterator<String> litr = al.listIterator(); while (litr.hasNext()) { String element = litr.next(); litr.set(element + "+"); } itr = al.iterator(); while (itr.hasNext()) { String element = itr.next(); System.out.print(element + " "); } while (litr.hasPrevious()) { String element = litr.previous(); System.out.print(element + " "); } }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("Oracle"); list.add("SQL"); list.add("CSS"); list.add("XML"); System.out.println("List: " + list); // Get the list iterator ListIterator<String> iterator = list.listIterator(); while (iterator.hasNext()) { int index = iterator.nextIndex(); String element = iterator.next(); System.out.println("Index=" + index + ", Element=" + element); }//from w w w . j a v a2s. co m // Reuse the iterator to iterate from the end to the beginning while (iterator.hasPrevious()) { int index = iterator.previousIndex(); String element = iterator.previous(); System.out.println("Index=" + index + ", Element=" + element); } }
From source file:org.deegree.tools.alkis.BackReferenceFixer.java
public static void main(String[] args) { Options opts = initOptions();//from w w w .jav a2 s .com FileInputStream fis = null; FileOutputStream fos = null; try { CommandLine line = new PosixParser().parse(opts, args); String input = line.getOptionValue('i'); String output = line.getOptionValue('o'); String schema = line.getOptionValue('s'); fis = new FileInputStream(input); fos = new FileOutputStream(output); XMLInputFactory xifac = XMLInputFactory.newInstance(); XMLOutputFactory xofac = XMLOutputFactory.newInstance(); XMLStreamReader xreader = xifac.createXMLStreamReader(input, fis); IndentingXMLStreamWriter xwriter = new IndentingXMLStreamWriter(xofac.createXMLStreamWriter(fos)); GMLStreamReader reader = GMLInputFactory.createGMLStreamReader(GMLVersion.GML_32, xreader); AppSchema appSchema = new GMLAppSchemaReader(null, null, schema).extractAppSchema(); reader.setApplicationSchema(appSchema); GMLStreamWriter writer = GMLOutputFactory.createGMLStreamWriter(GMLVersion.GML_32, xwriter); XlinkedObjectsHandler handler = new XlinkedObjectsHandler(true, null, new GmlXlinkOptions()); writer.setReferenceResolveStrategy(handler); QName prop = new QName(ns601, "dientZurDarstellungVon"); Map<String, List<String>> refs = new HashMap<String, List<String>>(); Map<String, List<String>> types = new HashMap<String, List<String>>(); Map<String, String> bindings = null; for (Feature f : reader.readFeatureCollectionStream()) { if (bindings == null) { bindings = f.getType().getSchema().getNamespaceBindings(); } for (Property p : f.getProperties(prop)) { FeatureReference ref = (FeatureReference) p.getValue(); List<String> list = refs.get(ref.getId()); if (list == null) { list = new ArrayList<String>(); refs.put(ref.getId(), list); } list.add(f.getId()); list = types.get(ref.getId()); if (list == null) { list = new ArrayList<String>(); types.put(ref.getId(), list); } list.add("inversZu_dientZurDarstellungVon_" + f.getType().getName().getLocalPart()); } } QName[] inversePropNames = new QName[] { new QName(ns601, "inversZu_dientZurDarstellungVon_AP_Darstellung"), new QName(ns601, "inversZu_dientZurDarstellungVon_AP_LTO"), new QName(ns601, "inversZu_dientZurDarstellungVon_AP_PTO"), new QName(ns601, "inversZu_dientZurDarstellungVon_AP_FPO"), new QName(ns601, "inversZu_dientZurDarstellungVon_AP_KPO_3D"), new QName(ns601, "inversZu_dientZurDarstellungVon_AP_LPO"), new QName(ns601, "inversZu_dientZurDarstellungVon_AP_PPO") }; reader.close(); fis.close(); writer.setNamespaceBindings(bindings); fis = new FileInputStream(input); xreader = xifac.createXMLStreamReader(input, fis); reader = GMLInputFactory.createGMLStreamReader(GMLVersion.GML_32, xreader); reader.setApplicationSchema(appSchema); if (bindings != null) { for (Map.Entry<String, String> e : bindings.entrySet()) { if (!e.getKey().isEmpty()) { xwriter.setPrefix(e.getValue(), e.getKey()); } } } xwriter.writeStartDocument(); xwriter.setPrefix("gml", "http://www.opengis.net/gml/3.2"); xwriter.writeStartElement("http://www.opengis.net/gml/3.2", "FeatureCollection"); xwriter.writeNamespace("gml", "http://www.opengis.net/gml/3.2"); GmlDocumentIdContext ctx = new GmlDocumentIdContext(GMLVersion.GML_32); for (Feature f : reader.readFeatureCollectionStream()) { if (refs.containsKey(f.getId())) { List<Property> props = new ArrayList<Property>(f.getProperties()); ListIterator<Property> iter = props.listIterator(); String name = iter.next().getName().getLocalPart(); while (name.equals("lebenszeitintervall") || name.equals("modellart") || name.equals("anlass") || name.equals("zeigtAufExternes") || name.equals("istTeilVon") || name.equals("identifier")) { if (iter.hasNext()) { name = iter.next().getName().getLocalPart(); } else { break; } } if (iter.hasPrevious()) { iter.previous(); } for (QName propName : inversePropNames) { Iterator<String> idIter = refs.get(f.getId()).iterator(); Iterator<String> typeIter = types.get(f.getId()).iterator(); while (idIter.hasNext()) { String id = idIter.next(); if (typeIter.next().equals(propName.getLocalPart())) { PropertyType pt = f.getType().getPropertyDeclaration(propName); Property p = new GenericProperty(pt, new FeatureReference(ctx, "#" + id, null)); iter.add(p); } } } f.setProperties(props); } xwriter.writeStartElement("http://www.opengis.net/gml/3.2", "featureMember"); writer.write(f); xwriter.writeEndElement(); } xwriter.writeEndElement(); xwriter.close(); } catch (Throwable e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { IOUtils.closeQuietly(fis); IOUtils.closeQuietly(fos); } }
From source file:Main.java
public final static <T> T peekPrevious(ListIterator<T> iterator) { T previous = iterator.previous(); iterator.next();/*from www. j ava 2 s . co m*/ return previous; }
From source file:Main.java
private static <T> T findPrevious(ListIterator<T> iter) { T prev = null;//from ww w. jav a 2 s . co m iter.previous(); // rewind if (iter.hasPrevious()) { prev = iter.previous(); iter.next(); // come back } iter.next(); // come back return prev; }
From source file:Main.java
public final static <T> T peekNext(ListIterator<T> iterator) { T next = iterator.next();/*from ww w . j ava 2 s .c o m*/ iterator.previous(); return next; }
From source file:Main.java
/** * Remove all null elements at the end of the list. *///from www. j a v a 2 s . com public static <T> void trimTail(List<T> l) { final ListIterator<T> it = l.listIterator(l.size()); while (it.hasPrevious()) { if (it.previous() != null) return; it.remove(); } }
From source file:Main.java
/** * Returns the last non-null element in the given list; or, if * there is no non-null element, it returns null. * * @param l The list. It may be null, in which case null is * returned./*from w w w .j a v a 2 s . c o m*/ * * @return The element. */ public static <E> E getLastNonNull(List<E> l) { if (l == null) { return null; } ListIterator<E> i = l.listIterator(l.size()); while (i.hasPrevious()) { E e = i.previous(); if (e != null) { return e; } } return null; }
From source file:Main.java
private static <T> T findNext(ListIterator<T> iter) { T next = null;/*w ww. j av a2 s . co m*/ if (iter.hasNext()) { next = iter.next(); iter.previous(); // come back } return next; }