Example usage for java.util Collection iterator

List of usage examples for java.util Collection iterator

Introduction

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

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this collection.

Usage

From source file:Main.java

public static <K> boolean isEquals(Collection<K> collection1, Collection<K> collection2) {

    if (collection1 == null && collection2 == null) {
        return true;
    }/*from   w ww  . j a  va2  s .  com*/
    if (collection1 == null || collection2 == null || collection1.size() != collection2.size()) {
        return false;
    }
    boolean result = true;
    Iterator<K> ite2 = collection2.iterator();
    while (ite2.hasNext()) {
        if (!collection1.contains(ite2.next())) {
            result = false;
            break;
        }
    }
    return result;
}

From source file:org.soyatec.windowsazure.authenticate.HttpRequestAccessor.java

/**
 * A helper function for extracting HTTP header values from a
 * NameValueCollection object.//from w ww . jav  a  2  s . co  m
 * 
 * @param header
 *            A MultiValueMap object that should contain HTTP header
 *            name-values pairs.
 * @param headerName
 *            Name of the header that we want to get values of.
 * @return A array list of values for the header. The values are in the same
 *         order as they are exist in the MultiValueMap object.
 */
public static List<String> getHeaderValues(NameValueCollection header, String headerName) {
    List<String> arrayOfValues = new ArrayList<String>();
    Collection collection = header.getCollection(headerName);
    if (collection != null) {
        for (Iterator iterator = collection.iterator(); iterator.hasNext();) {
            String object = (String) iterator.next();
            arrayOfValues.add(object);
        }
    }
    return arrayOfValues;
}

From source file:fi.hsl.parkandride.back.UtilizationDao.java

private static <S, T extends Comparable<T>> PostgreSQLQuery<S> addCriteria(PostgreSQLQuery<S> q,
        Collection<T> collection, ComparableExpressionBase<T> path) {
    switch (collection.size()) {
    case 0:/*from  w  w w .j  av  a 2s.  c o  m*/
        return q;
    case 1:
        return q.where(path.eq(collection.iterator().next()));
    default:
        return q.where(path.in(collection));
    }
}

From source file:info.magnolia.cms.beans.config.Subscriber.java

/**
 * Cache listener content from the config repository.
 *///from w ww .j  a  v a2 s  .c  o m
private static void cacheContent(Collection subs) {

    Iterator ipList = subs.iterator();

    // start by setting the subscribersEnabled property to false, will be reset when an active subscriber is found
    subscribersEnabled = false;

    while (ipList.hasNext()) {
        Content c = (Content) ipList.next();
        Subscriber si = new Subscriber();

        si.url = c.getNodeData("URL").getString(); //$NON-NLS-1$

        if (StringUtils.isEmpty(si.url)) {
            String address = c.getNodeData("address").getString(); //$NON-NLS-1$
            String protocol = c.getNodeData("protocol").getString(); //$NON-NLS-1$

            log.warn(
                    "Deprecated: subscriber is missing the URL property. Please use URL instead of address and domain");

            if (StringUtils.isEmpty(protocol)) {
                protocol = "http";
                si.url = protocol + "://" + address;
            }
        }

        if (!si.url.endsWith("/")) {
            si.url = si.url + "/";
        }

        si.senderURL = c.getNodeData("senderURL").getString(); //$NON-NLS-1$
        si.requestConfirmation = c.getNodeData("requestConfirmation").getBoolean(); //$NON-NLS-1$
        si.name = c.getName();

        // don't use getBoolean since subscribers without an "active" node should be enabled by default
        String activeString = c.getNodeData("active").getString(); //$NON-NLS-1$

        if (StringUtils.isNotEmpty(activeString)) {
            si.active = BooleanUtils.toBoolean(activeString);
        } else {
            si.active = true;
        }

        if (si.active) {
            // at least one subscriber is enabled
            subscribersEnabled = true;
        }

        // all context info
        try {
            addContext(si, c);
        } catch (RepositoryException e) {
            // valid
        }
        Subscriber.cachedContent.put(c.getName(), si);
    }
    ipList = null;
}

From source file:coolmap.application.plugin.PluginMaster.java

