Example usage for java.util Set iterator

List of usage examples for java.util Set iterator

Introduction

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

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this set.

Usage

From source file:Main.java

public static Set minus(Set oriSet, Set tarSet) {
    if (oriSet == null || oriSet.size() == 0)
        return oriSet;
    if (tarSet == null || tarSet.size() == 0)
        return oriSet;
    Iterator oriItor = oriSet.iterator();
    Set minusSet = new HashSet();
    while (oriItor.hasNext()) {
        Object oriObj = oriItor.next();
        Iterator tarItor = tarSet.iterator();
        boolean isExist = false;
        while (tarItor.hasNext()) {
            Object tarObj = tarItor.next();
            if (tarObj.equals(oriObj)) {
                isExist = true;//from w  ww .  j  a  va2s. c o m
                break;
            }
        }
        if (!isExist) {
            minusSet.add(oriObj);
        }

    }
    return minusSet;

}

From source file:com.elsevier.xml.NamespaceContextMappings.java

/**
 * Init the cache with the passed HashMap of prefixes and namespaces. 
 * /*w ww .  j av  a  2  s .  c  o  m*/
 * @param initPrefixNamespaceMap HashMap of prefixes and namespaces
 */
public static void init(HashMap<String, String> initPrefixNamespaceMap) {

    if (prefixNamespaceMap == null) {
        synchronized (NamespaceContextMappings.class) {
            if (prefixNamespaceMap == null) {

                // Add the defaults
                prefixNamespaceMap = new HashMap<String, String>();
                prefixNamespaceMap.put("xml", XMLConstants.XML_NS_URI);
                prefixNamespaceMap.put("fn", "http://www.w3.org/2005/xpath-functions");
                prefixNamespaceMap.put("xs", "http://www.w3.org/2001/XMLSchema");

                // Add those passed to init
                prefixNamespaceMap.putAll(initPrefixNamespaceMap);

                // Output the list of namespace prefix to uri mappings
                Set<String> keys = prefixNamespaceMap.keySet();
                Iterator<String> it = keys.iterator();
                log.info("** Namespace Mappings **");
                while (it.hasNext()) {
                    String key = it.next();
                    String val = prefixNamespaceMap.get(key);
                    log.info(key + "=" + val);
                }

            }
        }
    }

}

From source file:com.joyent.manta.client.crypto.EncryptedMetadataUtils.java

/**
 * Converts the headers to be encrypted to a plaintext string. This returns
 * the value of that will be encrypted and stored as ciphertext.
 *
 * @param metadata metadata object containing items to be encrypted
 * @return string containing headers in the format of <code>Header: Value</code>
 *///w  ww.jav a2 s  .c  om
public static String encryptedMetadataAsString(final MantaMetadata metadata) {
    Set<Map.Entry<String, String>> entrySet = metadata.entrySet();
    Iterator<Map.Entry<String, String>> iterator = entrySet.iterator();
    StringBuilder builder = new StringBuilder();

    while (iterator.hasNext()) {
        Map.Entry<String, String> entry = iterator.next();

        if (entry.getKey().startsWith(MantaMetadata.ENCRYPTED_METADATA_PREFIX)) {
            String line = String.format("%s: %s", entry.getKey(), entry.getValue());
            builder.append(line);

            if (iterator.hasNext()) {
                builder.append(CharUtils.LF);
            }
        }
    }

    return builder.toString();
}

From source file:io.wcm.dam.assetservice.impl.DamPathHandler.java

/**
 * Set DAM paths that should be handled. Only called once by {@link AssetRequestServlet}.
 * @param damPaths DAM folder paths or empty/null if all should be handled.
 *///www . j  av a 2s  .  c o m
private static Pattern buildDamPathsPattern(Set<String> damPaths) {
    StringBuilder pattern = new StringBuilder();
    pattern.append("^(");
    Iterator<String> paths = damPaths.iterator();
    while (paths.hasNext()) {
        pattern.append(Pattern.quote(paths.next()));
        pattern.append("/.*");
        if (paths.hasNext()) {
            pattern.append("|");
        }
    }
    pattern.append(")$");
    return Pattern.compile(pattern.toString());
}

From source file:com.nesscomputing.syslog4j.server.SyslogServer.java

public synchronized static final void shutdown() throws SyslogRuntimeException {
    Set<String> protocols = instances.keySet();

    Iterator<String> i = protocols.iterator();

    while (i.hasNext()) {
        String protocol = i.next();

        SyslogServerIF syslogServer = instances.get(protocol);

        syslogServer.shutdown();//from   www . j av  a  2  s .c  om
    }

    instances.clear();
}

From source file:grails.plugin.searchable.internal.util.GrailsDomainClassUtils.java

/**
 * Get the parent GrailsDomainClass for the given GrailsDomainClass, if it
 * exists in the given collection otherwise null
 *
 * @param grailsDomainClass the class whose parent to find
 * @param grailsDomainClasses the collection of possible parents
 * @return null if the given class has no parent or the parent is not in the collection
 *//*from w  w w.j a v  a  2 s  . c  o m*/
