List of usage examples for java.util ListIterator previousIndex
int previousIndex();
From source file:org.toryt.util_I.beanfinder.ChainedBeanFinder.java
public final Object findFor(_Argument_ argument) throws BeanFinderConfigurationException, NoBeanFoundException { Object bean = null;//w w w . j a va2 s .co m ListIterator<BeanFinder<_Argument_>> iter = $actualBeanFinders.listIterator(); while ((bean == null) && iter.hasNext()) { BeanFinder<_Argument_> bf = iter.next(); _LOG.debug("trying chained beanfinder " + iter.previousIndex() + ": " + bf); try { bean = bf.findFor(argument); // throws BeanFinderConfigurationException, NoBeanFoundException _LOG.debug("bean found for argument \"" + argument + "\" by bean finder \"" + bf + "\": " + bean); } catch (NoBeanFoundException nbfExc) { _LOG.debug("no bean found for argument \"" + argument + "\" by bean finder \"" + bf + "\"; continuing chain"); assert bean == null; // continue the search } } if (bean == null) { _LOG.debug("no bean found for argument \"" + argument + "\" by any bean " + "finder in the chain; giving up"); throw new NoBeanFoundException(this, argument); } return bean; }
From source file:org.ut.biolab.medsavant.server.db.variants.annotation.AnnotationCursor.java
boolean annotateVariants(List<SimpleVariantRecord> variantWindow, long minStart, long maxEnd, int annotationIndex, boolean isLowDensity) throws Exception { if (!canAnnotateThisChromosome(variantWindow.get(0).chrom)) { //this chromosome can't be annotated. return false; }//from w w w . j ava2s .c o m //Annotates variants by separately seeking annotations for each variant. Usually slow unless //variants are very sparse. if (isLowDensity) { for (SimpleVariantRecord svr : variantWindow) { TabixReader.Iterator annotationIt = reader.query(reader.chr2tid(variantWindow.get(0).chrom), (int) svr.start - 1, //this function returns annotations AFTER this position, so we need to have the -1 (int) svr.end); if (annotationIt == null) { continue; } while (annotationIt.hasNext()) { String annotationLineStr = (String) annotationIt.next(); String[] annotationLine = removeNewLinesAndCarriageReturns(annotationLineStr) .split(VariantManagerUtils.FIELD_DELIMITER, -1); SimpleAnnotationRecord annotationRecord = new SimpleAnnotationRecord(annotationLine); if (annotationRecord.matchesVariant(svr)) { svr.annotate(annotationIndex, getVariantAnnotationString(annotationLine)); } } } return true; } //Annotates variants by reading in all annotations in the region delimited by the variantWindow //(only uses one seek). Faster if variants are dense. TabixReader.Iterator annotationIt = reader.query(reader.chr2tid(variantWindow.get(0).chrom), (int) Math.max(0, minStart - 1), //this function returns annotations AFTER this position, so we need to have the -1 (int) maxEnd); if (annotationIt == null) { //no annotations in this range. return true; } int variantWindowIndex = 0; while (annotationIt.hasNext()) { //For each annotation in start + min(start+max_base_pair_distance_in_window, end) String annotationLineStr = (String) annotationIt.next(); String[] annotationLine = removeNewLinesAndCarriageReturns(annotationLineStr) .split(VariantManagerUtils.FIELD_DELIMITER, -1); SimpleAnnotationRecord annotationRecord = new SimpleAnnotationRecord(annotationLine); ListIterator<SimpleVariantRecord> variantWindowIt = variantWindow.listIterator(variantWindowIndex); while (variantWindowIt.hasNext()) { SimpleVariantRecord variantRecord = variantWindowIt.next(); if (annotationRecord.matchesVariant(variantRecord)) { //annotate variantRecord.annotate(annotationIndex, getVariantAnnotationString(annotationLine)); } else if (variantRecord.start > annotationRecord.end) { variantWindowIndex = variantWindowIt.previousIndex(); break; } } } return true; }
From source file:samples.com.axiomine.largecollections.util.KryoListSample.java
public static void workOnKryoList(KryoList<Integer> lst) { try {/*from w w w .j a va 2 s.co m*/ ListIterator<Integer> it = lst.listIterator(); for (int i = 0; i < 10; i++) { boolean b = lst.add(i); Assert.assertEquals(true, true); } System.out.println("Size of map=" + lst.size()); System.out.println("Value for key 0=" + lst.get(0)); ; System.out.println("Now remove key 0"); try { int i = lst.remove(0); } catch (Exception ex) { System.out.println(ex.getMessage()); } int i = lst.remove(9); System.out.println("Value for deleted key=" + i); ; System.out.println("Size of map=" + lst.size()); lst.close(); boolean b = false; try { lst.add(9); } catch (Exception ex) { System.out.println("Exception because acces after close"); b = true; } lst.open(); System.out.println("Open again"); b = lst.add(9); Assert.assertEquals(true, b); i = lst.set(9, 99); Assert.assertEquals(99, i); i = lst.set(5, 55); Assert.assertEquals(55, i); i = lst.set(0, 100); Assert.assertEquals(100, i); System.out.println(lst.get(0)); System.out.println(lst.get(5)); System.out.println(lst.get(9)); System.out.println("Now put worked. Size of map should be 10. Size of the map =" + lst.size()); Iterator<Integer> iter = lst.iterator(); try { while (iter.hasNext()) { i = iter.next(); System.out.println("From ITerator = " + i); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) iter).close(); } ListIterator<Integer> lstIter = lst.listIterator(); try { while (lstIter.hasNext()) { i = lstIter.next(); System.out.println("From List Iterator = " + i); System.out.println("From List Iterator Next Index= " + lstIter.nextIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } lstIter = lst.listIterator(5); try { while (lstIter.hasNext()) { i = lstIter.next(); System.out.println("From List Iterator = " + i); System.out.println("From List Iterator Next Index= " + lstIter.nextIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("---"); lstIter = lst.listIterator(9); try { while (lstIter.hasPrevious()) { i = lstIter.previous(); System.out.println("From List Iterator Previous= " + i); System.out.println("From List Iterator Previous Index= " + lstIter.previousIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("----------------------------------"); lstIter = lst.listIterator(); try { while (lstIter.hasNext()) { i = lstIter.next(); System.out.println("Iterating Forward = " + i); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("Now Serialize the List"); File serFile = new File(System.getProperty("java.io.tmpdir") + "/x.ser"); FileSerDeUtils.serializeToFile(lst, serFile); System.out.println("Now De-Serialize the List"); lst = (KryoList<Integer>) FileSerDeUtils.deserializeFromFile(serFile); System.out.println("After De-Serialization " + lst); System.out.println("After De-Serialization Size of map should be 10. Size of the map =" + lst.size()); printListCharacteristics(lst); System.out.println("Now calling lst.clear()"); lst.clear(); System.out.println("After clear list size should be 0 and =" + lst.size()); lst.add(0); System.out.println("Just added a record and lst size =" + lst.size()); System.out.println("Finally Destroying"); lst.destroy(); System.out.println("Cleanup serialized file"); FileUtils.deleteQuietly(serFile); } catch (Exception ex) { throw Throwables.propagate(ex); } }
From source file:samples.com.axiomine.largecollections.util.TurboListSample.java
public static void workOnTurboList(TurboList<Integer> lst) { try {// ww w. ja v a 2 s . com ListIterator<Integer> it = lst.listIterator(); for (int i = 0; i < 10; i++) { boolean b = lst.add(i); Assert.assertEquals(true, true); } System.out.println("Size of map=" + lst.size()); System.out.println("Value for key 0=" + lst.get(0)); ; System.out.println("Now remove key 0"); try { int i = lst.remove(0); } catch (Exception ex) { System.out.println(ex.getMessage()); } int i = lst.remove(9); System.out.println("Value for deleted key=" + i); ; System.out.println("Size of map=" + lst.size()); lst.close(); boolean b = false; try { lst.add(9); } catch (Exception ex) { System.out.println("Exception because acces after close"); b = true; } lst.open(); System.out.println("Open again"); b = lst.add(9); Assert.assertEquals(true, b); i = lst.set(9, 99); Assert.assertEquals(99, i); i = lst.set(5, 55); Assert.assertEquals(55, i); i = lst.set(0, 100); Assert.assertEquals(100, i); System.out.println(lst.get(0)); System.out.println(lst.get(5)); System.out.println(lst.get(9)); System.out.println("Now put worked. Size of map should be 10. Size of the map =" + lst.size()); Iterator<Integer> iter = lst.iterator(); try { while (iter.hasNext()) { i = iter.next(); System.out.println("From ITerator = " + i); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) iter).close(); } ListIterator<Integer> lstIter = lst.listIterator(); try { while (lstIter.hasNext()) { i = lstIter.next(); System.out.println("From List Iterator = " + i); System.out.println("From List Iterator Next Index= " + lstIter.nextIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } lstIter = lst.listIterator(5); try { while (lstIter.hasNext()) { i = lstIter.next(); System.out.println("From List Iterator = " + i); System.out.println("From List Iterator Next Index= " + lstIter.nextIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("---"); lstIter = lst.listIterator(9); try { while (lstIter.hasPrevious()) { i = lstIter.previous(); System.out.println("From List Iterator Previous= " + i); System.out.println("From List Iterator Previous Index= " + lstIter.previousIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("----------------------------------"); lstIter = lst.listIterator(); try { while (lstIter.hasNext()) { i = lstIter.next(); System.out.println("Iterating Forward = " + i); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("Now Serialize the List"); File serFile = new File(System.getProperty("java.io.tmpdir") + "/x.ser"); FileSerDeUtils.serializeToFile(lst, serFile); System.out.println("Now De-Serialize the List"); lst = (TurboList<Integer>) FileSerDeUtils.deserializeFromFile(serFile); System.out.println("After De-Serialization " + lst); System.out.println("After De-Serialization Size of map should be 10. Size of the map =" + lst.size()); printListCharacteristics(lst); System.out.println("Now calling lst.clear()"); lst.clear(); System.out.println("After clear list size should be 0 and =" + lst.size()); lst.add(0); System.out.println("Just added a record and lst size =" + lst.size()); System.out.println("Finally Destroying"); lst.destroy(); System.out.println("Cleanup serialized file"); FileUtils.deleteQuietly(serFile); } catch (Exception ex) { throw Throwables.propagate(ex); } }
From source file:samples.com.axiomine.largecollections.util.WritableListSample.java
public static void workOnWritableList(WritableList<IntWritable> lst) { try {/*from ww w. j a va 2 s. co m*/ ListIterator<Writable> it = lst.listIterator(); for (int i = 0; i < 10; i++) { boolean b = lst.add(new IntWritable(i)); Assert.assertEquals(true, true); } System.out.println("Size of map=" + lst.size()); System.out.println("Value for key 0=" + lst.get(0)); ; System.out.println("Now remove key 0"); try { //int i = lst.remove(0); Writable w = lst.remove(0); } catch (Exception ex) { System.out.println(ex.getMessage()); } int i = ((IntWritable) lst.remove(9)).get(); System.out.println("Value for deleted key=" + i); ; System.out.println("Size of map=" + lst.size()); lst.close(); boolean b = false; try { lst.add(new IntWritable(9)); } catch (Exception ex) { System.out.println("Exception because acces after close"); b = true; } lst.open(); System.out.println("Open again"); b = lst.add(new IntWritable(9)); Assert.assertEquals(true, b); i = ((IntWritable) lst.set(9, new IntWritable(99))).get(); Assert.assertEquals(99, i); i = ((IntWritable) lst.set(5, new IntWritable(55))).get(); Assert.assertEquals(55, i); i = ((IntWritable) lst.set(0, new IntWritable(100))).get(); Assert.assertEquals(100, i); System.out.println(lst.get(0)); System.out.println(lst.get(5)); System.out.println(lst.get(9)); System.out.println("Now put worked. Size of map should be 10. Size of the map =" + lst.size()); Iterator<Writable> iter = lst.iterator(); try { while (iter.hasNext()) { i = ((IntWritable) iter.next()).get(); System.out.println("From ITerator = " + i); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) iter).close(); } ListIterator<Writable> lstIter = lst.listIterator(); try { while (lstIter.hasNext()) { i = ((IntWritable) lstIter.next()).get(); System.out.println("From List Iterator = " + i); System.out.println("From List Iterator Next Index= " + lstIter.nextIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } lstIter = lst.listIterator(5); try { while (lstIter.hasNext()) { i = ((IntWritable) lstIter.next()).get(); System.out.println("From List Iterator = " + i); System.out.println("From List Iterator Next Index= " + lstIter.nextIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("---"); lstIter = lst.listIterator(9); try { while (lstIter.hasPrevious()) { i = ((IntWritable) lstIter.next()).get(); System.out.println("From List Iterator Previous= " + i); System.out.println("From List Iterator Previous Index= " + lstIter.previousIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("----------------------------------"); lstIter = lst.listIterator(); try { while (lstIter.hasNext()) { i = ((IntWritable) lstIter.next()).get(); System.out.println("Iterating Forward = " + i); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("Now Serialize the List"); File serFile = new File(System.getProperty("java.io.tmpdir") + "/x.ser"); FileSerDeUtils.serializeToFile(lst, serFile); System.out.println("Now De-Serialize the List"); lst = (WritableList<IntWritable>) FileSerDeUtils.deserializeFromFile(serFile); System.out.println("After De-Serialization " + lst); System.out.println("After De-Serialization Size of map should be 10. Size of the map =" + lst.size()); printListCharacteristics(lst); System.out.println("Now calling lst.clear()"); lst.clear(); System.out.println("After clear list size should be 0 and =" + lst.size()); lst.add(new IntWritable(0)); System.out.println("Just added a record and lst size =" + lst.size()); System.out.println("Finally Destroying"); lst.destroy(); System.out.println("Cleanup serialized file"); FileUtils.deleteQuietly(serFile); } catch (Exception ex) { throw Throwables.propagate(ex); } }