Example usage for java.util List iterator

List of usage examples for java.util List iterator

Introduction

In this page you can find the example usage for java.util List iterator.

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this list in proper sequence.

Usage

From source file:Main.java

/**
 * Appends the specified path token to the provided buffer
 * followed by the position specification of the target node in
 * its siblings list./*from w  w  w  .ja  v  a2 s  . co  m*/
 *
 * @param  node        the target node for the XPath expression.
 * @param  siblings    the siblings of the target node.
 * @param  pathToken   the path token identifying the target node.
 * @param  buffer      the buffer to which appending the XPath
 *                     sub-expression or <code>null</code> if the
 *                     method shall allocate a new buffer.
 *
 * @return the XPath sub-expression to select the target node
 *         among its siblings.
 */
private static StringBuffer getPositionPath(Object node, List siblings, String pathToken, StringBuffer buffer) {
    if (buffer == null) {
        buffer = new StringBuffer();
    }
    if (pathToken != null) {
        buffer.append(pathToken);
    }

    if ((siblings != null) && (siblings.size() != 1)) {
        int position = 0;
        for (Iterator i = siblings.iterator(); i.hasNext();) {
            position++;
            if (i.next() == node)
                break;
        }
        buffer.append('[').append(position).append(']');
    }
    return buffer;
}

From source file:fedora.server.utilities.rebuild.Rebuild.java

private static int setValuesForProfile(List configs, String profile) {
    Iterator iter = configs.iterator();
    int c = 0;/* w  w w. j a v  a2  s  . c o  m*/
    while (iter.hasNext()) {
        c += setValuesForProfile((Configuration) iter.next(), profile);
    }
    return c;
}

From source file:net.phyloviz.mstsstatistics.Runner.java

private static int findMaxId(List edgesList) {
    int id = 0;/*ww  w  . jav  a 2s . c  o m*/
    Iterator<EdgeMST> eIter = edgesList.iterator();
    while (eIter.hasNext()) {
        EdgeMST e = (EdgeMST) eIter.next();
        id = Math.max(id, e.getSource());
        id = Math.max(id, e.getDest());
    }

    return id;
}

From source file:com.salesmanager.core.service.common.impl.ModuleManagerImpl.java

public static Collection<CoreModuleService> getModuleService(String countryIsoCode, int serviceCode) {

    List services = ServicesUtil.getServices(countryIsoCode);

    Collection returnList = new ArrayList();

    if (services != null) {

        Iterator i = services.iterator();
        while (i.hasNext()) {
            CoreModuleService srv = (CoreModuleService) i.next();
            if (srv.getCoreModuleServiceCode() == serviceCode) {
                // return srv;
                returnList.add(srv);// w  w  w .jav a 2s.co m
            }
        }
    }

    return returnList;

}

From source file:com.salesmanager.core.service.common.impl.ModuleManagerImpl.java

public static Collection<CoreModuleService> getModuleService(String countryIsoCode, int serviceCode,
        int subservice) {

    List services = ServicesUtil.getServices(countryIsoCode);

    Collection returnList = new ArrayList();

    if (services != null) {

        Iterator i = services.iterator();
        while (i.hasNext()) {
            CoreModuleService srv = (CoreModuleService) i.next();
            if (srv.getCoreModuleServiceCode() == serviceCode
                    && srv.getCoreModuleServiceSubtype() == subservice) {
                returnList.add(srv);/*ww w  . j  a va2s .  c  o  m*/
                // return srv;
            }
        }
    }

    return null;
}

From source file:com.yahoo.xpathproto.ProtoBuilder.java

private static void transformUsingDefinition(final Context vars, final Config config, final JXPathCopier copier,
        final Config.Entry transform) {
    boolean isRepeated = false;
    if (transform.getField() != null) {
        Descriptors.FieldDescriptor fieldDescriptor = copier.getTarget().getDescriptorForType()
                .findFieldByName(transform.getField());
        if (null == fieldDescriptor) {
            throw new RuntimeException("Unknown target field in protobuf: " + transform.getField());
        }//from  ww  w. j  a  v a  2 s  .  c o m

        isRepeated = fieldDescriptor.isRepeated();
    }

    JXPathContext context = copier.getSource();
    if (isRepeated) {
        List list = context.selectNodes(transform.getPath());
        Iterator iterator = list.iterator();
        int limit = 0;
        int count = 0;

        if (transform.getLimit() != null) {
            limit = transform.getLimit();
        }
        logger.debug("Applying limit of {} for field {}", limit, transform.getField());

        while (iterator.hasNext() && (count != limit || limit == 0)) {
            Object value = iterator.next();
            JXPathCopier innerCopier = new JXPathCopier(JXPathContext.newContext(value), copier.getTarget());
            Message.Builder innerBuilder = transformUsing(vars, config, innerCopier, transform.getDefinition());
            if ((transform.getField() != null) && (null != innerBuilder) && (innerBuilder.isInitialized())) {
                copier.copyObject(innerBuilder.build(), transform.getField());
            }
            count++;
        }
    } else {
        JXPathContext innerContext = JXPathCopier.getRelativeContext(context, transform.getPath());
        if (innerContext != null) {
            JXPathCopier innerCopier = new JXPathCopier(innerContext, copier.getTarget());
            Message.Builder innerBuilder = transformUsing(vars, config, innerCopier, transform.getDefinition());
            if ((transform.getField() != null) && (null != innerBuilder) && (innerBuilder.isInitialized())) {
                copier.copyObject(innerBuilder.build(), transform.getField());
            }
        }
    }
}