public static GrailsDomainClass getSuperClass(GrailsDomainClass grailsDomainClass,
        Collection grailsDomainClasses) {
    Set candidates = new HashSet();
    for (Iterator iter = grailsDomainClasses.iterator(); iter.hasNext();) {
        GrailsDomainClass gdc = (GrailsDomainClass) iter.next();
        if (gdc.getSubClasses().contains(grailsDomainClass)) {
            candidates.add(gdc);
        }
    }
    if (candidates.isEmpty()) {
        return null;
    }
    while (candidates.size() > 1) {
        Set copy = new HashSet(candidates);
        for (Iterator iter = copy.iterator(); iter.hasNext();) {
            GrailsDomainClass supsup = (GrailsDomainClass) iter.next();
            boolean remove = false;
            for (Iterator iter2 = candidates.iterator(); iter2.hasNext();) {
                GrailsDomainClass sup = (GrailsDomainClass) iter2.next();
                if (supsup.getSubClasses().contains(sup)) {
                    remove = true;
                    break;
                }
            }
            if (remove) {
                candidates.remove(supsup);
                break;
            }
        }
    }
    return (GrailsDomainClass) candidates.iterator().next();
}

From source file:com.hg.development.apps.messagenotifier_v1.Utils.Utility.java

/**
 * Permet de supprimer les doublons dans la liste des contacts.
 * @param duplicatelist Map contenant le nom de chaque contact.
 * @return la liste des contacts sans doublons.
 *//* ww  w. j  av a 2 s  . c o m*/
public static List<LocalContact> removeContactsDuplicated(Map<String, LocalContact> duplicatelist) {
    try {
        List<LocalContact> list = new ArrayList<>();

        Set set = duplicatelist.entrySet();
        Iterator i = set.iterator();

        while (i.hasNext()) {
            Map.Entry me = (Map.Entry) i.next();

            LocalContact contact = (LocalContact) me.getValue();

            if (!list.contains((contact)))
                list.add(contact);
        }

        return list;
    } catch (Exception ex) {
        throw ex;
    }
}

From source file:com.datatorrent.contrib.kafka.KafkaMetadataUtil.java

/**
 * There is always only one string in zkHost
 * @param zkHost//  w  w  w .jav  a  2  s  .com
 * @return
 */
public static Set<String> getBrokers(Set<String> zkHost) {

    ZkClient zkclient = new ZkClient(zkHost.iterator().next(), 30000, 30000, ZKStringSerializer$.MODULE$);
    Set<String> brokerHosts = new HashSet<String>();
    for (Broker b : JavaConversions.asJavaIterable(ZkUtils.getAllBrokersInCluster(zkclient))) {
        brokerHosts.add(b.connectionString());
    }
    zkclient.close();
    return brokerHosts;
}

From source file:com.hg.development.apps.messagenotifier_v1.Utils.Utility.java

/**
 * Permet de supprimer les doublons dans la liste des numros d'un contact.
 * @param duplicatelist Map contenant l'id du contact et le numro correspondant.
 * @return la liste des numros d'un contact sans doublons.
 *///from  w ww.j a  va  2s .  c  om
public static List<com.hg.development.apps.messagenotifier_v1.Contact.Person.Number> removeNumbersDuplicated(
        Map<String, Number> duplicatelist) {
    try {
        List<com.hg.development.apps.messagenotifier_v1.Contact.Person.Number> list = new ArrayList<>();

        Set set = duplicatelist.entrySet();
        Iterator i = set.iterator();

        while (i.hasNext()) {
            Map.Entry me = (Map.Entry) i.next();

            Number number = (Number) me.getValue();

            if (!list.contains(number))
                list.add((Number) me.getValue());
        }

        return list;
    } catch (Exception ex) {
        throw ex;
    }
}

From source file:edu.uci.ics.jung.utils.PredicateUtils.java

/**
 * Returns a <code>Set</code> consisting of all edges <code>e</code> 
 * in graph <code>g</code> that satisfy predicate <code>p</code>,
 * that is, those for which <code>p.evaluate(e)</code> returns true.
 *//* www. ja va2  s  .  c om*/
public static Set getEdges(ArchetypeGraph g, Predicate p) {
    SubsetManager sm = (SubsetManager) g.getUserDatum(ArchetypeGraph.SUBSET_MANAGER);
    if (sm != null) {
        Set s = sm.getEdges(p);
        if (s != null)
            return s;
    }

    Set s = new HashSet();
    Set edges = g.getEdges();
    for (Iterator e_it = edges.iterator(); e_it.hasNext();) {
        ArchetypeEdge e = (ArchetypeEdge) e_it.next();
        if (p.evaluate(e))
            s.add(e);
    }
    return Collections.unmodifiableSet(s);
}