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.github.checkstyle.NotesBuilder.java

/**
 * Forms a string which represents the authors who are referenced in the commits.
 * @param commits commits./*from w w  w  . j  a  v a 2  s.  com*/
 * @return string which represents the authors who are referenced in the commits.
 */
private static String getAuthorsOf(Set<RevCommit> commits) {
    final Set<String> commitAuthors = findCommitAuthors(commits);
    return Joiner.on(SEPARATOR).join(commitAuthors.iterator());
}

From source file:com.sforce.cd.apexUnit.client.codeCoverage.WebServiceInvoker.java

public static JSONObject doGet(String relativeServiceURL, String accessToken) {

    LOG.debug("relativeServiceURL in doGet method:" + relativeServiceURL);
    HttpClient httpclient = new HttpClient();
    GetMethod get = null;//w w w  .  j  av a2s  . c o  m

    String authorizationServerURL = CommandLineArguments.getOrgUrl() + relativeServiceURL;
    get = new GetMethod(authorizationServerURL);
    get.addRequestHeader("Content-Type", "application/json");
    get.setRequestHeader("Authorization", "Bearer " + accessToken);
    LOG.debug("Start GET operation for the url..." + authorizationServerURL);
    InputStream instream = null;
    try {
        instream = executeHTTPMethod(httpclient, get, authorizationServerURL);
        LOG.debug("done with get operation");

        JSONObject json = (JSONObject) JSONValue.parse(new InputStreamReader(instream));
        LOG.debug("is json null? :" + json == null ? "true" : "false");
        if (json != null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("ToolingApi.get response: " + json.toString());
                Set<String> keys = castSet(String.class, json.keySet());
                Iterator<String> jsonKeyIter = keys.iterator();
                LOG.debug("Response for the GET method: ");
                while (jsonKeyIter.hasNext()) {
                    String key = jsonKeyIter.next();
                    LOG.debug("key : " + key + ". Value :  " + json.get(key) + "\n");
                    // TODO if query results are too large, only 1st batch
                    // of results
                    // are returned. Need to use the identifier in an
                    // additional query
                    // to retrieve rest of the next batch of results

                    if (key.equals("nextRecordsUrl")) {
                        // fire query to the value for this key
                        // doGet((String) json.get(key), accessToken);
                        try {
                            authorizationServerURL = CommandLineArguments.getOrgUrl() + (String) json.get(key);
                            get.setURI(new URI(authorizationServerURL, false));
                            instream = executeHTTPMethod(httpclient, get, authorizationServerURL);
                            JSONObject newJson = (JSONObject) JSONValue.parse(new InputStreamReader(instream));
                            if (newJson != null) {
                                Set<String> newKeys = castSet(String.class, json.keySet());
                                Iterator<String> newJsonKeyIter = newKeys.iterator();
                                while (newJsonKeyIter.hasNext()) {
                                    String newKey = newJsonKeyIter.next();
                                    json.put(newKey, newJson.get(newKey));
                                    LOG.debug("newkey : " + newKey + ". NewValue :  " + newJson.get(newKey)
                                            + "\n");
                                }
                            }

                        } catch (URIException e) {
                            ApexUnitUtils.shutDownWithDebugLog(e,
                                    "URI exception while fetching subsequent batch of result");
                        }
                    }

                }
            }
        }
        return json;
    } finally {
        get.releaseConnection();
        try {
            if (instream != null) {
                instream.close();

            }
        } catch (IOException e) {
            ApexUnitUtils.shutDownWithDebugLog(e,
                    "Encountered IO exception when closing the stream after reading response from the get method. The error says: "
                            + e.getMessage());
        }
    }
}

From source file:info.magnolia.cms.util.QueryUtil.java

/**
 * Creates a simple SQL2 query statement.
 * //  w  w  w  .j av a2s.  c  om
 * @param statement
 * @param startPath
 */
public static String buildQuery(String statement, String startPath) {
    Set<String> arguments = new HashSet<String>(
            Arrays.asList(StringUtils.splitByWholeSeparator(statement, ",")));

    Iterator<String> argIt = arguments.iterator();
    String queryString = "select * from [nt:base] as t where ISDESCENDANTNODE([" + startPath + "])";
    while (argIt.hasNext()) {
        queryString = queryString + " AND contains(t.*, '" + argIt.next() + "')";
    }
    log.debug("query string: " + queryString);
    return queryString;
}

