Example usage for java.util ListIterator hasPrevious

List of usage examples for java.util ListIterator hasPrevious

Introduction

In this page you can find the example usage for java.util ListIterator hasPrevious.

Prototype

boolean hasPrevious();

Source Link

Document

Returns true if this list iterator has more elements when traversing the list in the reverse direction.

Usage

From source file:org.xchain.impl.CommandList.java

public boolean execute(JXPathContext context) throws Exception {
    // Verify our parameters
    if (context == null) {
        throw new IllegalArgumentException();
    }/*from   ww  w  .j  a  v a  2  s  .c  o m*/

    // Execute the commands in this list until one returns true
    // or throws an exception
    boolean saveResult = false;
    Exception saveException = null;
    ListIterator<Command> iterator = listIterator();
    while (iterator.hasNext()) {
        try {
            saveResult = iterator.next().execute(context);
            if (saveResult) {
                break;
            }
        } catch (Exception e) {
            saveException = e;
            break;
        }
    }

    boolean handled = false;
    boolean result = false;
    while (iterator.hasPrevious()) {
        Object previous = iterator.previous();
        if (previous instanceof Filter) {
            try {
                result = ((Filter) previous).postProcess(context, saveException);
                if (result) {
                    handled = true;
                }
            } catch (Exception e) {
                // Silently ignore
            }
        }
    }

    // Return the exception or result state from the last execute()
    if ((saveException != null) && !handled) {
        throw saveException;
    } else {
        return (saveResult);
    }
}

From source file:org.flowable.cmmn.converter.ConversionHelper.java

public void addEntryCriterionToCurrentElement(Criterion entryCriterion) {
    addEntryCriterion(entryCriterion);/*from w w  w  .j a  v a 2  s .c om*/

    ListIterator<CmmnElement> iterator = currentCmmnElements.listIterator(currentCmmnElements.size());
    HasEntryCriteria hasEntryCriteria = null;
    while (hasEntryCriteria == null && iterator.hasPrevious()) {
        CmmnElement cmmnElement = iterator.previous();
        if (cmmnElement instanceof HasEntryCriteria) {
            hasEntryCriteria = (HasEntryCriteria) cmmnElement;
        }
    }
    if (hasEntryCriteria != null) {

        if (StringUtils.isEmpty(entryCriterion.getId())) {
            // An id is expected by the evaluation algorithm, so setting an internal one if there isn't one
            entryCriterion.setId("entryCriterion_" + (hasEntryCriteria.getEntryCriteria().size() + 1));
        }

        entryCriterion.setAttachedToRefId(hasEntryCriteria.getId());
        hasEntryCriteria.getEntryCriteria().add(entryCriterion);

    } else {
        throw new FlowableException("Cannot add an entry criteria " + entryCriterion.getId()
                + " no matching plan item found to attach it to");
    }
}

From source file:org.netflux.core.Record.java

/**
 * Removes from this record all the field metadata and all the fields with names included in the supplied collection.
 * //from  www.j a  v  a  2  s. com
 * @param fieldNames the names of the field metadata and fields to remove.
 * @throws NullPointerException if the specified collection is <code>null</code>.
 */
public void remove(Collection<String> fieldNames) {
    List<String> fieldsToRemove = new LinkedList<String>(this.metadata.getFieldNames());
    fieldsToRemove.retainAll(fieldNames);

    ListIterator<String> fieldIndexIterator = fieldsToRemove.listIterator(fieldsToRemove.size());
    while (fieldIndexIterator.hasPrevious()) {
        this.data.remove(fieldIndexIterator.previous());
    }

    this.metadata.remove(fieldNames);
}

From source file:org.apache.stratos.autoscaler.service.util.IaasContext.java

/**
 * This will return the public IP of the node which is belong to the
 * requesting domain, sub domain and which is the most recently created. If it cannot find a
 * matching public IP, this will return <code>null</code>.
 * @param domain service domain. //w ww  .  j a  v  a  2 s .  com
 * @param subDomain service sub domain. 
 * @return the public IP of the node
 */
public String getLastMatchingPublicIp(String domain, String subDomain) {

    InstanceContext ctx = getInstanceContext(domain, subDomain);

    if (ctx == null) {
        return null;
    }

    // iterate in reverse order
    ListIterator<String> iter = new ArrayList<String>(ctx.getNodeIdToIpMap().keySet())
            .listIterator(ctx.getNodeIdToIpMap().size());

    while (iter.hasPrevious()) {
        return ctx.getNodeIdToIpMap().get(iter.previous());
    }

    return null;

    //        // traverse from the last entry of the map
    //        ListIterator<Map.Entry<String, String>> iter =
    //            new ArrayList<Entry<String, String>>(publicIpToDomainMap.entrySet()).
    //                                listIterator(publicIpToDomainMap.size());
    //
    //        while (iter.hasPrevious()) {
    //            Map.Entry<String, String> entry = iter.previous();
    //            if (entry.getValue().equals(domain)) {
    //                return entry.getKey();
    //            }
    //        }
    //        
    //        return null;
}

