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 (if
 * needed)./*from w w w  . ja  v a  2  s  .  com*/
 * 
 * @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 StringBuilder getPositionPath(Object node, List<?> siblings, String pathToken,
        StringBuilder buffer) {

    buffer.append(pathToken);

    if (siblings != null) {
        int position = 0;
        final Iterator<?> i = siblings.iterator();
        while (i.hasNext()) {
            position++;
            if (i.next() == node)
                break;
        }
        if (position > 1 || i.hasNext()) {
            // the item is not at the first location, ot there are more
            // locations. in other words, indexing is required.
            buffer.append('[').append(position).append(']');
        }
    }
    return buffer;
}

From source file:com.fengduo.bee.commons.core.lang.ArrayUtils.java

public static String[] removeBlankElement(String[] array) {
    if (Argument.isEmptyArray(array)) {
        logger.debug("ArrayUtils.removeBlankElement array is null!");
        return null;
    }/*from www  .  ja  v  a  2  s.com*/
    List<String> list = new ArrayList<String>(Arrays.asList(array));
    Iterator<String> iterator = list.iterator();
    while (iterator.hasNext()) {
        if (Argument.isBlank(iterator.next())) {
            iterator.remove();
        }
    }
    if (list.isEmpty()) {
        return null;
    } else {
        return list.toArray(new String[0]);
    }
}

From source file:Main.java

/**
 * //from   w  w  w. j  a  v  a 2 s.  c o  m
 * 
 */
public static <T> boolean equalsAsSet(Collection<T> value1, Collection<T> value2, Method equalsMethod)
        throws IllegalAccessException, InvocationTargetException {
    if (!equalsMethod.getReturnType().equals(boolean.class)) {
        return false;
    }
    List<T> s1 = new LinkedList<T>();
    for (T v : value1) {
        s1.add(v);
    }
    for (T v : value2) {
        Iterator<T> i2 = s1.iterator();
        boolean found = false;
        while (i2.hasNext()) {
            if (((Boolean) equalsMethod.invoke(v, i2.next())).booleanValue()) {
                i2.remove();
                found = true;
                break;
            }
        }
        if (!found)
            return false;
    }
    return s1.size() == 0;
}

From source file:Main.java

/**
 * Creates a list of values extracted from the provided list using the
 * specified value method, keeping the order of the provided list.
 *//*w w  w.jav a2  s.co m*/
@SuppressWarnings("unchecked")
public static <K, T> List<K> createList(List<T> list, String valueMethod) {
    List<K> valueList = new ArrayList<>(list.size());

    if (list.isEmpty()) {
        return valueList;
    }

    Class<?> elementClass = list.iterator().next().getClass();

    Method getValueMethod;

    try {
        getValueMethod = elementClass.getMethod(valueMethod, new Class[0]);
    } catch (Exception e) {
        throw new RuntimeException("Failed to get key method", e);
    }

    for (T element : list) {
        K value;

        try {
            value = (K) getValueMethod.invoke(element, (Object[]) null);
        } catch (Exception e) {
            throw new RuntimeException("Failed to get key", e);
        }

        valueList.add(value);
    }

    return valueList;
}

From source file:org.osmtools.ra.traverse.TraverseService.java

public static void fillInNodesBetweenNodes(List<ConnectableSegment> modifyableSegments, List<Node> resultNodes,
        Node startNode, Node currentNode) {
    for (Iterator<ConnectableSegment> it = modifyableSegments.iterator(); it.hasNext();) {
        ConnectableSegment connectableSegment = it.next();

        if (connectableSegment.containsNodes(startNode, currentNode)) {
            int prevSize = resultNodes.size();
            connectableSegment.appendNodesBetween(resultNodes, startNode, currentNode);
            // If the segment list is only 2 elements we must make sure 
            // that we not reuse the same segment again
            // Scenario: A => B => A
            if (modifyableSegments.size() <= 2) {
                it.remove();/*w w w.  j  a v a 2  s  .co  m*/
            }
            if (prevSize < resultNodes.size())
                break;
        }
    }
}

