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.titilink.camel.rest.util.CommonUtils.java

/**
 * ?// w w w.  j  a  v  a 2s  .c o m
 *
 * @param instance
 * @throws OperationException
 */
private static <T> void checkParameterWithRawInfo(T instance) throws OperationException {
    Set<RootResponse> errorBoxs = ValidationUtil.validateExtend(instance);
    if (null != errorBoxs) {
        LOGGER.error("checkParameterWithRawInfo method error, instance={}, errorBoxs={}.",
                new Object[] { instance, errorBoxs });
        Iterator<RootResponse> it = errorBoxs.iterator();
        if (null != it && it.hasNext()) {
            RootResponse response = it.next();
            throw new OperationException(response.getCode(), response.getMessage());
        } else {
            throw new OperationException(CommonCode.INVALID_INPUT_PARAMETER, "Invalid input params");
        }
    }
}

From source file:com.aoindustries.website.signup.ServerConfirmationCompletedActionHelper.java

/**
 * Sends the customer emails and stores the successAddresses and failureAddresses as request attributes.
 *///  w  w w. jav a  2s  . c om
public static void sendCustomerSummaryEmails(ActionServlet servlet, HttpServletRequest request, String pkey,
        String statusKey, SiteSettings siteSettings, PackageDefinition packageDefinition,
        SignupCustomizeServerForm signupCustomizeServerForm,
        SignupCustomizeManagementForm signupCustomizeManagementForm, SignupBusinessForm signupBusinessForm,
        SignupTechnicalForm signupTechnicalForm, SignupBillingInformationForm signupBillingInformationForm) {
    Set<String> addresses = new HashSet<String>();
    addresses.add(signupTechnicalForm.getBaEmail());
    addresses.add(signupBillingInformationForm.getBillingEmail());
    Set<String> successAddresses = new HashSet<String>();
    Set<String> failureAddresses = new HashSet<String>();
    Iterator<String> I = addresses.iterator();
    while (I.hasNext()) {
        String address = I.next();
        boolean success = sendSummaryEmail(servlet, request, pkey, statusKey, address, siteSettings,
                packageDefinition, signupCustomizeServerForm, signupCustomizeManagementForm, signupBusinessForm,
                signupTechnicalForm, signupBillingInformationForm);
        if (success)
            successAddresses.add(address);
        else
            failureAddresses.add(address);
    }

    // Store request attributes
    request.setAttribute("successAddresses", successAddresses);
    request.setAttribute("failureAddresses", failureAddresses);
}

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

