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:com.evolveum.midpoint.prism.xml.XsdTypeMapper.java

public static <T> Class<T> getXsdToJavaMapping(QName xsdType) {
    Class clazz = xsdToJavaTypeMap.get(xsdType);
    if (clazz == null) {
        Set<QName> keys = xsdToJavaTypeMap.keySet();
        for (Iterator<QName> iterator = keys.iterator(); iterator.hasNext();) {
            QName key = iterator.next();
            if (QNameUtil.match(key, xsdType)) {
                return xsdToJavaTypeMap.get(key);
            }//from w  w w  . java  2  s  . c o m
        }
    }
    return xsdToJavaTypeMap.get(xsdType);
}

From source file:Main.java

public static <T> Set<T> addSorted(Set<T> set, T element) {
    final int size = set.size();
    if (size == 0) {
        return ImmutableSet.of(element);
    } else if (set instanceof ImmutableSet) {
        if (size == 1) {
            final T val = set.iterator().next();
            set = Sets.newLinkedHashSet();
            set.add(val);
        } else {/*w  w  w.  j av a  2  s .c  om*/
            set = Sets.newLinkedHashSet(set);
        }
    }
    set.add(element);
    return set;
}

From source file:Main.java

public static <T> Set<T> add(Set<T> set, T element) {
    final int size = set.size();
    if (size == 0) {
        return ImmutableSet.of(element);
    } else if (set instanceof ImmutableSet) {
        if (size == 1) {
            final T val = set.iterator().next();
            set = Sets.newHashSet();/*from w  w w  .  jav  a  2 s. c  o  m*/
            set.add(val);
        } else {
            set = Sets.newHashSet(set);
        }
    }
    set.add(element);
    return set;
}

From source file:edu.uci.ics.jung.graph.impl.BipartiteGraph.java

/**
 * Adds all pairs (key, value) to the multimap from
 * the initial set keySet./*from w  w  w  . j a v  a  2s.  c o  m*/
 * @param set
 * @param hyperEdge
 */
private static void addAll(MultiMap mm, Set keyset, Object value) {
    for (Iterator iter = keyset.iterator(); iter.hasNext();) {
        Object key = iter.next();
        mm.put(key, value);
    }
}

From source file:interactivespaces.service.web.server.internal.netty.NettyHttpRequest.java

private static String createPortString(Set<Integer> ports) {
    StringBuilder portString = new StringBuilder();
    Iterator<Integer> iter = ports.iterator();
    while (iter.hasNext()) {
        portString.append(String.valueOf(iter.next()));
        if (iter.hasNext()) {
            portString.append(",");
        }//from   w ww  .j  a v  a2  s  .  c  o m
    }

    return portString.toString();
}

From source file:org.eel.kitchen.jsonschema.ref.JsonPointerTest.java

private static Iterator<Object[]> nodeToDataProvider(final JsonNode node) {
    final Map<String, JsonNode> map = JacksonUtils.nodeToMap(node);

    final Set<Object[]> set = Sets.newHashSet();

    for (final Map.Entry<String, JsonNode> entry : map.entrySet())
        set.add(new Object[] { entry.getKey(), entry.getValue() });

    return set.iterator();
}

From source file:net.sf.ehcache.config.ConfigurationFactory.java

/**
 * Translates system properties which can be added as tokens to the config file using ${token} syntax.
 * <p/>//from   w w w  .  ja v  a  2s .  c om
 * So, if the config file contains a character sequence "multicastGroupAddress=${multicastAddress}", and there is a system property
 * multicastAddress=230.0.0.12 then the translated sequence becomes "multicastGroupAddress=230.0.0.12"
 *
 * @param inputStream
 * @return a translated stream
 */
