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.mbari.aved.ui.classifier.knowledgebase.SearchableConceptTreePanel.java

/**
 * Loads the branch of a particular concept. This method does the following
 * <ol>//from  w w  w.j  a va 2 s .co  m
 *      <li>Walks from the concept up the tree to the root concept, storing
 *      the concepts in a list. (This is very fast)</li>
 *  <li>Starts walking from the root down (using lazyExpand), searching each
 *      childnode for a matching primary name (which was stored in the first
 *      step</li>
 *  <li>If a matching primary name is found this stops otherwise
 *              it opens the next level and searches for the next mathc in the list.</li>
 *  <li></li>
 * </ol>
 * @param concept
 */
private void openNode(final Concept concept) {
    if (log.isDebugEnabled()) {
        log.debug("Opening node containing " + concept);
    }

    if (concept == null) {
        return;
    }

    // Get the list of concepts up to root
    final LinkedList conceptList = new LinkedList();
    Concept c = concept;

    while (c != null) {
        conceptList.add(c);
        c = (Concept) c.getParentConcept();
    }

    // Walk the tree from root on down opening nodes as we go
    final ListIterator i = conceptList.listIterator(conceptList.size());

    // Skip the root
    i.previous();

    final JTree tree = getJTree();
    final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();
    final DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel.getRoot();
    TreePath path = new TreePath(rootNode.getPath());

    tree.setSelectionPath(path);

    DefaultMutableTreeNode parentNode = rootNode;

    while (i.hasPrevious()) {
        c = (Concept) i.previous();

        final TreeConcept parentTreeConcept = (TreeConcept) parentNode.getUserObject();

        parentTreeConcept.lazyExpand(parentNode);

        // treeModel.reload(parentNode);
        final Enumeration enm = parentNode.children();

        while (enm.hasMoreElements()) {
            final DefaultMutableTreeNode node = (DefaultMutableTreeNode) enm.nextElement();
            final TreeConcept tc = (TreeConcept) node.getUserObject();

            if (tc.getName().equals(c.getPrimaryConceptNameAsString())) {
                parentNode = node;

                break;
            }
        }
    }

    final TreeNode _parentNode = parentNode;

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            treeModel.reload(_parentNode);
            tree.scrollPathToVisible(new TreePath(_parentNode));
        }
    });
}

From source file:org.springframework.ldap.core.DistinguishedName.java

/**
 * Determines if this <code>DistinguishedName</code> ends with a certian
 * path.//from   w w w. j a v a2  s  .co  m
 * 
 * If the argument path is empty (no names in path) this method will return
 * <code>false</code>.
 * 
 * @param name The suffix to check for.
 * 
 */
public boolean endsWith(Name name) {
    DistinguishedName path = null;
    if (name instanceof DistinguishedName) {
        path = (DistinguishedName) name;
    } else {
        return false;
    }

    List shortlist = path.getNames();

    // this path must be at least as long
    if (getNames().size() < shortlist.size())
        return false;

    // must have names
    if (shortlist.size() == 0)
        return false;

    ListIterator longiter = getNames().listIterator(getNames().size());
    ListIterator shortiter = shortlist.listIterator(shortlist.size());

    while (shortiter.hasPrevious()) {
        LdapRdn longname = (LdapRdn) longiter.previous();
        LdapRdn shortname = (LdapRdn) shortiter.previous();

        if (!longname.equals(shortname))
            return false;
    }

    // if short list ended, all were equal
    return true;

}

From source file:com.offbynull.peernetic.playground.chorddht.model.FingerTable.java

/**
 * Searches the finger table for the closest id to the id being searched for (closest in terms of being {@code <=} to), but skips
 * certain ids./*w  ww.  j a va  2 s .com*/
 *
 * @param id id being searched for
 * @param skipIds ids being skipped
 * @return closest pointer (closest in terms of being {@code <=} to)
 * @throws NullPointerException if any arguments are {@code null}
 * @throws IllegalArgumentException if {@code id}'s has a different limit bit size than base pointer's id
 */
public Pointer findClosest(Id id, Id... skipIds) {
    Validate.notNull(id);
    Validate.noNullElements(skipIds);
    Validate.isTrue(IdUtils.getBitLength(id) == bitCount);

    List<Id> skipIdList = Arrays.asList(skipIds);
    Id selfId = basePtr.getId();

    InternalEntry foundEntry = null;
    ListIterator<InternalEntry> lit = table.listIterator(table.size());
    while (lit.hasPrevious()) {
        InternalEntry ie = lit.previous();
        Id fingerId = ie.pointer.getId();
        // if finger should be skipped, ignore it
        if (skipIdList.contains(fingerId)) {
            continue;
        }
        // if finger[i] exists between n (exclusive) and id (exclusive)
        // then return it
        if (fingerId.isWithin(selfId, false, id, true)) {
            foundEntry = ie;
            break;
        }
    }

    return foundEntry == null ? basePtr : foundEntry.pointer;
}