public static void initialize() {
    String pluginPath;/*from  w  w  w  .ja  v a  2 s  . co m*/
    if (Config.isInitialized()) {
        pluginPath = Config.getProperty(Config.PLUGIN_DIRECTORY);
    } else {
        pluginPath = "plugin";
    }

    File pluginFolder = new File(pluginPath);

    //        System.out.println(pluginFolder.getAbsolutePath());
    pluginManager = PluginManagerFactory.createPluginManager();
    pluginManager.addPluginsFrom(pluginFolder.toURI());

    //        after loading everything
    pluginManagerUtil = new PluginManagerUtil(pluginManager);
    Collection<CoolMapPlugin> plugins = pluginManagerUtil.getPlugins(CoolMapPlugin.class);

    Collection<PluginInformation> pluginInfo = pluginManagerUtil.getPlugins(PluginInformation.class);

    PluginInformationImpl piImpl = null;
    if (!pluginInfo.isEmpty()) {
        piImpl = (PluginInformationImpl) pluginInfo.iterator().next();
    }

    for (CoolMapPlugin plugin : plugins) {
        try {

            CMConsole.logInfo("Loaded " + plugin.getName() + " plugin");
            //                System.out.println(plugin.getName());
            JSONObject config = new JSONObject();
            if (piImpl != null) {
                //gets the string
                try {
                    Collection<String> paths = piImpl
                            .getInformation(PluginInformation.Information.CLASSPATH_ORIGIN, plugin);
                    if (!paths.isEmpty()) {
                        config.put(CoolMapPluginTerms.ATTR_URI, paths.iterator().next());
                    }
                } catch (Exception e) {
                    //do nothing, not found
                }
            }

            plugin.initialize(config);

        } catch (Exception e) {
            CMConsole.logWarning("Loaded '" + plugin.getName() + "' plugin");
            CMConsole.logToFile(e);
        }
    }
}

From source file:Main.java

/**
 * Returns true if there is any element that is common to both collections.
 *///from w w  w .  j a va2  s  . com
public static boolean containsAny(Collection c1, Collection c2) {
    // A better implementation here would be to use sets
    Collection smallCollection;
    Collection largeCollection;
    if (c1.size() < c2.size()) {
        smallCollection = c1;
        largeCollection = c2;
    } else {
        smallCollection = c2;
        largeCollection = c1;
    }
    boolean intersect = false;
    Iterator i = smallCollection.iterator();
    while (i.hasNext()) {
        if (largeCollection.contains(i.next())) {
            intersect = true;
            break;
        }
    }
    return intersect;
}

From source file:com.mycollab.vaadin.resources.StreamDownloadResourceUtil.java

public static String getDownloadFileName(Collection<Resource> lstRes) {
    if (CollectionUtils.isEmpty(lstRes)) {
        throw new UserInvalidInputException(
                UserUIContext.getMessage(FileI18nEnum.ERROR_NO_SELECTED_FILE_TO_DOWNLOAD));
    } else if (lstRes.size() == 1) {
        Resource resource = lstRes.iterator().next();
        return (resource instanceof Folder) ? "out.zip" : resource.getName();
    } else {/*from ww  w .ja v a2 s .  co  m*/
        return "out.zip";
    }

}

From source file:com.eryansky.common.utils.collections.Collections3.java

/**
 * ab??List./*  ww  w  .ja v a  2 s . com*/
 */
public static <T> List<T> aggregate(Collection<T> a, Collection<T> b) {
    List<T> list = new ArrayList<T>();
    if (a != null) {
        Iterator it = a.iterator();
        while (it.hasNext()) {
            T o = (T) it.next();
            if (!list.contains(o)) {
                list.add(o);
            }
        }
    }
    if (b != null) {
        Iterator it = b.iterator();
        while (it.hasNext()) {
            T o = (T) it.next();
            if (!list.contains(o))
                list.add(o);
        }
    }
    return list;
}

From source file:com.salesmanager.core.util.MerchantConfigurationUtil.java

public static String getConfigurationValue(Collection<String> values, String delimiter) {
    if (values == null || values.size() == 0) {
        return "";
    }/*from w ww . j a  v  a  2s.  c o  m*/
    int count = 1;
    Iterator i = values.iterator();
    StringBuffer b = new StringBuffer();
    while (i.hasNext()) {
        String value = (String) i.next();
        b.append(value);
        if (values.size() > count) {
            b.append(delimiter);
        }
        count++;
    }
    return b.toString();
}

From source file:Main.java

/**
 * <p>//  w w  w  .  j  a v  a  2 s .co m
 * Checks if the given two {@link Collection}s contains the same elements
 * in any order.
 * </p>
 * <p>
 * Empty {@link Collection}s and {@code null} parameters are treated as equal.
 * </p> 
 * @param first The first {@link Collection}.
 * @param second The second {@link Collection}.
 * @return {@code true} both {@link Collection}s contains same elements, {@code false} {@link Collection}s are different.
 */
public static <T> boolean containsSame(Collection<T> first, Collection<T> second) {
    if (first != null) {
        if (second != null) {
            if (first.size() == second.size()) {
                Collection<T> firstCopy = new LinkedList<T>(first);
                boolean same = true;
                Iterator<T> secondIter = second.iterator();
                while (same && secondIter.hasNext()) {
                    T secondNext = secondIter.next();
                    same = firstCopy.remove(secondNext);
                }
                return same;
            } else {
                return false;
            }
        } else {
            return first.size() == 0;
        }
    } else {
        return second == null || second.size() == 0;
    }
}