private static InputStream translateSystemProperties(InputStream inputStream) throws IOException {

    StringBuffer stringBuffer = new StringBuffer();
    int c;
    while ((c = inputStream.read()) != -1) {
        stringBuffer.append((char) c);
    }
    String configuration = stringBuffer.toString();

    Set tokens = extractPropertyTokens(configuration);
    Iterator tokenIterator = tokens.iterator();
    while (tokenIterator.hasNext()) {
        String token = (String) tokenIterator.next();
        String leftTrimmed = token.replaceAll("\\$\\{", "");
        String trimmedToken = leftTrimmed.replaceAll("\\}", "");

        String property = System.getProperty(trimmedToken);
        if (property == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Did not find a system property for the " + token
                        + " token specified in the configuration.Replacing with \"\"");
            }
        } else {
            configuration = configuration.replaceAll("\\$\\{" + trimmedToken + "\\}", property);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Found system property value of " + property + " for the " + token
                        + " token specified in the configuration.");
            }
        }
    }
    return new ByteArrayInputStream(configuration.getBytes());
}

From source file:Main.java

/**
 *
 * @param columnName/*from w ww .  j a va 2 s. c om*/
 * @param objects
 * @return
 */
private static String getQueryPartId(final String columnName, final Set<String> objects) {

    final StringBuilder queryPart = new StringBuilder();
    String queryPartString = "";

    // TODO or rule for every id
    if (objects != null && !objects.isEmpty()) {
        final Iterator<String> it = objects.iterator();

        while (it.hasNext()) {
            final String id = it.next();

            queryPart.append(columnName).append('=' + "\'\"").append(id).append("\"\'");
            if (it.hasNext()) {
                queryPart.append(" OR ");
            }
        }
        queryPartString = queryPart.toString();
    }

    return queryPartString;
}

From source file:com.gargoylesoftware.htmlunit.general.HostExtractor.java

private static void ensure(final File file, final Set<String> set) throws IOException {
    final Set<String> unusedNames = new HashSet<>(set);
    final List<String> lines = FileUtils.readLines(file);
    for (final String line : lines) {
        for (final Iterator<String> it = unusedNames.iterator(); it.hasNext();) {
            if (line.contains("(\"" + it.next() + "\")")) {
                it.remove();//from  w  w w.j av  a 2 s .  c  o  m
            }
        }
    }
    unusedNames.remove("this");
    unusedNames.remove("Boolean");
    unusedNames.remove("null");

    if (!unusedNames.isEmpty()) {
        for (final String name : unusedNames) {
            if (name.contains(" ")) {
                continue;
            }
            System.out.println("");
            System.out.println("    /**");
            System.out.println("     * @throws Exception if the test fails");
            System.out.println("     */");
            System.out.println("    @Test");
            System.out.println("    @Alerts(\"exception\")");
            String methodName = name;
            for (final String prefix : PREFIXES_) {
                if (methodName.startsWith(prefix)) {
                    methodName = prefix.toLowerCase(Locale.ROOT) + methodName.substring(prefix.length());
                    break;
                }
            }
            if (Character.isUpperCase(methodName.charAt(0))) {
                methodName = Character.toLowerCase(methodName.charAt(0)) + methodName.substring(1);
            }
            methodName = methodName.replace(".", "_");
            System.out.println("    public void " + methodName + "() throws Exception {");
            System.out.println("        test(\"" + name + "\");");
            System.out.println("    }");
        }
    }
    for (final String name : unusedNames) {
        if (name.contains(" ")) {
            System.out.println("Ignoring: " + name);
        }
    }
}

From source file:Main.java

protected static Set unionEmail(Set excluded, String email) {
    String _sub = email.substring(email.indexOf('@') + 1);

    if (excluded.isEmpty()) {
        excluded.add(_sub);//ww w  .  j  a v a 2s  . c  o m
        return excluded;
    } else {
        Set intersect = new HashSet();

        Iterator _iter = excluded.iterator();
        while (_iter.hasNext()) {
            String _excluded = (String) _iter.next();

            if (_sub.endsWith(_excluded)) {
                intersect.add(_excluded);
            } else if (_excluded.endsWith(_sub)) {
                intersect.add(_sub);
            } else {
                intersect.add(_excluded);
                intersect.add(_sub);
            }
        }

        return intersect;
    }
}