From source file:org.openhab.binding.freeswitch.internal.FreeswitchBinding.java

/**
 * update items on call end//from w  ww. java  2 s .  co  m
 * @param config
 */
private void endCallItemUpdate(FreeswitchBindingConfig config) {

    OnOffType activeState = OnOffType.OFF;
    ;
    CallType callType = (CallType) CallType.EMPTY;
    StringType callerId = StringType.EMPTY;

    /*
     * A channel has ended that has this item associated with it
     * We still need to check if this item is associated with other
     * channels.
     * We are going to iterate backwards to get the last added channel;
     */
    ListIterator<String> it = new ArrayList<String>(itemMap.keySet()).listIterator(itemMap.size());

    //if we get a match we will stop processing
    boolean match = false;
    while (it.hasPrevious()) {
        String uuid = it.previous();
        for (FreeswitchBindingConfig c : itemMap.get(uuid)) {
            if (c.getItemName().equals(config.getItemName())) {
                Channel channel = eventCache.get(uuid);
                activeState = OnOffType.ON;
                callType = channel.getCall();
                callerId = new StringType(String.format("%s : %s", channel.getEventHeader(CID_NAME),
                        channel.getEventHeader(CID_NUMBER)));
                match = true;
                break;
            }
        }
        if (match)
            break;
    }
    if (config.getItemType().isAssignableFrom(SwitchItem.class)) {

        eventPublisher.postUpdate(config.getItemName(), activeState);
    } else if (config.getItemType().isAssignableFrom(CallItem.class)) {

        eventPublisher.postUpdate(config.getItemName(), callType);
    } else if (config.getItemType().isAssignableFrom(StringItem.class)) {

        eventPublisher.postUpdate(config.getItemName(), callerId);
    } else {
        logger.warn("handleHangupCall - postUpdate for itemType '{}' is undefined", config.getItemName());
    }
}

From source file:com.offbynull.peernetic.playground.chorddht.model.FingerTable.java

/**
 * Removes a pointer in to the finger table. If the pointer doesn't exist in the finger table, does nothing. See the
 * constraints/guarantees mentioned in the class Javadoc: {@link FingerTable}.
 * @param ptr pointer to put in as finger
 * @throws NullPointerException if any arguments are {@code null}
 * @throws IllegalArgumentException if {@code ptr}'s id has a different limit bit size than the base pointer's id, or if {@code ptr} has
 * an id that matches the base pointer's id
 *//*from   ww  w.j a  v a 2  s . c  o  m*/
public void remove(ExternalPointer<A> ptr) {
    Validate.notNull(ptr);
    Validate.isTrue(IdUtils.getBitLength(ptr.getId()) == bitCount);

    Id id = ptr.getId();
    A address = ptr.getAddress();
    Id baseId = basePtr.getId();

    Validate.isTrue(IdUtils.getBitLength(id) == bitCount);
    Validate.isTrue(!id.equals(baseId));

    ListIterator<InternalEntry> lit = table.listIterator(table.size());
    while (lit.hasPrevious()) {
        InternalEntry ie = lit.previous();

        if (ie.pointer instanceof InternalPointer) { // don't bother inspecting internal pointers since we can only remove
                                                     // external pointers
            continue;
        }

        ExternalPointer<A> testPtr = (ExternalPointer<A>) ie.pointer;
        Id testId = testPtr.getId();
        A testAddress = testPtr.getAddress();

        if (id.equals(testId) && address.equals(testAddress)) {
            remove(lit.previousIndex() + 1);
            break;
        }
    }
}

From source file:edu.umn.msi.tropix.persistence.dao.hibernate.TropixObjectDaoImpl.java

public TropixObject getHomeDirectoryPath(final String userId, final List<String> pathParts) {
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("getPath called with userId %s and path parts %s", userId,
                Iterables.toString(pathParts)));
    }/*www.  ja  va 2s .c  o m*/
    final StringBuilder joins = new StringBuilder(), wheres = new StringBuilder();
    final ListIterator<String> pathPartsIter = pathParts.listIterator(pathParts.size());
    final LinkedList<String> parameters = Lists.newLinkedList();
    while (pathPartsIter.hasPrevious()) {
        int index = pathPartsIter.previousIndex() + 1;
        final String pathPart = pathPartsIter.previous();

        int nextObjectBackIndex = pathPartsIter.previousIndex() + 1;
        joins.append(String.format(" inner join o%d.permissionParents as o%d ", index, nextObjectBackIndex));
        wheres.append(String.format(" and o%d.deletedTime is null", index));
        wheres.append(String.format(" and o%d.committed is true", index));
        addConstraintForPathPart(pathPart, index, wheres, parameters);
    }

    final String queryString = String.format(
            "User u, TropixObject o%d %s where u.cagridId = :userId %s and u.homeFolder.id = o0.id",
            pathParts.size(), joins.toString(), wheres.toString());
    return executePathQuery(userId, String.format("o%d", pathParts.size()), queryString, 1, parameters);
}

