List of usage examples for java.util ListIterator hasPrevious
boolean hasPrevious();
From source file:org.apache.poi.ss.format.CellNumberFormatter.java
private void writeInteger(StringBuffer result, StringBuffer output, List<Special> numSpecials, Set<StringMod> mods, boolean showCommas) { int pos = result.indexOf(".") - 1; if (pos < 0) { if (exponent != null && numSpecials == integerSpecials) pos = result.indexOf("E") - 1; else//from www . jav a2 s .co m pos = result.length() - 1; } int strip; for (strip = 0; strip < pos; strip++) { char resultCh = result.charAt(strip); if (resultCh != '0' && resultCh != ',') break; } ListIterator<Special> it = numSpecials.listIterator(numSpecials.size()); boolean followWithComma = false; Special lastOutputIntegerDigit = null; int digit = 0; while (it.hasPrevious()) { char resultCh; if (pos >= 0) resultCh = result.charAt(pos); else { // If result is shorter than field, pretend there are leading zeros resultCh = '0'; } Special s = it.previous(); followWithComma = showCommas && digit > 0 && digit % 3 == 0; boolean zeroStrip = false; if (resultCh != '0' || s.ch == '0' || s.ch == '?' || pos >= strip) { zeroStrip = s.ch == '?' && pos < strip; output.setCharAt(s.pos, (zeroStrip ? ' ' : resultCh)); lastOutputIntegerDigit = s; } if (followWithComma) { mods.add(insertMod(s, zeroStrip ? " " : ",", StringMod.AFTER)); followWithComma = false; } digit++; --pos; } StringBuffer extraLeadingDigits = new StringBuffer(); if (pos >= 0) { // We ran out of places to put digits before we ran out of digits; put this aside so we can add it later ++pos; // pos was decremented at the end of the loop above when the iterator was at its end extraLeadingDigits = new StringBuffer(result.substring(0, pos)); if (showCommas) { while (pos > 0) { if (digit > 0 && digit % 3 == 0) extraLeadingDigits.insert(pos, ','); digit++; --pos; } } mods.add(insertMod(lastOutputIntegerDigit, extraLeadingDigits, StringMod.BEFORE)); } }
From source file:playground.sergioo.ptsim2013.qnetsimengine.PTQLink.java
/** * This method/*from w w w . jav a 2 s. co m*/ * moves transit vehicles from the stop queue directly to the front of the * "queue" of the QLink. An advantage is that this will observe flow * capacity restrictions. */ private void moveTransitToQueue(final double now) { QVehicle veh; // handle transit traffic in stop queue List<QVehicle> departingTransitVehicles = null; while ((veh = transitVehicleStopQueue.peek()) != null) { // there is a transit vehicle. if (veh.getEarliestLinkExitTime() > now) { break; } if (departingTransitVehicles == null) { departingTransitVehicles = new LinkedList<QVehicle>(); } departingTransitVehicles.add(transitVehicleStopQueue.poll()); } if (departingTransitVehicles != null) { // add all departing transit vehicles at the front of the vehQueue ListIterator<QVehicle> iter = departingTransitVehicles.listIterator(departingTransitVehicles.size()); while (iter.hasPrevious()) { this.vehQueue.addFirst(iter.previous()); } } }
From source file:net.sf.jabref.bst.VM.java
private void reverse(Tree child) { BstFunction f = functions.get(child.getChild(0).getText()); ListIterator<BstEntry> i = entries.listIterator(entries.size()); while (i.hasPrevious()) { f.execute(i.previous());/*from w w w. jav a 2 s . c o m*/ } }
From source file:com.epam.catgenome.manager.gene.GffManager.java
private void loadExonsBackwards(int centerPosition, int viewPortSize, Chromosome chromosome, int intronLength, int featuresStart, final IntervalTree<Block> intervalTree, final AbstractFeatureReader<GeneFeature, LineIterator> featureReader) throws IOException { int totalLength = 0; // check if some of exons, got by forward lookup are good for backwards Iterator<IntervalTree.Node<Block>> nodeIterator = intervalTree.overlappers(featuresStart, centerPosition); while (nodeIterator.hasNext()) { Block exon = nodeIterator.next().getValue(); totalLength += calculateExonLength(exon, centerPosition, false); }//from www.ja v a 2 s.c o m int i = 0; boolean lastChunk = false; while (totalLength < viewPortSize / 2) { if (lastChunk) { break; } int firstIndex = centerPosition - EXON_SEARCH_CHUNK_SIZE * (i + 1); final int lastIndex = centerPosition - 1 - EXON_SEARCH_CHUNK_SIZE * i; if (firstIndex < featuresStart) { firstIndex = featuresStart; lastChunk = true; // this is the last chunk to be traversed } CloseableIterator<GeneFeature> iterator = Utils.query(featureReader, chromosome, firstIndex, lastIndex); // instead traversing the whole file, read it by small chunks, 100000 bps // long. Hopefully, the desired window will be covered by first/second chunk if (iterator.hasNext()) { List<GeneFeature> featuresChunk = iterator.toList(); ListIterator<GeneFeature> listIterator = featuresChunk.listIterator(featuresChunk.size() - 1); while (listIterator.hasPrevious() && totalLength < viewPortSize / 2) { GeneFeature feature = listIterator.previous(); totalLength = processExon(intervalTree, totalLength, feature, intronLength, centerPosition, false); } } i++; } }
From source file:org.eredlab.g4.ccl.net.ftp.parser.VMSVersioningFTPEntryParser.java
/** * Implement hook provided for those implementers (such as * VMSVersioningFTPEntryParser, and possibly others) which return * multiple files with the same name to remove the duplicates .. * * @param original Original list/*from ww w.ja va 2 s .c o m*/ * * @return Original list purged of duplicates */ public List preParse(List original) { original = super.preParse(original); HashMap existingEntries = new HashMap(); ListIterator iter = original.listIterator(); while (iter.hasNext()) { String entry = ((String) iter.next()).trim(); MatchResult result = null; if (_preparse_matcher_.matches(entry, _preparse_pattern_)) { result = _preparse_matcher_.getMatch(); String name = result.group(1); String version = result.group(2); NameVersion nv = new NameVersion(name, version); NameVersion existing = (NameVersion) existingEntries.get(name); if (null != existing) { if (nv.versionNumber < existing.versionNumber) { iter.remove(); // removal removes from original list. continue; } } existingEntries.put(name, nv); } } // we've now removed all entries less than with less than the largest // version number for each name that were listed after the largest. // we now must remove those with smaller than the largest version number // for each name that were found before the largest while (iter.hasPrevious()) { String entry = ((String) iter.previous()).trim(); MatchResult result = null; if (_preparse_matcher_.matches(entry, _preparse_pattern_)) { result = _preparse_matcher_.getMatch(); String name = result.group(1); String version = result.group(2); NameVersion nv = new NameVersion(name, version); NameVersion existing = (NameVersion) existingEntries.get(name); if (null != existing) { if (nv.versionNumber < existing.versionNumber) { iter.remove(); // removal removes from original list. } } } } return original; }
From source file:net.rptools.tokentool.controller.TokenTool_Controller.java
public void updateOverlayTreeViewRecentFolder(boolean selectMostRecent) { if (lastSelectedItem != null) updateRecentOverlayTreeItems(lastSelectedItem.getValue()); // Update Recent Overlay List if (!recentOverlayTreeItems.isEmpty()) { // Remember current selection (adding/removing tree items messes with the selection model) // int selectedItem = overlayTreeView.getSelectionModel().getSelectedIndex(); overlayTreeView.getSelectionModel().clearSelection(); // Clear current folder recentFolder.getChildren().clear(); // Add recent list to recentFolder in reverse order so most recent is at the top ListIterator<Entry<Path, TreeItem<Path>>> iter = new ArrayList<>(recentOverlayTreeItems.entrySet()) .listIterator(recentOverlayTreeItems.size()); while (iter.hasPrevious()) recentFolder.getChildren().add(iter.previous().getValue()); if (overlayTreeView.getRoot().getChildren().indexOf(recentFolder) == -1) { overlayTreeView.getRoot().getChildren().add(recentFolder); } else {//from w w w .j a v a 2 s . c o m overlayTreeView.getRoot().getChildren().remove(recentFolder); overlayTreeView.getRoot().getChildren().add(recentFolder); } // Auto expand recent folder... recentFolder.setExpanded(true); addPseudoClassToLeafs(overlayTreeView); // Set the selected index back to what it was unless... if (selectMostRecent) { overlayTreeView.getSelectionModel().select(recentFolder.getChildren().get(0)); } else { // overlayTreeView.getSelectionModel().clearAndSelect(selectedItem); } } }
From source file:com.projity.pm.graphic.frames.DocumentFrame.java
/** * sees if currently selected row belongs to main project. used to see if can insert a subproject. subprojects can * only be inserted into master project//from w w w . j a va2s.co m * @return */ public boolean isCurrentRowInMainProject() { CommonSpreadSheet spreadSheet = getTopSpreadSheet(); if (spreadSheet == null) return true; int row = spreadSheet.getCurrentRow(); if (row == -1) return true; Node current = spreadSheet.getCurrentRowNode(); SpreadSheetModel model = (SpreadSheetModel) spreadSheet.getModel(); LinkedList previousNodes = model.getPreviousVisibleNodesFromRow(row); if (previousNodes == null) return true; previousNodes.add(current); // treat current node first since going backwards ListIterator i = previousNodes.listIterator(previousNodes.size()); while (i.hasPrevious()) { Object o = ((Node) i.previous()).getImpl(); if (o instanceof Task) { if (((Task) o).isInSubproject()) return false; return project == ((Task) o).getOwningProject(); } } return true; }
From source file:com.qspin.qtaste.testsuite.impl.JythonTestScript.java
private void dumpScriptPythonStackDetails(TestResult result, Throwable error) { StringBuilder stackTrace = new StringBuilder(); // get stacktrace from PyException traceback, because easier and line number is not always correct in Java stack trace if (error instanceof PyException) { List<PyFrame> stacktrace = new ArrayList<>(); PyTraceback previousTraceback = null; PyTraceback traceback = ((PyException) error).traceback; while (traceback != null && traceback != previousTraceback) { PyFrame frame = traceback.tb_frame; String fileName;//from ww w .ja v a2s . c om String function; if (frame != null && frame.f_code != null && (fileName = frame.f_code.co_filename) != null && (function = frame.f_code.co_name) != null) { // skip execfile() call in the embedded jython, doStep() and doSteps() functions, // private __invokexxx() methods of the __TestAPIWrapper class, // private __checkPresent() method of a test API wrapper class, // user_line() method of the __ScriptDebugger class and a function of the debugger if ((!fileName.equals("embedded_jython") || (!function.equals("<module>") && !function.equals("doStep") && !function.equals("doSteps") && !function.startsWith("_TestAPIWrapper__invoke") && !function.endsWith("__checkPresent") && !function.equals("user_line"))) && !fileName.endsWith(File.separator + "bdb.py")) { stacktrace.add(frame); } } previousTraceback = traceback; traceback = (PyTraceback) traceback.tb_next; } // extract all necessary details from stacktrace from last frame to first one boolean stackLastDataExtracted = false; ListIterator<PyFrame> frameIterator = stacktrace.listIterator(stacktrace.size()); while (frameIterator.hasPrevious()) { PyFrame frame = frameIterator.previous(); String fileName = frame.f_code.co_filename; String function = frame.f_code.co_name; int lineNumber = frame.f_lineno; // convert absolute path to relative path Path filePath = Paths.get(fileName); if (filePath.isAbsolute()) { filePath = Paths.get("").toAbsolutePath().relativize(filePath); } // normalize path fileName = filePath.normalize().toString(); if (function.equals("<module>")) { stackTrace.append("at file ").append(fileName).append(" line ").append(lineNumber).append('\n'); } else if (!function.equals("importTestScript")) { stackTrace.append("function ").append(function); if (!fileName.equals("embedded_jython") && !fileName.equals("JythonTestScript.java")) { stackTrace.append(" at file ").append(fileName).append(" line ").append(lineNumber); } stackTrace.append('\n'); } if (!stackLastDataExtracted && !fileName.equals("embedded_jython") && !fileName.equals("JythonTestScript.java")) { stackLastDataExtracted = true; result.setFailedLineNumber(lineNumber); result.setFailedFunctionId(function); } result.addStackTraceElement(new StackTraceElement("", function, fileName, lineNumber)); } } result.setStackTrace(stackTrace.toString().trim()); }
From source file:org.zkoss.poi.ss.format.CellNumberFormatter.java
private void writeInteger(StringBuffer result, StringBuffer output, List<Special> numSpecials, Set<StringMod> mods, boolean showCommas, boolean fraction) {//20100924, henrichen@zkoss.org: fraction has special treatment about zero //20100914, henrichen@zkoss.org: repect the current locale final char comma = Formatters.getGroupingSeparator(locale); final String commaStr = "" + comma; final String dot = "" + Formatters.getDecimalSeparator(locale); int pos = result.indexOf(dot) - 1; if (pos < 0) { if (exponent != null && numSpecials == integerSpecials) pos = result.indexOf("E") - 1; else// w w w .ja va2 s. co m pos = result.length() - 1; } int strip; for (strip = 0; strip < pos; strip++) { char resultCh = result.charAt(strip); if (resultCh != '0' && resultCh != comma) break; } //20100924, henrichen@zkoss.org: handle all zero case final char posCh = !fraction && strip == pos && pos >= 0 ? result.charAt(pos) : '\000'; final boolean allZeros = posCh == '0' || posCh == comma; ListIterator<Special> it = numSpecials.listIterator(numSpecials.size()); boolean followWithComma = false; Special lastOutputIntegerDigit = null; int digit = 0; while (it.hasPrevious()) { char resultCh; if (pos >= 0) resultCh = result.charAt(pos); else { // If result is shorter than field, pretend there are leading zeros resultCh = '0'; } Special s = it.previous(); followWithComma = showCommas && digit > 0 && digit % 3 == 0; boolean zeroStrip = false; if (resultCh != '0' || s.ch == '0' || s.ch == '?' || pos >= strip) { zeroStrip = s.ch == '?' && (pos < strip || allZeros); //20100924, henrichen@zkoss.org: handle all zero case output.setCharAt(s.pos, (zeroStrip ? ' ' : resultCh)); lastOutputIntegerDigit = s; } if (followWithComma) { //20100914, henrichen@zkoss.org: repect the current locale //mods.add(insertMod(s, zeroStrip ? " " : ",", StringMod.AFTER)); mods.add(insertMod(s, zeroStrip ? " " : commaStr, StringMod.AFTER)); followWithComma = false; } digit++; --pos; } StringBuffer extraLeadingDigits = new StringBuffer(); if (pos >= 0) { // We ran out of places to put digits before we ran out of digits; put this aside so we can add it later ++pos; // pos was decremented at the end of the loop above when the iterator was at its end extraLeadingDigits = new StringBuffer(result.substring(0, pos)); if (showCommas) { while (pos > 0) { if (digit > 0 && digit % 3 == 0) //20100914, henrichen@zkoss.org: repect the current locale //extraLeadingDigits.insert(pos, ','); extraLeadingDigits.insert(pos, comma); digit++; --pos; } } mods.add(insertMod(lastOutputIntegerDigit, extraLeadingDigits, StringMod.BEFORE)); } }
From source file:de.fosd.jdime.matcher.cost_model.CostModelMatcher.java
/** * Finds the lowest pair of (possibly different) ancestors of <code>a</code> and <code>b</code> that are part of the * same sibling group./*from w w w.j a v a 2s .c om*/ * * @param a * the first <code>Artifact</code> * @param b * the second <code>Artifact</code> * @param matchings * the current <code>CMMatching</code> * @param parameters * the <code>CMParameters</code> to use * @return the ancestor of the first <code>Artifact</code> in the first position, that of the second in the second * position */ private Tuple<T, T> lca(T a, T b, CMMatchings<T> matchings, CMParameters<T> parameters) { return parameters.lcaCache.computeIfAbsent(Tuple.of(a, b), ab -> { Tuple<T, T> ba = Tuple.of(b, a); if (parameters.lcaCache.containsKey(ba)) { Tuple<T, T> baLCS = parameters.lcaCache.get(ba); return Tuple.of(baLCS.y, baLCS.x); } if (siblings(a, matchings, parameters).contains(b)) { return ab; } List<T> aPath = pathToRoot(a); List<T> bPath = pathToRoot(b); ListIterator<T> aIt = aPath.listIterator(aPath.size()); ListIterator<T> bIt = bPath.listIterator(bPath.size()); T l, r; do { l = aIt.previous(); r = bIt.previous(); } while (l == r && (aIt.hasPrevious() && bIt.hasPrevious())); return Tuple.of(l, r); }); }