List of usage examples for java.util ListIterator previous
E previous();
From source file:com.diffplug.gradle.GradleIntegrationTest.java
protected String getContents(Predicate<String> subpathsToInclude) throws IOException { TreeDef<File> treeDef = TreeDef.forFile(Errors.rethrow()); List<File> files = TreeStream.depthFirst(treeDef, folder.getRoot()).filter(file -> file.isFile()) .collect(Collectors.toList()); ListIterator<File> iterator = files.listIterator(files.size()); int rootLength = folder.getRoot().getAbsolutePath().length() + 1; return StringPrinter.buildString(printer -> { Errors.rethrow().run(() -> {/*from ww w. j a va 2 s . c om*/ while (iterator.hasPrevious()) { File file = iterator.previous(); String subPath = file.getAbsolutePath().substring(rootLength); if (subpathsToInclude.test(subPath)) { printer.println("### " + subPath + " ###"); printer.println(read(subPath)); } } }); }); }
From source file:org.cipango.callflow.diameter.JmxMessageLogger.java
public void setMaxMessages(int maxMessages) { if (maxMessages <= 0) throw new IllegalArgumentException("Max message must be greater than 0"); synchronized (this) { if (isRunning() && maxMessages != _maxMessages) { MessageInfo[] messages = new MessageInfo[maxMessages]; ListIterator<MessageInfo> it = iterate(false); int index = maxMessages; while (it.hasPrevious()) { messages[--index] = it.previous(); if (index == 0) break; }//from w w w . j a v a2 s. c om _cursor = 0; _messages = messages; } _maxMessages = maxMessages; } }
From source file:fr.paris.lutece.plugins.workflow.modules.ticketing.service.task.TaskReplyAssignUpTicket.java
/** * Get the user assigning up the ticket corresponding to the resource of the resourceHistory id * @param nIdResourceHistory the resourceHistory id * @return the user assigning up the ticket corresponding to the resource of the resourceHistory id , {@code null} otherwise *//*from w w w .j av a 2 s. c o m*/ protected AdminUser getAssigner(int nIdResourceHistory) { ResourceHistory resourceHistory = _resourceHistoryService.findByPrimaryKey(nIdResourceHistory); List<Integer> listIdResource = new ArrayList<Integer>(); listIdResource.add(resourceHistory.getIdResource()); List<Integer> listIdHistory = _resourceHistoryService.getListHistoryIdByListIdResourceId(listIdResource, resourceHistory.getResourceType(), resourceHistory.getWorkflow().getId()); boolean isAssignUpActionFound = false; ListIterator<Integer> iterator = listIdHistory.listIterator(listIdHistory.size()); while (!isAssignUpActionFound && iterator.hasPrevious()) { resourceHistory = _resourceHistoryService.findByPrimaryKey(iterator.previous()); if ((resourceHistory.getAction().getId() == ASSIGN_UP_ACTION_ID) || (resourceHistory.getAction().getId() == ASSIGN_TO_UNIT_ACTION_ID)) { isAssignUpActionFound = true; } } return (isAssignUpActionFound ? AdminUserHome.findUserByLogin(resourceHistory.getUserAccessCode()) : null); }
From source file:org.cipango.callflow.diameter.JmxMessageLogger.java
@SuppressWarnings("unchecked") private List<MessageInfo> getMessageList(Integer maxMessages, String msgFilter) throws Exception { if (_messages == null) return null; synchronized (this) { JexlContext jc = JexlHelper.createContext(); Expression msgExpression = null; if (msgFilter != null && !msgFilter.trim().equals("")) { LOG.debug("Get messages with filter: " + msgFilter); msgExpression = ExpressionFactory.createExpression("log." + msgFilter); }//from w w w .j a va 2 s . c o m List<MessageInfo> result = new ArrayList<MessageInfo>(); ListIterator<MessageInfo> it = iterate(false); int i = 0; while (it.hasPrevious() && i < maxMessages) { MessageInfo info = it.previous(); jc.getVars().put("log", info); jc.getVars().put("message", info.getMessage()); if (msgExpression == null || ((Boolean) msgExpression.evaluate(jc)).booleanValue()) { result.add(0, info); i++; } } return result; } }
From source file:org.xchain.framework.lifecycle.Lifecycle.java
/** * Start all lifecycle steps found by the LifecycleStepScanner. * //from ww w . ja va 2 s . c om * @throws LifecycleException If an exception was encountered attempting to start the lifecycle steps. * @see LifecycleStepScanner */ private static void startLifecycleSteps() throws LifecycleException { // Create a scanner to find the lifecycle steps in the current classpath. LifecycleStepScanner scanner = new LifecycleStepScanner(context); try { scanner.scan(); lifecycleStepList = scanner.getLifecycleStepList(); } catch (ScanException se) { throw new LifecycleException("An exception was thrown while scanning for lifecycle steps.", se); } if (log.isInfoEnabled()) { StringBuilder message = new StringBuilder(); message.append("Found ").append(lifecycleStepList.size()).append(" lifecycle steps:\n"); for (LifecycleStep lifecycleStep : lifecycleStepList) { message.append(" ").append(lifecycleStep.getQName()).append("\n"); } log.info(message.toString()); } // Start all the found lifecycle steps. ListIterator<LifecycleStep> iterator = lifecycleStepList.listIterator(); try { while (iterator.hasNext()) { LifecycleStep lifecycleStep = iterator.next(); if (log.isInfoEnabled()) { log.info("Starting Lifecycle Step '" + lifecycleStep.getQName() + "'."); } lifecycleStep.startLifecycle(context, Lifecycle.configDocumentContext); if (log.isInfoEnabled()) { log.info("Finished Lifecycle Step '" + lifecycleStep.getQName() + "'."); } } } catch (LifecycleException le) { if (log.isErrorEnabled()) { log.error("Stopping the lifecycle startup due to a lifecycle exception.", le); } iterator.previous(); while (iterator.hasPrevious()) { LifecycleStep lifecycleStep = iterator.previous(); try { lifecycleStep.stopLifecycle(context); } catch (Throwable t) { if (log.isWarnEnabled()) { log.warn("An exception was thrown while stopping a lifecycle exception.", t); } } } // clear the lifecycle step list. lifecycleStepList.clear(); // we should throw the lifecycle exception here. throw le; } finally { // make sure the configuration DOM gets garbage collected, no reason to keep it around once everyone is configured. Lifecycle.configDocumentContext = null; } }
From source file:bigtweet.BTSim.java
/** * * @param na number of agents/*from w ww . ja v a 2s . c o m*/ * @param selectingMethod: , last, or first in the list of agents. (or null, * random, to random) * @param exceptState agents except of that state, can be null * @return */ public List<UserAgent> getNUsers(int na, String selectingMethod, String exceptState) { List<UserAgent> r = new ArrayList<UserAgent>(); UserAgent aux; int added = 0; switch (selectingMethod) { case "last": ListIterator<UserAgent> li = getAgents().listIterator(getAgents().size()); while (li.hasPrevious() && added < na) { aux = li.previous(); if (exceptState == null || !aux.getState().equals(exceptState)) { r.add(aux); added++; } } if (added < na) { throw new RuntimeException("There is no " + na + " agents to be added."); } break; case "first": li = getAgents().listIterator(); while (li.hasNext() && added < na) { aux = li.next(); if (exceptState == null || !aux.getState().equals(exceptState)) { r.add(aux); added++; } } if (added < na) { throw new RuntimeException("There is no " + na + " agents to be added."); } break; default: r = getNRandomUsers(na, exceptState); } return r; }
From source file:org.apache.fop.render.AbstractImageHandlerRegistry.java
/** * Add an image handler. The handler itself is inspected to find out what it supports. * @param handler the ImageHandler instance *//* ww w. ja v a 2s . c o m*/ public synchronized void addHandler(ImageHandlerBase handler) { this.handlers.put(handler.getSupportedImageClass(), handler); //Sorted insert ListIterator iter = this.handlerList.listIterator(); while (iter.hasNext()) { ImageHandlerBase h = (ImageHandlerBase) iter.next(); if (getHandlerComparator().compare(handler, h) < 0) { iter.previous(); break; } } iter.add(handler); this.handlerRegistrations++; }
From source file:com.cloudera.sqoop.cli.SqoopParser.java
@Override /**//ww w .j a v a 2 s.c om * Processes arguments to options but only strips matched quotes. */ public void processArgs(Option opt, ListIterator iter) throws ParseException { // Loop until an option is found. while (iter.hasNext()) { String str = (String) iter.next(); if (getOptions().hasOption(str) && str.startsWith("-")) { // found an Option, not an argument. iter.previous(); break; } // Otherwise, this is a value. try { // Note that we only strip matched quotes here. addValForProcessing.invoke(opt, stripMatchedQuotes(str)); } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (java.lang.reflect.InvocationTargetException ite) { // Any runtime exception thrown within addValForProcessing() // will be wrapped in an InvocationTargetException. iter.previous(); break; } catch (RuntimeException re) { iter.previous(); break; } } if (opt.getValues() == null && !opt.hasOptionalArg()) { throw new MissingArgumentException(opt); } }
From source file:fr.norad.visuwall.core.business.process.capabilities.BuildCapabilityProcess.java
public void updatePreviousCompletedBuild(Project project) throws ProjectNotFoundException { List<String> buildIds = project.getBuildId(); if (buildIds.size() < 2) { // with only a build there is no previous completed build return;/* w w w . j a v a 2 s . co m*/ } try { int skip = 1; if (project.getLastBuild().isBuilding()) { if (buildIds.size() < 3) { // first build is building so we do not have enough builds to have a previous completed return; } skip = 2; } ListIterator<String> reverseBuildIt = project.getBuildId().listIterator(project.getBuildId().size()); for (int i = 0; reverseBuildIt.hasPrevious(); i++) { String buildId = reverseBuildIt.previous(); if (i < skip) { continue; } Build build = getCreatedWithContentBuild(project, buildId); if (build == null) { continue; } BuildState state = build.getState(); if (state == BuildState.UNKNOWN || state == BuildState.ABORTED) { continue; } project.setPreviousCompletedBuildId(build.getBuildId()); break; } } catch (BuildNotFoundException e) { LOG.warn("last build not found to update previous completed build", e); } }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushSelectIntoJoinRule.java
private void pushOps(List<ILogicalOperator> opList, Mutable<ILogicalOperator> joinBranch, IOptimizationContext context) throws AlgebricksException { ILogicalOperator topOp = joinBranch.getValue(); ListIterator<ILogicalOperator> iter = opList.listIterator(opList.size()); while (iter.hasPrevious()) { ILogicalOperator op = iter.previous(); List<Mutable<ILogicalOperator>> opInpList = op.getInputs(); opInpList.clear();//from w ww . j a v a2s .c o m opInpList.add(new MutableObject<ILogicalOperator>(topOp)); topOp = op; context.computeAndSetTypeEnvironmentForOperator(op); } joinBranch.setValue(topOp); }