/**
 * Given a set of edges, creates a new <tt>Graph</tt> that contains all
 * of those edges, and at least all the vertices that are attached to them.
 * Uses <tt>{@link edu.uci.ics.jung.graph.filters.UnassembledGraph UnassembledGraph}</tt>
 * mechanism to create the graph. The parameter decides what to do with
 * disconnected vertices: <tt>true</tt> says that they should be
 * retained, <tt>false</tt> says that they should be discarded (with a
 * {@link edu.uci.ics.jung.graph.filters.impl.DropSoloNodesFilter DropSoloNodesFilter}).
 * /*from  www .j a  v a2 s.  co  m*/
 * @param edges
 *            A set of <tt>Edge</tt> s that want to be a part of a new
 *            <tt>Graph</tt>
 * @param retain
 *            Is true if all isolated vertices should be retained; is false if they
 *            should be discarded.
 * @return A graph, created with <tt>{@link edu.uci.ics.jung.graph.Graph#newInstance Graph.newInstance}</tt>,
 *         containing edges equivalent to (and that are copies of!) all the
 *         edges in the input set. Note that if the input is an empty set,
 *         <tt>null</tt> is returned.
 */
public static Graph edgeSetToGraph(Set edges, boolean retain) {
    if (edges.isEmpty())
        return null;
    Edge e = (Edge) edges.iterator().next();
    Graph g = (Graph) e.getGraph();
    Graph retval = new UnassembledGraph("edgeSetToGraph", g.getVertices(), edges, g).assemble();
    if (retain)
        return retval;
    else {
        return DropSoloNodesFilter.getInstance().filter(retval).assemble();
    }
}

From source file:at.ac.tuwien.dsg.cloud.salsa.engine.utils.SystemFunctions.java

public static List<String> getEndPoints()
        throws MalformedObjectNameException, NullPointerException, UnknownHostException,
        AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    Set<ObjectName> objs = mbs.queryNames(new ObjectName("*:type=Connector,*"),
            Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
    String hostname = InetAddress.getLocalHost().getHostName();
    InetAddress[] addresses = InetAddress.getAllByName(hostname);
    ArrayList<String> endPoints = new ArrayList<>();
    for (Iterator<ObjectName> i = objs.iterator(); i.hasNext();) {
        ObjectName obj = i.next();
        String scheme = mbs.getAttribute(obj, "scheme").toString();
        String port = obj.getKeyProperty("port");
        for (InetAddress addr : addresses) {
            String host = addr.getHostAddress();
            String ep = scheme + "://" + host + ":" + port;
            endPoints.add(ep);//  www .ja v  a  2 s . c  o m
        }
    }
    return endPoints;
}

From source file:mj.ocraptor.extraction.tika.parser.pkg.ZipContainerDetector.java

@SuppressWarnings("unchecked")
private static MediaType detectIpa(ZipFile zip) {
    // Note - consider generalising this logic, if another format needs many regexp matching
    Set<Pattern> tmpPatterns = (Set<Pattern>) ipaEntryPatterns.clone();

    Enumeration<ZipArchiveEntry> entries = zip.getEntries();
    while (entries.hasMoreElements()) {
        ZipArchiveEntry entry = entries.nextElement();
        String name = entry.getName();

        Iterator<Pattern> ip = tmpPatterns.iterator();
        while (ip.hasNext()) {
            if (ip.next().matcher(name).matches()) {
                ip.remove();//from   w w  w.j  av a 2 s  .c o  m
            }
        }
        if (tmpPatterns.isEmpty()) {
            // We've found everything we need to find
            return MediaType.application("x-itunes-ipa");
        }
    }

    // If we get here, not all required entries were found
    return null;
}

From source file:com.netflix.nicobar.core.utils.ClassPathUtils.java

private static Set<String> filterPathSet(Set<String> pathSet, Set<String> excludePrefixes,
        Set<String> includePrefixes) {
    Set<String> filteredSet = new HashSet<String>(pathSet);

    // Ideally, we would use a trie, but we are talking ~100s of paths and a few excludes and includes,
    // not to mention these are throw away scans and not reused typically.

    // First process the excludes
    for (String exclude : excludePrefixes) {
        Iterator<String> setIterator = filteredSet.iterator();
        while (setIterator.hasNext()) {
            String path = setIterator.next();
            if (path.startsWith(exclude))
                setIterator.remove();/*from  w  w w  .j a  va 2s  .c  o m*/
        }
    }

    // An empty set of includes indicates include everything
    if (includePrefixes.size() == 0) {
        return filteredSet;
    }

    // Now, create a filtered set based on the includes
    Iterator<String> setIterator = filteredSet.iterator();
    while (setIterator.hasNext()) {
        String path = setIterator.next();
        boolean shouldInclude = false;
        for (String include : includePrefixes) {
            if (path.startsWith(include)) {
                shouldInclude = true;
                break;
            }
        }

        // Remove if none of the includes specify this package path
        if (!shouldInclude) {
            setIterator.remove();
        }
    }

    return filteredSet;
}

From source file:org.ala.harvester.LocalCSVHarvester.java

private static void displayMapContent(Map<String, String> map) {
    Set<String> keyset = map.keySet();
    Iterator<String> iterator = keyset.iterator();

    while (iterator.hasNext()) {
        String key = iterator.next();
        String value = map.get(key);
        System.out.println("Key: " + key + ", value: " + value);
    }/*from   w ww.  java 2  s  .c  o  m*/
}

From source file:com.intuit.tank.common.ScriptUtil.java

/**
 * @param step//from  w w w .  j a  v  a 2 s . c om
 * @return
 */
private static String getStepLabel(ScriptStep step) {
    StringBuilder label = new StringBuilder();
    if (step.getType().equalsIgnoreCase(ScriptConstants.REQUEST)) {
        label.append(step.getProtocol()).append("://").append(step.getHostname()).append(step.getSimplePath());

        int qsCount = 0;
        if (step.getQueryStrings() != null) {
            for (RequestData qs : step.getQueryStrings()) {
                label.append(qsCount == 0 ? "?" : "&");
                label.append(qs.getKey()).append("=").append(qs.getValue());
                qsCount++;
            }
        }
    } else if (step.getType().equalsIgnoreCase(ScriptConstants.VARIABLE)) {
        Set<RequestData> setData = step.getData();
        if (null != setData) {
            Iterator<RequestData> iter = setData.iterator();
            while (iter.hasNext()) {
                RequestData d = iter.next();
                label.append("Variable definition " + d.getKey() + "=>" + d.getValue());
            }
        }
    } else if (step.getType().equalsIgnoreCase(ScriptConstants.AUTHENTICATION)) {
        Set<RequestData> setData = step.getData();
        if (null != setData) {
            String scheme = "ALL";
            String host = "";
            String user = "";
            Iterator<RequestData> iter = setData.iterator();
            while (iter.hasNext()) {
                RequestData d = iter.next();
                if (d.getKey().equals(ScriptConstants.AUTH_SCHEME)) {
                    scheme = d.getValue();
                } else if (d.getKey().equals(ScriptConstants.AUTH_HOST)) {
                    host = d.getValue();
                } else if (d.getKey().equals(ScriptConstants.AUTH_USER_NAME)) {
                    user = d.getValue();
                }
            }
            label.append("Authentication " + scheme + " [host: " + host + " user: " + user + "]");
        }
    } else if (step.getType().equalsIgnoreCase(ScriptConstants.THINK_TIME)) {

        String min = "0";
        String max = "0";
        Set<RequestData> setData = step.getData();
        if (null != setData) {
            Iterator<RequestData> iter = setData.iterator();
            while (iter.hasNext()) {
                RequestData d = iter.next();
                if (d.getKey().contains("min"))
                    min = d.getValue();
                else if (d.getKey().contains("max"))
                    max = d.getValue();
            }
        }
        label.append("Think time " + min + "-" + max);
    } else if (step.getType().equalsIgnoreCase(ScriptConstants.LOGIC)) {
        label.append("Logic Step: " + step.getName());
    } else if (step.getType().equalsIgnoreCase(ScriptConstants.COOKIE)) {
        String name = "";
        String value = "";
        for (RequestData requestData : step.getData()) {
            if (ScriptConstants.COOKIE_NAME.equals(requestData.getKey())) {
                name = requestData.getValue();
            }
            if (ScriptConstants.COOKIE_VALUE.equals(requestData.getKey())) {
                value = requestData.getValue();
            }
            // if (ScriptConstants.COOKIE_DOMAIN.equals(requestData.getKey())) {
            // domain = requestData.getValue();
            // }
        }
        label.append("Set Cookie: ").append(name).append(" = ").append(value).toString();
    } else if (step.getType().equalsIgnoreCase(ScriptConstants.SLEEP)) {

        Set<RequestData> setData = step.getData();
        if (null != setData) {
            Iterator<RequestData> iter = setData.iterator();
            while (iter.hasNext()) {
                RequestData d = iter.next();
                label.append("Sleep for " + d.getValue());
            }
        }
    } else if (step.getType().equalsIgnoreCase(ScriptConstants.CLEAR)) {
        label.append("Clear session");
    } else if (step.getType().equalsIgnoreCase(ScriptConstants.TIMER)) {
        String name = null;
        String timerAction = null;
        for (RequestData rd : step.getData()) {
            if (rd.getKey().equalsIgnoreCase(ScriptConstants.IS_START)) {
                timerAction = rd.getValue();
            }
            if (rd.getKey().equalsIgnoreCase(ScriptConstants.LOGGING_KEY)) {
                name = rd.getValue();
            }
        }

        label.append(name).append(":").append(timerAction);

    }
    return StringUtils.abbreviate(label.toString(), 1024);
}

From source file:com.egt.core.db.util.Reporter.java

private static Object[] getReportParametersArray(Map parameters) {
    if (parameters == null || parameters.isEmpty()) {
        return null;
    }//from   ww w . ja  va2  s  .c  o m
    int n = parameters.size();
    Object[] args = new Object[n];
    Set set = parameters.keySet();
    Iterator iterator = set.iterator();
    Object key;
    Object val;
    String psi;
    String str;
    for (int i = 0; i < n && iterator.hasNext(); i++) {
        key = iterator.next();
        val = parameters.get(key);
        if (val != null) {
            psi = val instanceof Long ? Global.PREFIJO_STRING_ID_RECURSO : "";
            str = StringUtils.trimToEmpty(STP.getString(val));
            args[i] = key + "=" + psi + str;
            Bitacora.trace("args [" + i + "] = " + key + "=(" + val.getClass().getSimpleName() + ")" + str);
        }
    }
    return args;
}

From source file:com.doculibre.constellio.services.SearchServicesImpl.java

private static void addTagsTo(SimpleSearch simpleSearch, SolrQuery query) {
    StringBuffer sb = new StringBuffer();
    Set<String> tags = simpleSearch.getTags();
    if (!tags.isEmpty()) {
        sb.append("(");
        for (Iterator<String> it = tags.iterator(); it.hasNext();) {
            String tag = it.next();
            sb.append("(");
            sb.append(IndexField.FREE_TEXT_TAGGING_FIELD + ":" + tag);
            sb.append(" OR ");
            sb.append(IndexField.THESAURUS_TAGGING_FIELD + ":" + tag);
            sb.append(")");
            if (it.hasNext()) {
                sb.append(" AND ");
            }//from  w  w w.  j a va 2  s .c o  m
        }
        sb.append(")");
    }
    query.addFilterQuery(sb.toString());
}