From source file:de.mprengemann.intellij.plugin.androidicons.util.ExportNameUtils.java

public static String getExportDescription(List<ImageInformation> scalingInformationList) {
    Set<String> importFileNames = new HashSet<String>();
    for (ImageInformation information : scalingInformationList) {
        importFileNames.add(information.getImageFile().getName());
    }/* ww  w .  j a  v  a2  s.c o  m*/
    StringBuilder builder = new StringBuilder("Import of ");
    // No multi import
    if (importFileNames.size() == 1) {
        builder.append(importFileNames.iterator().next());
        if (scalingInformationList.size() == 1) {
            builder.append(" in resolution ");
        } else {
            builder.append(" in resolutions ");
        }
        for (Iterator<ImageInformation> iterator = scalingInformationList.iterator(); iterator.hasNext();) {
            ImageInformation information = iterator.next();
            builder.append(information.getTargetResolution());
            if (iterator.hasNext()) {
                builder.append(", ");
            }
        }
    } else {
        for (Iterator<String> iterator = importFileNames.iterator(); iterator.hasNext();) {
            String exportName = iterator.next();
            builder.append(exportName);
            if (iterator.hasNext()) {
                builder.append(", ");
            }
        }
        builder.append(" as ").append(scalingInformationList.get(0).getExportName());
    }
    return builder.toString();
}

From source file:net.sf.morph.util.TransformerUtils.java

/**
 * Get the mapped destination type from the specified typemap.
 * @param typeMapping Map// w w  w .ja  va2s. co  m
 * @param requestedType Class
 * @return Class
 */
public static Class getMappedDestinationType(Map typeMapping, Class requestedType) {
    if (typeMapping == null) {
        return null;
    }
    // see if the requested type has been directly mapped to some other type
    Class mappedDestinationType = (Class) typeMapping.get(requestedType);
    // see if the requested type has been indirectly mapped to some other type
    if (mappedDestinationType == null) {
        Set keys = typeMapping.keySet();
        for (Iterator i = keys.iterator(); i.hasNext();) {
            Class type = (Class) i.next();
            if (type.isAssignableFrom(requestedType)) {
                mappedDestinationType = (Class) typeMapping.get(type);
                break;
            }
        }
    }
    return mappedDestinationType;
}

From source file:com.netspective.axiom.TestUtils.java

static public void setupDb(String connProviderId, boolean createDb, boolean loadData) {
    Log log = LogFactory.getLog(TestUtils.class);

    Set connContextsWithOpenConnections = new HashSet(
            AbstractConnectionContext.getConnectionContextsWithOpenConnections());

    for (Iterator i = connContextsWithOpenConnections.iterator(); i.hasNext();) {
        ConnectionContext cc = (ConnectionContext) i.next();

        cc.rollbackAndCloseAndLogAsConnectionLeak(log, null);
    }//from   w w w .  j a va2 s . c  o m

    String classDir = connProviderId.replace('.', '/');

    FileFind.FileFindResults ffr = FileFind.findInClasspath(classDir + "/" + schemaFilename,
            FileFind.FINDINPATHFLAG_SEARCH_RECURSIVELY);
    if (!ffr.isFileFound()) {
        ffr = FileFind.findInClasspath(classDir + "-" + schemaFilename,
                FileFind.FINDINPATHFLAG_SEARCH_RECURSIVELY);
    }

    if (!ffr.isFileFound()) {
        return;
    }

    File schemaFile = ffr.getFoundFile();
    String rootPath = schemaFile.getParentFile().getAbsolutePath();

    Project project = new Project();

    Target target = new Target();
    target.setName("generate-ddl");

    AxiomTask task = new AxiomTask();
    task.setTaskName("generate-ddl");
    task.setSchema("db");
    task.setDdl("*");
    task.setProjectFile(new File(rootPath + "/" + schemaFilename));
    task.setDestDir(new File(rootPath + ddlPath));

    target.addTask(task);
    project.addTarget(target);
    task.setProject(project);

    SqlManager manager = task.getSqlManager();
    task.generateDdlFiles(manager);

    if (!createDb)
        return;

    SQLExec sqlExec = new SQLExec();
    target.addTask(sqlExec);
    sqlExec.setProject(project);
    File dbFolder = new File(rootPath + dbPath);

    //need to do a recursive delete or call the deleteTree ant task
    Delete del = new Delete();
    target.addTask(del);
    del.setProject(project);
    del.setDir(dbFolder);
    del.execute();

    dbFolder.mkdir();

    sqlExec.setSrc(new File(rootPath + ddlPath + "/db-hsqldb.sql"));
    sqlExec.setDriver("org.hsqldb.jdbcDriver");
    sqlExec.setUrl("jdbc:hsqldb:" + rootPath + dbPath + "/" + dbName);
    sqlExec.setUserid("sa");
    sqlExec.setPassword("");
    sqlExec.execute();

    //TODO: If we ever need to generate the DAL, then the trick is how to compile the classes that use it.
    //      For now, we leve it here for code coverage purposes, since it is excercising the DAL Generator
    String testRoot = rootPath.substring(0, rootPath.length() - connProviderId.length() - 1);
    task.setDestDir(new File(testRoot));
    task.setDalPackage(connProviderId + ".dal");
    task.generateDalFiles(manager);

    if (!loadData)
        return;

    task.setImport(new File(rootPath + "/" + dataImportFile));
    task.setDtdFile(new File(rootPath + dataImportDtdFile));
    task.generateImportDtd(manager);

    task.setDriver("org.hsqldb.jdbcDriver");
    task.setUrl("jdbc:hsqldb:" + rootPath + dbPath + "/" + dbName);
    task.setUserId("sa");
    task.setPassword("");
    task.importData(manager);

    connProvider.addDataSourceInfo(connProviderId, "org.hsqldb.jdbcDriver",
            "jdbc:hsqldb:" + rootPath + dbPath + File.separator + dbName, "sa", "");

}