From source file:org.broadinstitute.gatk.tools.walkers.haplotypecaller.graphs.Path.java

/**
  * Checks whether a given path is a suffix of this path.
  */*from  www .  j a  v  a 2s .  c o m*/
  * @param other the path to compare against.
  * @throws IllegalArgumentException if <code>other</code> is <code>null</code>, or the come from
  *   different graphs.
  * @return true if <code>other</code> is a suffix of this path.
  */
public boolean isSuffix(final Path<T, E> other) {
    if (other == null)
        throw new IllegalArgumentException("path cannot be null");
    if (other.getGraph() != this.getGraph())
        throw new IllegalArgumentException("the other path most belong to the same path");
    if (!lastVertex.equals(other.lastVertex))
        return false;
    final ListIterator<E> myIt = edgesInOrder.listIterator(edgesInOrder.size());
    final ListIterator<E> otherIt = other.edgesInOrder.listIterator(other.edgesInOrder.size());
    while (myIt.hasPrevious() && otherIt.hasPrevious())
        if (otherIt.previous() != myIt.previous())
            return false;
    return !otherIt.hasPrevious();
}

From source file:edu.csun.ecs.cs.multitouchj.ui.graphic.WindowManager.java

private void dispatchObjectEventControls(ObjectEvent objectEvent) {
    List<Control> cursors = null;
    synchronized (cursorHandler) {
        cursors = cursorHandler.getCursors();
    }/*  ww  w . ja v  a  2 s  .  c  om*/

    Control activeControl = null;
    LinkedList<ObjectObserverEvent> consumedOoes = new LinkedList<ObjectObserverEvent>();
    ListIterator<Control> listIterator = controls.listIterator(controls.size());
    while (listIterator.hasPrevious()) {
        Control control = listIterator.previous();
        if ((!control.isVisible()) || (cursors.contains(control))) {
            continue;
        }

        ObjectEvent copiedObjectEvent = objectEvent.copy();
        // check how many of Ooes are within this control
        LinkedList<ObjectObserverEvent> ooes = new LinkedList<ObjectObserverEvent>();
        for (ObjectObserverEvent ooe : objectEvent.getObjectObserverEvents()) {
            if (!consumedOoes.contains(ooe)) {
                if (control.isWithin(new Point(ooe.getX(), ooe.getY()))) {
                    ooes.add(ooe);
                    consumedOoes.add(ooe);
                }
            }
        }
        copiedObjectEvent.setObjectObserverEvents(ooes);

        ObjectObserverEvent targetOoe = objectEvent.getTargetObjectObserverEvent();
        if (ooes.contains(targetOoe)) {
            activeControl = control;
        } else {
            targetOoe = null;
        }
        copiedObjectEvent.setTargetObjectObserverEvent(targetOoe);

        //log.debug("Ooes: "+ooes.size());
        if (ooes.size() > 0) {
            log.debug(control.getClass().toString() + "[" + control.getPosition().toString() + "]"
                    + ": Sending " + ooes.size() + " ooes");
            control.dispatchEvent(copiedObjectEvent);
        }
    }

    if ((activeControl != null) && (!activeControl.equals(backgroundControl))) {
        if (!activeControl.equals(controls.getLast())) {
            controls.remove(activeControl);
            controls.add(activeControl);
        }
    }
}

From source file:org.apache.cocoon.components.pipeline.impl.CachingPointProcessingPipeline.java

/**
 * Cache longest cacheable path plus cache points.
 *//* www .  j av  a 2  s.c  om*/
