List of usage examples for java.util ListIterator previous
E previous();
From source file:chat.viska.commons.pipelines.Pipeline.java
@Nullable private ListIterator<Map.Entry<String, Pipe>> getIteratorOf(@Nullable final Pipe pipe) { if (pipe == null) { return null; }// ww w. java 2 s . com final ListIterator<Map.Entry<String, Pipe>> iterator = pipes.listIterator(); while (iterator.hasNext()) { Map.Entry entry = iterator.next(); if (entry.getValue().equals(pipe)) { iterator.previous(); return iterator; } } return null; }
From source file:chat.viska.commons.pipelines.Pipeline.java
private void processException(ListIterator<Map.Entry<String, Pipe>> iterator, Exception cause, boolean isReading) { while (isReading ? iterator.hasNext() : iterator.hasPrevious()) { final Pipe pipe = isReading ? iterator.next().getValue() : iterator.previous().getValue(); try {/*from w ww . j av a 2 s . co m*/ if (isReading) { pipe.catchInboundException(this, cause); } else { pipe.catchOutboundException(this, cause); } return; } catch (Exception rethrown) { cause = rethrown; } } triggerEvent(new ExceptionCaughtEvent(this, cause)); }
From source file:org.apache.cloudstack.api.response.QuotaResponseBuilderImpl.java
@Override public QuotaBalanceResponse createQuotaBalanceResponse(List<QuotaBalanceVO> quotaBalance, Date startDate, Date endDate) {/* w w w. j av a2 s . co m*/ if (quotaBalance == null || quotaBalance.isEmpty()) { throw new InvalidParameterValueException("The request period does not contain balance entries."); } Collections.sort(quotaBalance, new Comparator<QuotaBalanceVO>() { public int compare(QuotaBalanceVO o1, QuotaBalanceVO o2) { o1 = o1 == null ? new QuotaBalanceVO() : o1; o2 = o2 == null ? new QuotaBalanceVO() : o2; return o2.getUpdatedOn().compareTo(o1.getUpdatedOn()); // desc } }); boolean have_balance_entries = false; //check that there is at least one balance entry for (Iterator<QuotaBalanceVO> it = quotaBalance.iterator(); it.hasNext();) { QuotaBalanceVO entry = it.next(); if (entry.isBalanceEntry()) { have_balance_entries = true; break; } } //if last entry is a credit deposit then remove that as that is already //accounted for in the starting balance after that entry, note the sort is desc if (have_balance_entries) { ListIterator<QuotaBalanceVO> li = quotaBalance.listIterator(quotaBalance.size()); // Iterate in reverse. while (li.hasPrevious()) { QuotaBalanceVO entry = li.previous(); if (s_logger.isDebugEnabled()) { s_logger.debug("createQuotaBalanceResponse: Entry=" + entry); } if (entry.getCreditsId() > 0) { li.remove(); } else { break; } } } int quota_activity = quotaBalance.size(); QuotaBalanceResponse resp = new QuotaBalanceResponse(); BigDecimal lastCredits = new BigDecimal(0); boolean consecutive = true; for (Iterator<QuotaBalanceVO> it = quotaBalance.iterator(); it.hasNext();) { QuotaBalanceVO entry = it.next(); if (s_logger.isDebugEnabled()) { s_logger.debug("createQuotaBalanceResponse: All Credit Entry=" + entry); } if (entry.getCreditsId() > 0) { if (consecutive) { lastCredits = lastCredits.add(entry.getCreditBalance()); } resp.addCredits(entry); it.remove(); } else { consecutive = false; } } if (quota_activity > 0 && quotaBalance.size() > 0) { // order is desc last item is the start item QuotaBalanceVO startItem = quotaBalance.get(quotaBalance.size() - 1); QuotaBalanceVO endItem = quotaBalance.get(0); resp.setStartDate(startDate); resp.setStartQuota(startItem.getCreditBalance()); resp.setEndDate(endDate); if (s_logger.isDebugEnabled()) { s_logger.debug("createQuotaBalanceResponse: Start Entry=" + startItem); s_logger.debug("createQuotaBalanceResponse: End Entry=" + endItem); } resp.setEndQuota(endItem.getCreditBalance().add(lastCredits)); } else if (quota_activity > 0) { // order is desc last item is the start item resp.setStartDate(startDate); resp.setStartQuota(new BigDecimal(0)); resp.setEndDate(endDate); resp.setEndQuota(new BigDecimal(0).add(lastCredits)); } else { resp.setStartDate(startDate); resp.setEndDate(endDate); resp.setStartQuota(new BigDecimal(0)); resp.setEndQuota(new BigDecimal(0)); } resp.setCurrency(QuotaConfig.QuotaCurrencySymbol.value()); resp.setObjectName("balance"); return resp; }
From source file:com.edgenius.wiki.render.macro.BaseMacro.java
/** * Move Iterator cursor backward or forward to given node. You must ensure then direction is correct! * This location will only following "forward inertia". <br> * "Inertia" means, if iterator goes previous, then next, the same cursor will return, likewise in next->previous. * (see {@link com.edgenius.wiki.gwt.client.html.TestHTMLNodeContainer#testIteratorAdd()}) <br> * //from w ww.j av a 2 s .c o m * This method will if call next(), it already return next HTMNode from current cursor. But if call previous(), * it returns current cursor at first time. * * @param node * @param iter * @param forward */ protected void moveIteratorCursorTo(HTMLNode node, ListIterator<HTMLNode> iter, boolean forward) { if (forward) { if (iter.hasNext()) { HTMLNode cursor = iter.next(); if (cursor.previous() != node) { //this is just ensure, iter current position is not equals with given node while (cursor != node && iter.hasNext()) { cursor = iter.next(); } } } } else { //backward if (iter.hasPrevious()) { HTMLNode cursor = iter.previous(); if (cursor.next() != node) { //this is just ensure, iter current position is not equals with given node while (cursor != node && iter.hasPrevious()) { cursor = iter.previous(); } } //delete inertia iter.next(); } } }
From source file:arun.com.chromer.webheads.WebHeadService.java
private void selectNextMaster() { final ListIterator<String> it = new ArrayList<>(webHeads.keySet()).listIterator(webHeads.size()); //noinspection LoopStatementThatDoesntLoop while (it.hasPrevious()) { final String key = it.previous(); final WebHead toBeMaster = webHeads.get(key); if (toBeMaster != null) { toBeMaster.setMaster(true);//from w ww. j a v a2 s.co m updateSpringChain(); toBeMaster.goToMasterTouchDownPoint(); } break; } }
From source file:arun.com.chromer.webheads.WebHeadService.java
private void openContextActivity() { final ListIterator<String> it = new ArrayList<>(webHeads.keySet()).listIterator(webHeads.size()); final ArrayList<Website> websites = new ArrayList<>(); while (it.hasPrevious()) { final String key = it.previous(); final WebHead webHead = webHeads.get(key); if (webHead != null) { websites.add(webHead.getWebsite()); }// w ww . ja va 2s. c om } ContextActivityHelper.open(this, websites); }
From source file:com.wolvereness.bluebutton.crash.ExceptionMessage.java
public Report(final String text) { final ArrayList<String> lines; { // _LINES_/*from w ww.ja va 2s . co m*/ int i; if ((i = text.indexOf('\r')) != -1) { if (text.startsWith("\r\n", i)) { // StartsWith prevents OOB exception lines = Splitter.splitAll(text, "\r\n"); } else { lines = Splitter.splitAll(text, '\r'); } } else { lines = Splitter.splitAll(text, '\n'); } } // _LINES_ final ImmutableMap.Builder<Nodes, Node> nodes = ImmutableMap.builder(); final ListIterator<String> it = lines.listIterator(lines.size() - 1); { // _DETAILS_ int count = 0; // Number of lines with no "- " for sub-listing while (true) { String entry = it.previous(); if (entry.startsWith(START)) { if (entry.startsWith(WORLD, 2)) { continue; // Process this at end } final int colon = entry.indexOf(':'); Nodes type = Nodes.valueOf(entry.substring(2, colon).toUpperCase().replace(' ', '_')); if (type == null) { type = Nodes._NA; } final List<String> subList = lines.subList(it.nextIndex(), it.nextIndex() + count); final Node node = type.makeNode(entry.substring(colon + 1), subList); nodes.put(type, node); count = 0; // Reset count, as it is used for sub-listing } else if (entry.equals(DETAILS_START)) { { final ArrayList<String> worlds = new ArrayList<String>(); while (it.hasNext()) { entry = it.next(); if (entry.startsWith(WORLD_START)) { worlds.add(entry); } } nodes.put(Nodes.WORLD, Nodes.WORLD.makeNode(null, worlds)); } while (!it.previous().equals(DETAILS_START)) { } if (!it.previous().equals("")) // NOTE_0- blank line preceding details check, see NOTE_0- below throw new IllegalStateException("Expected blank line in " + lines.toString()); while (!it.previous().startsWith(DESCRIPTION_START)) { } it.next(); // Description_start it.next(); // Blank line break; // We're done in the loop } else { count++; } } } // _DETAILS_ { // _STACK_ final LinkedList<ExceptionMessage> exceptions = new LinkedList<ExceptionMessage>(); final List<StackTraceElement> stacks = new ArrayList<StackTraceElement>(); final List<String> description = new ArrayList<String>(); description.add(it.next()); // Initialize; first line is always first exception for (String entry = it.next(); !entry.equals(DETAILS_START); entry = it.next()) { // Read in all the exception information. // Apocalypse if the formating changes... if (entry.startsWith(STACK_START)) { // Normal stack element stacks.add(toStackTraceElement(entry)); } else if (entry.startsWith(STACK_MORE_START)) { // "... n more" final line final ExceptionMessage previous = exceptions.getLast(); final List<StackTraceElement> previousTrace = previous.getStackTrace(); entry = entry.substring(STACK_MORE_START.length(), entry.length() - STACK_MORE_END.length()); final int stackCount = Integer.valueOf(entry); stacks.addAll(previousTrace.subList(previousTrace.size() - stackCount, previousTrace.size())); exceptions.add(new ExceptionMessage(description, stacks)); // Reset our counters description.clear(); stacks.clear(); } else if (entry.startsWith(CAUSED_START)) { // Finish old exception if (description.size() != 0) { exceptions.add(new ExceptionMessage(description, stacks)); description.clear(); stacks.clear(); } // New exception description.add(entry.substring(CAUSED_START.length())); } else { // Random description information description.add(entry); } } description.remove(description.size() - 1); // NOTE_0- There will be a blank line here, see NOTE_0- above if (description.size() != 0) { exceptions.add(new ExceptionMessage(description, stacks)); } this.exceptions = ImmutableList.copyOf(exceptions); } // _STACK_ while (!it.previous().startsWith(DESCRIPTION_START)) { } // This puts us on the line before the "description:" it.next(); // Push iterator for description_start to hit twice this.description = it.previous().substring(DESCRIPTION_START.length()); { // _TIMESTAMP_ final String timeStamp = it.previous().substring(TIME_START.length()); Date time = null; try { time = (Date) DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.parseObject(timeStamp); } catch (final ParseException ex) { try { time = new SimpleDateFormat().parse(timeStamp); } catch (final ParseException e) { } } this.time = time == null ? new Date(0l) : time; } // _TIMESTAMP_ it.previous(); // Blank line after joke this.fun = it.previous(); this.nodes = nodes.build(); }
From source file:org.commonjava.maven.ext.common.model.Project.java
private void resolveDeps(MavenSessionHandler session, List<Dependency> deps, boolean includeManagedDependencies, HashMap<ArtifactRef, Dependency> resolvedDependencies) throws ManipulationException { ListIterator<Dependency> iterator = deps.listIterator(deps.size()); // Iterate in reverse order so later deps take precedence while (iterator.hasPrevious()) { Dependency d = iterator.previous(); String g = PropertyResolver.resolveInheritedProperties(session, this, "${project.groupId}".equals(d.getGroupId()) ? getGroupId() : d.getGroupId()); String a = PropertyResolver.resolveInheritedProperties(session, this, "${project.artifactId}".equals(d.getArtifactId()) ? getArtifactId() : d.getArtifactId()); String v = PropertyResolver.resolveInheritedProperties(session, this, d.getVersion()); if (includeManagedDependencies && isEmpty(v)) { v = "*"; }//from w w w. ja v a 2 s . c o m if (isNotEmpty(g) && isNotEmpty(a) && isNotEmpty(v)) { SimpleArtifactRef sar = new SimpleArtifactRef(g, a, v, d.getType(), d.getClassifier()); // If the GAVTC already exists within the map it means we have a duplicate entry. While Maven // technically allows this it does warn that this leads to unstable models. In PME case this breaks // the indexing as we don't have duplicate entries. Given they are exact matches, remove older duplicate. if (resolvedDependencies.containsKey(sar)) { logger.error("Found duplicate entry within dependency list. Key of {} and dependency {}", sar, d); iterator.remove(); } else { Dependency old = resolvedDependencies.put(sar, d); if (old != null) { logger.error( "Internal project dependency resolution failure ; replaced {} in store by {}:{}:{}.", old, g, a, v); throw new ManipulationException( "Internal project dependency resolution failure ; replaced " + old + " by " + d); } } } } }
From source file:org.commonjava.maven.ext.common.model.Project.java
private void resolvePlugins(MavenSessionHandler session, List<Plugin> plugins, HashMap<ProjectVersionRef, Plugin> resolvedPlugins) throws ManipulationException { ListIterator<Plugin> iterator = plugins.listIterator(plugins.size()); // Iterate in reverse order so later plugins take precedence while (iterator.hasPrevious()) { Plugin p = iterator.previous(); String g = PropertyResolver.resolveInheritedProperties(session, this, "${project.groupId}".equals(p.getGroupId()) ? getGroupId() : p.getGroupId()); String a = PropertyResolver.resolveInheritedProperties(session, this, "${project.artifactId}".equals(p.getArtifactId()) ? getArtifactId() : p.getArtifactId()); String v = PropertyResolver.resolveInheritedProperties(session, this, p.getVersion()); // Its possible the internal plugin list is either abbreviated or empty. Attempt to fill in default values for // comparison purposes. if (isEmpty(g)) { g = PLUGIN_DEFAULTS.getDefaultGroupId(a); }//from ww w.j av a 2s . c om // Theoretically we could default an empty v via PLUGIN_DEFAULTS.getDefaultVersion( g, a ) but // this means managed plugins would be included which confuses things. if (isNotEmpty(g) && isNotEmpty(a) && isNotEmpty(v)) { SimpleProjectVersionRef spv = new SimpleProjectVersionRef(g, a, v); // If the GAV already exists within the map it means we have a duplicate entry. While Maven // technically allows this it does warn that this leads to unstable models. In PME case this breaks // the indexing as we don't have duplicate entries. Given they are exact matches, remove older duplicate. if (resolvedPlugins.containsKey(spv)) { logger.error("Found duplicate entry within plugin list. Key of {} and plugin {}", spv, p); iterator.remove(); } else { Plugin old = resolvedPlugins.put(spv, p); if (old != null) { logger.error("Internal project plugin resolution failure ; replaced {} in store by {}.", old, spv); throw new ManipulationException( "Internal project plugin resolution failure ; replaced " + old + " by " + spv); } } } } }
From source file:com.quigley.filesystem.FilesystemPath.java
public FilesystemPath simplify() { List<String> elementsCopy = new ArrayList<String>(elements); ListIterator<String> i = elementsCopy.listIterator(); boolean saw = false; while (i.hasNext()) { String value = i.next();//from ww w.j a v a 2s . co m if (value.equals(".")) { i.remove(); } else if (value.equals("..")) { if (saw) { if (i.hasPrevious()) { i.remove(); i.previous(); i.remove(); } } } else { saw = true; } } FilesystemPath pathCopy = new FilesystemPath(elementsCopy); pathCopy.isAbsolute = isAbsolute; return pathCopy; }