From source file:edu.caltech.ipac.firefly.server.servlets.MultipartDataUtil.java

public static MultiPartData handleRequest(StringKey key, HttpServletRequest req) throws Exception {

    // Create a factory for disk-based file items
    DiskFileItemFactory factory = new DiskFileItemFactory();

    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload(factory);

    // Parse the request
    List /* FileItem */ items = upload.parseRequest(req);

    MultiPartData data = new MultiPartData(key);

    // Process the uploaded items
    Iterator iter = items.iterator();
    while (iter.hasNext()) {
        FileItem item = (FileItem) iter.next();

        if (item.isFormField()) {
            String name = item.getFieldName();
            String value = item.getString();
            data.addParam(name, value);/* w w  w. jav  a  2s . c om*/
        } else {
            String fieldName = item.getFieldName();
            String fileName = item.getName();
            String contentType = item.getContentType();
            File uf = new File(ServerContext.getTempWorkDir(), System.currentTimeMillis() + ".upload");
            item.write(uf);
            data.addFile(fieldName, uf, fileName, contentType);
            StringKey fileKey = new StringKey(fileName, System.currentTimeMillis());
            CacheManager.getCache(Cache.TYPE_TEMP_FILE).put(fileKey, uf);
        }
    }
    return data;
}

From source file:com.mirth.connect.client.ui.util.VariableListUtil.java

public static void getRuleVariables(Set<String> targetSet, Connector connector, boolean includeLocalVars,
        int row) {

    // add only the global variables
    List<Rule> connectorRules = connector.getFilter().getRules();
    Iterator<Rule> ruleIterator = connectorRules.iterator();
    String varPattern = GLOBAL_AND_CHANNEL_VARIABLE_PATTERN;
    if (includeLocalVars) {
        varPattern = LOCAL_VARIABLE_PATTERN;
    }/*www.j a  va  2 s .  c om*/
    int currentRow = 0;
    while (ruleIterator.hasNext()) {
        if (row > -1 && row <= currentRow) {
            break;
        }
        Pattern pattern = Pattern.compile(varPattern);
        String scriptWithoutComments = getScriptWithoutComments(ruleIterator.next().getScript());

        Matcher matcher = pattern.matcher(scriptWithoutComments);
        while (matcher.find()) {
            targetSet.add(getMapKey(matcher));
        }
        currentRow++;
    }
}

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

private static List convertTorqueListToBeanList(List torqueList) {
    List beanList = new ArrayList();
    if (torqueList != null) {
        Iterator itrTorqueList = torqueList.iterator();
        while (itrTorqueList.hasNext()) {
            beanList.add(((TMSProjectExchange) itrTorqueList.next()).getBean());
        }/* w  w  w .j a  va  2 s.c o  m*/
    }
    return beanList;
}

From source file:edu.uci.ics.hyracks.control.cc.partitions.PartitionMatchMaker.java

private static <T> void removeEntries(List<T> list, IEntryFilter<T> filter) {
    Iterator<T> j = list.iterator();
    while (j.hasNext()) {
        T o = j.next();/*from   w w  w  . j  a v a2s  .c o m*/
        if (filter.matches(o)) {
            j.remove();
        }
    }
}

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

public static List<IField> loadFullChildren(Integer objectID, Connection con) throws TorqueException {
    Criteria critChild = new Criteria();
    critChild.add(BaseTCardFieldPeer.CARDPANEL, objectID);
    List<IField> result = new ArrayList<IField>();
    List torqueList = BaseTCardFieldPeer.doSelect(critChild, con);
    if (torqueList != null) {
        Iterator itrTorqueList = torqueList.iterator();
        while (itrTorqueList.hasNext()) {
            result.add(((TCardField) itrTorqueList.next()).getBean());
        }//  w w w  .j av a2  s  . com
    }
    return result;
}