protected void cacheResults(Environment environment, OutputStream os) throws Exception {

    if (this.toCacheKey != null) {
        if (this.cacheCompleteResponse) {
            if (this.getLogger().isDebugEnabled()) {
                this.getLogger().debug("Cached: caching complete response; pSisze" + this.toCacheKey.size()
                        + " Key " + this.toCacheKey);
            }
            CachedResponse response = new CachedResponse(this.toCacheSourceValidities,
                    ((CachingOutputStream) os).getContent());
            response.setContentType(environment.getContentType());
            this.cache.store(this.toCacheKey.copy(), response);
            //
            // Scan back along the pipelineCacheKey for
            // for any cachepoint(s)
            //
            this.toCacheKey.removeUntilCachePoint();

            //
            // adjust the validities object
            // to reflect the new length of the pipeline cache key.
            //
            // REVISIT: Is it enough to simply reduce the length of the validities array?
            //
            if (this.toCacheKey.size() > 0) {
                SourceValidity[] copy = new SourceValidity[this.toCacheKey.size()];
                System.arraycopy(this.toCacheSourceValidities, 0, copy, 0, copy.length);
                this.toCacheSourceValidities = copy;
            }
        }

        if (this.toCacheKey.size() > 0) {
            ListIterator itt = this.xmlSerializerArray.listIterator(this.xmlSerializerArray.size());
            while (itt.hasPrevious()) {
                XMLSerializer serializer = (XMLSerializer) itt.previous();
                CachedResponse response = new CachedResponse(this.toCacheSourceValidities,
                        (byte[]) serializer.getSAXFragment());
                this.cache.store(this.toCacheKey.copy(), response);

                if (this.getLogger().isDebugEnabled()) {
                    this.getLogger().debug("Caching results for the following key: " + this.toCacheKey);
                }

                //
                // Check for further cachepoints
                //
                toCacheKey.removeUntilCachePoint();
                if (this.toCacheKey.size() == 0)
                    // no cachePoint found in key
                    break;

                //
                // re-calculate validities array
                //
                SourceValidity[] copy = new SourceValidity[this.toCacheKey.size()];
                System.arraycopy(this.toCacheSourceValidities, 0, copy, 0, copy.length);
                this.toCacheSourceValidities = copy;
            } //end serializer loop
        }
    }
}

From source file:org.jboss.set.aphrodite.repository.services.github.GithubPullRequestHomeService.java

private GHPullRequestReview findReviewStateByUser(PullRequest pullRequest, GHUser user) {
    URL url = pullRequest.getURL();
    int pullRequestId = Integer.parseInt(pullRequest.getId());
    String repositoryId = createRepositoryIdFromUrl(url);
    try {// w ww .jav a  2 s  .com
        GHRepository repository = github.getRepository(repositoryId);
        GHPullRequest ghPullRequest = repository.getPullRequest(pullRequestId);
        List<GHPullRequestReview> reviews = ghPullRequest.listReviews().asList();
        ListIterator<GHPullRequestReview> li = reviews.listIterator(reviews.size());
        // Iterate in reverse. created date and updated date are always Null, Is this really safe?
        while (li.hasPrevious()) {
            GHPullRequestReview review = li.previous();
            if (review.getUser().equals(user))
                return review;
        }
    } catch (IOException e) {
        Utils.logException(LOG, e);
    }
    return null;
}

From source file:org.xchain.impl.ChainImpl.java

public boolean execute(JXPathContext context) throws Exception {
    // Verify our parameters
    if (context == null) {
        throw new IllegalArgumentException();
    }//from w w w  .  j  a  va  2s .  c o  m

    // Execute the commands in this list until one returns true
    // or throws an exception
    boolean saveResult = false;
    Exception saveException = null;
    ListIterator<Command> iterator = commandList.listIterator();
    while (iterator.hasNext()) {
        try {
            saveResult = iterator.next().execute(context);
            if (saveResult) {
                break;
            }
        } catch (Exception e) {
            saveException = e;
            break;
        }
    }

    boolean handled = false;
    boolean result = false;
    while (iterator.hasPrevious()) {
        Object previous = iterator.previous();
        if (previous instanceof Filter) {
            try {
                result = ((Filter) previous).postProcess(context, saveException);
                if (result) {
                    handled = true;
                }
            } catch (Exception e) {
                // Silently ignore
            }
        }
    }

    // Return the exception or result state from the last execute()
    if ((saveException != null) && !handled) {
        throw saveException;
    } else {
        return (saveResult);
    }
}

From source file:org.echocat.jomon.maven.boot.ArtifactFactory.java

@Nullable
protected String selectLatestMatchingVersion(@Nonnull ArtifactRepositoryMetadata repositoryMetadata,
        @Nonnull Artifact artifact) {/*from   w  w  w.  j av a 2s  .  c o  m*/
    final Metadata metadata = repositoryMetadata.getMetadata();
    String latestMatchingVersion = null;
    final Versioning versioning = metadata.getVersioning();
    if (versioning != null) {
        final List<String> versions = versioning.getVersions();
        final ListIterator<String> i = versions.listIterator(versions.size());
        final VersionRange versionRange = artifact.getVersionRange();
        while (i.hasPrevious() && isEmpty(latestMatchingVersion)) {
            final String current = i.previous();
            if (versionRange.containsVersion(new DefaultArtifactVersion(current))) {
                latestMatchingVersion = current;
            }
        }
    }
    return latestMatchingVersion;
}