From source file:com.redhat.rhn.domain.token.ActivationKeyFactory.java

/**
 * Creates and fills out a new Activation Key (Including generating a key/token).
 * Sets deployConfigs to false, disabled to 0, and usage limit to null.
 * Sets the 'server' to the server param, and the groups to the
 * system groups the server is subscribed to.
 * @param user The user for the key// www. ja  v  a2 s  . com
 * @param server The server for the key
 * @param key Key to use, blank to have one auto-generated
 * @param note The note to attach to the key
 * @param usageLimit Usage limit for the activation key
 * @param baseChannel Base channel for the activation key
 * @param universalDefault Whether or not this key should be set as the universal
 *        default.
 * @return Returns the newly created ActivationKey.
 */
public static ActivationKey createNewKey(User user, Server server, String key, String note, Long usageLimit,
        Channel baseChannel, boolean universalDefault) {

    ActivationKey newKey = new ActivationKey();

    String keyToUse = key;
    if (keyToUse == null || keyToUse.equals("")) {
        keyToUse = generateKey();
    } else {
        keyToUse = key.trim().replace(" ", "");
    }

    keyToUse = ActivationKey.sanitize(user.getOrg(), keyToUse);
    validateKeyName(keyToUse);

    if (server != null) {
        keyToUse = "re-" + keyToUse;
    }

    newKey.setKey(keyToUse);
    newKey.setCreator(user);
    newKey.setOrg(user.getOrg());
    newKey.setServer(server);

    if (StringUtils.isBlank(note)) {
        note = DEFAULT_DESCRIPTION;
    }
    newKey.setNote((String) Scrubber.scrub(note));
    newKey.getToken().setDeployConfigs(false); // Don't deploy configs by default
    newKey.setDisabled(Boolean.FALSE); // Enable by default
    newKey.setUsageLimit(usageLimit);

    if (baseChannel != null) {
        newKey.getToken().addChannel(baseChannel);
    }

    // Set the entitlements equal to what the server has by default
    if (server != null) {
        List serverEntitlements = server.getEntitledGroups();
        for (Iterator itr = serverEntitlements.iterator(); itr.hasNext();) {
            ServerGroup group = (ServerGroup) itr.next();
            newKey.addEntitlement(group.getGroupType());
        }
    } else {
        newKey.addEntitlement(ServerConstants.getServerGroupTypeEnterpriseEntitled());
    }

    save(newKey);

    if (universalDefault) {
        Token token = newKey.getToken();
        user.getOrg().setToken(token);
        OrgFactory.save(user.getOrg());
    }

    return newKey;
}

From source file:com.aurel.track.persist.TDashboardScreenPeer.java

/**
 * delete all children and then delete the object
 * @param objectID/*from  w  w  w  .j  a  va 2  s .  c o  m*/
 * @param con
 * @throws TorqueException
 */
public static void deleteChildren(Integer objectID, Connection con) throws TorqueException {
    //delete also all children
    LOGGER.debug("Deleting children for screen:" + objectID + "...");
    Criteria critTabs = new Criteria();
    critTabs.add(BaseTDashboardTabPeer.PARENT, objectID);
    List tabs = BaseTDashboardTabPeer.doSelect(critTabs, con);
    for (Iterator iterTabs = tabs.iterator(); iterTabs.hasNext();) {
        TDashboardTab tab = (TDashboardTab) iterTabs.next();
        //delete the children for the tab
        TDashboardTabPeer.deleteChildren(tab.getObjectID(), con);
        //delete the tab
        BaseTDashboardTabPeer.doDelete(SimpleKey.keyFor(tab.getObjectID()), con);
    }
}

From source file:com.pureinfo.tgirls.servlet.GetPic.java

public static String idListToString(List<String> _viewdPicIds) {
    if (_viewdPicIds == null) {
        return "";
    }/*from ww w  .j  a  va 2 s.  c o m*/
    StringBuffer sbuff = new StringBuffer();
    for (Iterator iterator = _viewdPicIds.iterator(); iterator.hasNext();) {
        String string = (String) iterator.next();

        if (sbuff.length() == 0) {
            sbuff.append(string);
        } else {
            sbuff.append(",").append(string);
        }
    }
    return sbuff.toString();
}

From source file:com.sun.socialsite.web.ui.admin.menu.MenuHelper.java

private static ParsedTab elementToParsedTab(Element element) {

    ParsedTab tab = new ParsedTab();

    tab.setName(element.getAttributeValue("name"));
    if (element.getAttributeValue("weblogPerms") != null) {
        tab.setWeblogPermissionActions(/* w  ww.j  av a 2  s. c om*/
                Utilities.stringToStringList(element.getAttributeValue("weblogPerms"), ","));
    }
    if (element.getAttributeValue("globalPerms") != null) {
        tab.setGlobalPermissionActions(
                Utilities.stringToStringList(element.getAttributeValue("globalPerms"), ","));
    }
    tab.setEnabledProperty(element.getAttributeValue("enabledProperty"));
    tab.setDisabledProperty(element.getAttributeValue("disabledProperty"));

    List<?> menuItems = element.getChildren("menu-item");
    Iterator<?> iter = menuItems.iterator();
    while (iter.hasNext()) {
        Element e = (Element) iter.next();
        tab.addItem(elementToParsedTabItem(e));
    }

    return tab;
}