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:com.bonsai.btcreceive.HDChain.java

private int marginSize() {
    int count = 0;
    ListIterator li = mAddrs.listIterator(mAddrs.size());
    while (li.hasPrevious()) {
        HDAddress hda = (HDAddress) li.previous();
        if (!hda.isUnused())
            return count;
        ++count;/*from   w w w . java 2  s  .com*/
    }
    return count;
}

From source file:org.apache.openjpa.kernel.exps.CandidatePath.java

public FieldMetaData last() {
    if (_actions == null)
        return null;

    ListIterator itr = _actions.listIterator(_actions.size());
    Object prev;/*  w w  w. j  a  v a  2  s . co m*/
    while (itr.hasPrevious()) {
        prev = itr.previous();
        if (prev instanceof Traversal)
            return ((Traversal) prev).field;
    }
    return null;
}

From source file:org.apache.fop.layoutmgr.inline.FootnoteLayoutManager.java

/**
 * Find the last box in the sequence, and add a reference to the FootnoteBodyLM
 * @param citationList the list of elements representing the footnote citation
 *//*from   w  w w  .  j a  v a 2s  .  c  om*/
private void addAnchor(List citationList) {
    KnuthInlineBox lastBox = null;
    // the list of elements is searched backwards, until we find a box
    ListIterator citationIterator = citationList.listIterator(citationList.size());
    while (citationIterator.hasPrevious() && lastBox == null) {
        Object obj = citationIterator.previous();
        if (obj instanceof KnuthElement) {
            // obj is an element
            KnuthElement element = (KnuthElement) obj;
            if (element instanceof KnuthInlineBox) {
                lastBox = (KnuthInlineBox) element;
            }
        } else {
            // obj is a sequence of elements
            KnuthSequence seq = (KnuthSequence) obj;
            ListIterator nestedIterator = seq.listIterator(seq.size());
            while (nestedIterator.hasPrevious() && lastBox == null) {
                KnuthElement element = (KnuthElement) nestedIterator.previous();
                if (element instanceof KnuthInlineBox && !element.isAuxiliary() || element == forcedAnchor) {
                    lastBox = (KnuthInlineBox) element;
                }
            }
        }
    }
    if (lastBox != null) {
        lastBox.setFootnoteBodyLM(bodyLM);
    } else {
        //throw new IllegalStateException("No anchor box was found for a footnote.");
    }
}

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  .  ja va2 s .  co 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:se.uu.it.cs.recsys.ruleminer.impl.FPGrowthImpl.java

private Map<Set<Integer>, Integer> miningWithFPGrowth(FPTree fpTree, Set<Integer> suffixPattern) {

    Map<Set<Integer>, Integer> frequentPatternFromSinglePrefixPath = new HashMap<>();
    FPTree branchingTree = fpTree;/*www. jav  a2  s  .co  m*/

    if (fpTree.hasSinglePrefixPath()) {
        List<Item> singlePrefixPath = fpTree.getSinglePrefixPathInTopDownOrder();
        //            LOGGER.debug("Single prefix path: {}", singlePrefixPath);

        Map<Set<Integer>, Integer> frequentPatternWithinSinglePrefixPath = getFrequentPatternFromSinglePrefixPath(
                singlePrefixPath);

        frequentPatternFromSinglePrefixPath = frequentPatternWithinSinglePrefixPath.entrySet().stream()
                .collect(Collectors.toMap(entry -> {
                    Set<Integer> existingPattern = new HashSet<>(entry.getKey());
                    existingPattern.addAll(suffixPattern);
                    return existingPattern;
                }, entry -> entry.getValue()));

        branchingTree = fpTree.getBranchingTree();

        if (branchingTree == null) {
            return frequentPatternFromSinglePrefixPath;
        }
    }

    Map<Set<Integer>, Integer> frequentPatternFromBranchingTree = new HashMap<>();

    List<HeaderTableItem> headerList = branchingTree.getHeaderTable();
    ListIterator<HeaderTableItem> itr = headerList.listIterator(headerList.size());

    while (itr.hasPrevious()) {
        HeaderTableItem visitingItem = itr.previous();

        Set<Integer> newPattern = new HashSet<>(suffixPattern);
        newPattern.add(visitingItem.getItem().getId());

        frequentPatternFromBranchingTree.put(newPattern, visitingItem.getItem().getCount());
        //            LOGGER.debug("Adding new pattern: {}, count: {}", newPattern, visitingItem.getItem().getCount());

        Map<List<Integer>, Integer> patternBase = FPTreeUtil.getPatternBase(visitingItem);
        //            LOGGER.debug("Pattern base for item {} is: {}", visitingItem.getItem(), patternBase);

        FPTree conditionalTree = FPTreeBuilder.buildConditionalFPTree(patternBase, this.minSupport);

        if (conditionalTree != null && !conditionalTree.getRoot().getChildren().isEmpty()) {
            frequentPatternFromBranchingTree.putAll(miningWithFPGrowth(conditionalTree, newPattern));
        }
    }

    return consolidatePatterns(frequentPatternFromSinglePrefixPath, frequentPatternFromBranchingTree);
}

From source file:fr.norad.visuwall.core.business.process.capabilities.BuildCapabilityProcess.java

public void updateLastNotBuildingId(Project project) throws ProjectNotFoundException {
    ListIterator<String> reverseBuildIt = project.getBuildId().listIterator(project.getBuildId().size());
    while (reverseBuildIt.hasPrevious()) {
        String buildId = reverseBuildIt.previous();
        Build build = getCreatedWithContentBuild(project, buildId);
        if (build.isBuilding()) {
            continue;
        }/*w ww .j  a  va  2  s .  c  o  m*/
        project.setLastNotBuildingId(buildId);
        break;
    }
}

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);
        }/*w ww.  j av a2s. 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.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;
            }//w ww.j av  a 2  s .  c o m
            _cursor = 0;
            _messages = messages;
        }
        _maxMessages = maxMessages;
    }
}

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(() -> {//www  . ja va2  s.  com
            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:bigtweet.BTSim.java

/**
*
* @param na number of agents/*from  w  w  w .j a  va 2  s.  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;

}