From source file:edu.umn.msi.tropix.persistence.dao.hibernate.TropixObjectDaoImpl.java

public TropixObject getGroupDirectoryPath(final String userId, final List<String> pathParts) {
    final StringBuilder joins = new StringBuilder(), wheres = new StringBuilder();
    final ListIterator<String> pathPartsIter = pathParts.listIterator(pathParts.size());
    final LinkedList<String> parameters = Lists.newLinkedList();
    while (pathPartsIter.hasPrevious()) {
        int index = pathPartsIter.previousIndex();
        final String pathPart = pathPartsIter.previous();
        wheres.append(String.format(" and o%d.deletedTime is null", index));
        wheres.append(String.format(" and o%d.committed is true", index));
        addConstraintForPathPart(pathPart, index, wheres, parameters);
        if (pathPartsIter.hasPrevious()) {
            int nextObjectBackIndex = pathPartsIter.previousIndex();
            joins.append(/*from   w w  w. ja va2 s.  c o  m*/
                    String.format(" inner join o%d.permissionParents as o%d ", index, nextObjectBackIndex));
        }
    }

    final int lastIndex = pathParts.size() - 1;
    final String objectType = lastIndex == 0 ? "Folder" : "TropixObject";
    final String queryString = String.format(
            "%s o%d %s inner join o0.permissions p left join p.users u left join p.groups g left join g.users gu where (u.cagridId = :userId or gu.cagridId = :userId) and o0.parentFolder is null %s and o0.class is Folder",
            objectType, lastIndex, joins.toString(), wheres.toString());
    return executePathQuery(userId, String.format("o%d", lastIndex), queryString, 0, parameters);
}

From source file:org.jahia.services.content.JCRContentUtils.java

public static <T> Map<String, T> reverse(Map<String, T> orderedMap) {
    if (orderedMap == null || orderedMap.isEmpty()) {
        return orderedMap;
    }//from  w  w  w .  j av a  2  s  .c  o  m
    LinkedHashMap<String, T> reversed = new LinkedHashMap<String, T>(orderedMap.size());
    ListIterator<String> li = new LinkedList<String>(orderedMap.keySet()).listIterator(orderedMap.size());
    while (li.hasPrevious()) {
        String key = li.previous();
        reversed.put(key, orderedMap.get(key));
    }
    return reversed;
}

From source file:org.jahia.services.content.ConflictResolver.java

private Map<String, String> getOrdering(ListOrderedMap uuids1, List<String> removed) {
    Map<String, String> previousMap = new LinkedHashMap<String, String>();
    ListIterator<?> it = uuids1.keyList().listIterator(uuids1.size());
    String previous = "";
    while (it.hasPrevious()) {
        String uuid = (String) it.previous();
        if (!removed.contains(uuid)) {
            previousMap.put(uuid, previous);
            previous = uuid;//  www.  j  a va 2s  . co m
        }
    }
    return previousMap;
}

From source file:com.bt.aloha.dialog.state.DialogInfo.java

public void setRouteList(ListIterator<?> recordRouteHeaderIterator, boolean backwards) {
    routeList = new RouteList();
    if (recordRouteHeaderIterator == null)
        return;/*  ww w . java2  s  . c  o  m*/

    if (backwards)
        while (recordRouteHeaderIterator.hasNext())
            recordRouteHeaderIterator.next();

    while (backwards ? recordRouteHeaderIterator.hasPrevious() : recordRouteHeaderIterator.hasNext()) {
        RecordRouteHeader recordRouteHeader = backwards
                ? (RecordRouteHeader) recordRouteHeaderIterator.previous()
                : (RecordRouteHeader) recordRouteHeaderIterator.next();
        Route route = new Route();
        AddressImpl address = (AddressImpl) ((AddressImpl) recordRouteHeader.getAddress()).clone();
        route.setAddress(address);
        NameValueList nameValueList = new NameValueList();
        Iterator<?> paramIterator = recordRouteHeader.getParameterNames();
        while (paramIterator.hasNext()) {
            String paramName = (String) paramIterator.next();
            nameValueList.set(paramName, recordRouteHeader.getParameter(paramName));
        }
        route.setParameters(nameValueList);
        log.debug(String.format("Added route address %s, params %s to route set for dialog %s", address,
                nameValueList.toString(), getId()));
        routeList.add(route);
    }
}