From source file:net.sf.morph2.util.TransformerUtils.java

/**
 * Get the mapped destination type from the specified typemap.
 * @param typeMapping Map/*w  ww  . jav a  2 s . c  o m*/
 * @param requestedType Class
 * @return Class
 */
public static Class getMappedDestinationType(Map typeMapping, Class requestedType) {
    if (typeMapping == null) {
        return null;
    }
    // see if the requested type has been directly mapped to some other type
    Class mappedDestinationType = (Class) typeMapping.get(requestedType);
    // see if the requested type has been indirectly mapped to some other
    // type
    if (mappedDestinationType == null) {
        Set keys = typeMapping.keySet();
        for (Iterator i = keys.iterator(); i.hasNext();) {
            Class type = (Class) i.next();
            if (type.isAssignableFrom(requestedType)) {
                mappedDestinationType = (Class) typeMapping.get(type);
                break;
            }
        }
    }
    return mappedDestinationType;
}

From source file:fr.mixit.android.utils.NetworkUtils.java

static String buildParams(HashMap<String, String> args) {
    if (args != null && !args.isEmpty()) {
        final StringBuilder params = new StringBuilder();
        final Set<String> keys = args.keySet();
        for (final Iterator<String> iterator = keys.iterator(); iterator.hasNext();) {
            final String key = iterator.next();
            final String value = args.get(key);

            params.append(key);/* w ww . j a va  2s.  c om*/
            params.append(EQUAL);
            params.append(value);
            if (iterator.hasNext()) {
                params.append(AND);
            }
        }

        return params.toString();
    }
    return null;
}

From source file:edu.indiana.lib.twinpeaks.util.StatusUtils.java

/**
 * Get an iterator into the system status map
 * @param sessionContext Active SessionContext
 * @return Status map Iterator/*  w  w  w .j ava2s  . c o m*/
 */
public static Iterator getStatusMapEntrySetIterator(SessionContext sessionContext) {
    HashMap statusMap = (HashMap) sessionContext.get("searchStatus");
    Set entrySet = Collections.EMPTY_SET;

    if (statusMap != null) {
        entrySet = statusMap.entrySet();
    }
    return entrySet.iterator();
}

From source file:uk.ac.ebi.eva.test.utils.JobTestUtils.java

/**
 * reads the file and sorts it in memory to return the first ordered line. Don't use for big files!
 * @param file to be sorted//from   w ww.  j  av  a2 s. co  m
 * @return String, the first orderec line
 * @throws IOException
 */
public static String readFirstLine(File file) throws IOException {
    Set<String> lines = new TreeSet<>();
    try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
        String line = reader.readLine();
        while (line != null) {
            lines.add(line);
            line = reader.readLine();
        }
    }
    return lines.iterator().next();
}