Example usage for java.util HashMap keySet

List of usage examples for java.util HashMap keySet

Introduction

In this page you can find the example usage for java.util HashMap keySet.

Prototype

public Set<K> keySet() 

Source Link

Document

Returns a Set view of the keys contained in this map.

Usage

From source file:eu.sisob.uma.crawler.MatrixResultBuilder.java

public static void writeResultsList(File file, HashMap<String, Integer> universities_axis,
        HashMap<String, Integer> dept_axis,
        HashMap<String, HashMap<String, Map.Entry<Integer, Integer>>> resultsMatrix) {
    Map.Entry<Integer, Integer>[][] matrix = (Map.Entry<Integer, Integer>[][]) new Map.Entry[universities_axis
            .size()][dept_axis.size()];//from   ww  w  .j a  v a2s. com
    String[] cols = new String[universities_axis.size()];
    String[] rows = new String[dept_axis.size()];

    int total_researchers = 0;
    int success_researchers = 0;

    for (String j : resultsMatrix.keySet()) {
        cols[universities_axis.get(j)] = j;
        for (String k : resultsMatrix.get(j).keySet()) {
            rows[dept_axis.get(k)] = k;
        }
    }

    for (String j : resultsMatrix.keySet()) {
        for (String k : resultsMatrix.get(j).keySet()) {
            Map.Entry<Integer, Integer> r = resultsMatrix.get(j).get(k);

            int x = universities_axis.get(j);
            int y = dept_axis.get(k);

            matrix[x][y] = r;

            success_researchers += r.getKey();
            total_researchers += r.getValue();
        }
    }

    String s = "\"UNIVERSITY\"\t\"SUBJECT\"\t\"RESEARCHERS FOUND\"\t\"TOTAL RESEARCHERS\"";
    s += "\r\n";

    try {
        FileUtils.write(file, s, "UTF-8", false);
    } catch (IOException ex) {
        ProjectLogger.LOGGER.error("Error writing results list");
    }

    s = "";

    for (int i = 0; i < matrix.length; i++) {
        for (int j = 0; j < matrix[i].length; j++) {
            if (matrix[i][j] != null) {
                s += "\"" + cols[i] + "\"\t\"" + rows[j] + "\"\t" + matrix[i][j].getKey() + "\t"
                        + matrix[i][j].getValue();
                s += "\r\n";
            }
        }

        if (s.length() > 1000) {
            try {
                FileUtils.write(file, s, "UTF-8", true);
            } catch (IOException ex) {
                ProjectLogger.LOGGER.error("Error writing matrix results");
            }
            s = "";
        }
    }

    s += "\r\nRESEARCHERS FOUND\t" + success_researchers;
    s += "\r\nNUMBER OF RESEARCHERS\t" + total_researchers;

    if (!s.equals("")) {
        try {
            FileUtils.write(file, s, "UTF-8", true);
        } catch (IOException ex) {
            ProjectLogger.LOGGER.error("Error writing matrix results");
        }
    }
}

From source file:eu.sisob.uma.crawler.MatrixResultBuilder.java

public static void writeResultsMatrix(File file, HashMap<String, Integer> universities_axis,
        HashMap<String, Integer> dept_axis,
        HashMap<String, HashMap<String, Map.Entry<Integer, Integer>>> resultsMatrix) {
    Map.Entry<Integer, Integer>[][] matrix = (Map.Entry<Integer, Integer>[][]) new Map.Entry[universities_axis
            .size()][dept_axis.size()];//from w w  w  .ja  v a  2 s.  c o  m
    String[] cols = new String[universities_axis.size()];
    String[] rows = new String[dept_axis.size()];

    int total_researchers = 0;
    int success_researchers = 0;

    for (String j : resultsMatrix.keySet()) {
        cols[universities_axis.get(j)] = j;
        for (String k : resultsMatrix.get(j).keySet()) {
            rows[dept_axis.get(k)] = k;
        }
    }

    for (String j : resultsMatrix.keySet()) {
        for (String k : resultsMatrix.get(j).keySet()) {
            Map.Entry<Integer, Integer> r = resultsMatrix.get(j).get(k);

            int x = universities_axis.get(j);
            int y = dept_axis.get(k);

            matrix[x][y] = r;

            success_researchers += r.getKey();
            total_researchers += r.getValue();
        }
    }

    try {
        FileUtils.write(file, "RESULTS TABLE\r\n", "UTF-8", false);
    } catch (IOException ex) {
        ProjectLogger.LOGGER.error("Error writing results matrix");
    }

    String s = "#\t";
    for (int i = 0; i < rows.length; i++) {
        s += rows[i] + "\t";
    }
    s += "\r\n";
    for (int i = 0; i < matrix.length; i++) {
        s += cols[i] + "\t";
        for (int j = 0; j < matrix[i].length; j++) {
            if (matrix[i][j] != null)
                s += matrix[i][j].getKey() + "/" + matrix[i][j].getValue() + "\t";
            else
                s += "\t";
        }
        s += "\r\n";
        if (s.length() > 1000) {
            try {
                FileUtils.write(file, s, "UTF-8", true);
            } catch (IOException ex) {
                ProjectLogger.LOGGER.error("Error writing matrix results");
            }
            s = "";
        }
    }

    if (!s.equals("")) {
        try {
            FileUtils.write(file, s, "UTF-8", true);
        } catch (IOException ex) {
            ProjectLogger.LOGGER.error("Error writing matrix results");
        }
    }

    s = "\r\nTOTAL RESEARCHER = " + total_researchers + " - RESEARCHERS WITH RESULTS: " + success_researchers;
    try {
        FileUtils.write(file, s, "UTF-8", true);
    } catch (IOException ex) {
        ProjectLogger.LOGGER.error("Error writing matrix results");
    }
}

From source file:com.microsoft.tfs.core.httpclient.HttpState.java

/**
 * Find matching {@link Credentials credentials} for the given
 * authentication scope./*  www.  ja v a  2s .  co  m*/
 *
 * @param map
 *        the credentials hash map
 * @param token
 *        the {@link AuthScope authentication scope}
 * @return the credentials
 *
 */
private static Credentials matchCredentials(final HashMap<AuthScope, Credentials> map,
        final AuthScope authscope) {
    // see if we get a direct hit
    Credentials creds = map.get(authscope);

    if (creds == null) {
        // Nope.
        // Do a full scan
        int bestMatchFactor = -1;
        AuthScope bestMatch = null;
        final Iterator<AuthScope> items = map.keySet().iterator();
        while (items.hasNext()) {
            final AuthScope current = items.next();
            final int factor = authscope.match(current);
            if (factor > bestMatchFactor) {
                bestMatchFactor = factor;
                bestMatch = current;
            }
        }
        if (bestMatch != null) {
            creds = map.get(bestMatch);
        }
    }
    return creds;
}

From source file:es.bsc.servicess.ide.editors.deployers.ImageCreation.java

public static String getFullImageDescription(ProjectMetadata prMeta, HashMap<String, ServiceElement> allEls) {
    String[] els = allEls.keySet().toArray(new String[allEls.size()]);
    Map<String, Integer> minCoreInstances = prMeta.getMinElasticity(els);
    Map<String, String> maxConstraints = new HashMap<String, String>();
    Map<String, String> maxResourcesPerMachine = prMeta.getMaxResourcesProperties();
    Map<String, Integer> minCoreInstancesPerMachine = BuildingDeploymentFormPage.getConstraintsElements(els,
            allEls, minCoreInstances, maxResourcesPerMachine, maxConstraints);
    return generateTemplate(maxConstraints);
}

From source file:com.evolveum.polygon.test.scim.StandardScimTestUtils.java

public static ScimConnectorConfiguration buildConfiguration(HashMap<String, String> configuration) {
    ScimConnectorConfiguration scimConnectorConfiguration = new ScimConnectorConfiguration();

    for (String configurationParameter : configuration.keySet()) {

        if ("clientID".equals(configurationParameter)) {
            scimConnectorConfiguration.setClientID(configuration.get(configurationParameter));
        } else if ("clientSecret".equals(configurationParameter)) {
            scimConnectorConfiguration.setClientSecret(configuration.get(configurationParameter));
        } else if ("endpoint".equals(configurationParameter)) {
            scimConnectorConfiguration.setEndpoint(configuration.get(configurationParameter));
        } else if ("loginUrl".equals(configurationParameter)) {
            scimConnectorConfiguration.setLoginURL(configuration.get(configurationParameter));
        } else if ("password".equals(configurationParameter)) {
            char[] passChars = configuration.get(configurationParameter).toCharArray();
            GuardedString guardedPass = new GuardedString(passChars);
            scimConnectorConfiguration.setPassword(guardedPass);
        } else if ("service".equals(configurationParameter)) {
            scimConnectorConfiguration.setService(configuration.get(configurationParameter));
        } else if ("userName".equals(configurationParameter)) {
            scimConnectorConfiguration.setUserName(configuration.get(configurationParameter));
        } else if ("version".equals(configurationParameter)) {
            scimConnectorConfiguration.setVersion(configuration.get(configurationParameter));
        } else if ("authentication".equals(configurationParameter)) {
            scimConnectorConfiguration.setAuthentication(configuration.get(configurationParameter));
        } else if ("baseurl".equals(configurationParameter)) {
            scimConnectorConfiguration.setBaseUrl(configuration.get(configurationParameter));
        } else if ("token".equals(configurationParameter)) {
            char[] tokenCharacters = configuration.get(configurationParameter).toCharArray();
            GuardedString guardedToken = new GuardedString(tokenCharacters);
            scimConnectorConfiguration.setToken(guardedToken);

        } else if ("proxy".equals(configurationParameter)) {
            scimConnectorConfiguration.setProxyUrl(configuration.get(configurationParameter));
        } else if ("proxy_port_number".equals(configurationParameter)) {
            String parameterValue = configuration.get(configurationParameter);
            if (!parameterValue.isEmpty()) {
                Integer portNumber = Integer.parseInt(parameterValue);
                scimConnectorConfiguration.setProxyPortNumber(portNumber);
            } else
                scimConnectorConfiguration.setProxyPortNumber(null);
        } else {// w  w w. j  av a2 s  . c om

            LOGGER.warn("Occurrence of an non defined parameter");
        }
    }
    return scimConnectorConfiguration;

}

From source file:org.wso2.mdm.qsg.utils.HTTPInvoker.java

public static HTTPResponse sendHTTPPostWithOAuthSecurity(String url, HttpEntity entity,
        HashMap<String, String> headers) {
    HttpPost post = null;/*w  w w .  j  a  v  a 2  s . co m*/
    HttpResponse response = null;
    HTTPResponse httpResponse = new HTTPResponse();
    CloseableHttpClient httpclient = null;
    try {
        httpclient = (CloseableHttpClient) createHttpClient();
        post = new HttpPost(url);
        post.setEntity(entity);
        for (String key : headers.keySet()) {
            post.setHeader(key, headers.get(key));
        }
        post.setHeader(Constants.Header.AUTH, OAUTH_BEARER + oAuthToken);
        response = httpclient.execute(post);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyStoreException e) {
        e.printStackTrace();
    } catch (KeyManagementException e) {
        e.printStackTrace();
    }

    BufferedReader rd = null;
    try {
        rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    } catch (IOException e) {
        e.printStackTrace();
    }

    StringBuffer result = new StringBuffer();
    String line = "";
    try {
        while ((line = rd.readLine()) != null) {
            result.append(line);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    httpResponse.setResponseCode(response.getStatusLine().getStatusCode());
    httpResponse.setResponse(result.toString());
    try {
        httpclient.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return httpResponse;
}

From source file:free.yhc.netmbuddy.utils.Utils.java

public static Object[] getSortedKeyOfTimeMap(HashMap<? extends Object, Long> timeMap) {
    TimeElem[] te = new TimeElem[timeMap.size()];
    Object[] vs = timeMap.keySet().toArray(new Object[0]);
    for (int i = 0; i < vs.length; i++)
        te[i] = new TimeElem(vs[i], timeMap.get(vs[i]));
    Arrays.sort(te, sTimeElemComparator);
    Object[] sorted = new Object[vs.length];
    for (int i = 0; i < sorted.length; i++)
        sorted[i] = te[i].v;/*from   w  ww.j a  v a  2  s. c  o  m*/

    return sorted;
}

From source file:org.wso2.mdm.qsg.utils.HTTPInvoker.java

public static HTTPResponse sendHTTPPostWithURLParams(String url, List<NameValuePair> params,
        HashMap<String, String> headers) {
    HttpPost post = null;/*from   w ww.j a  v  a2 s .  co  m*/
    HttpResponse response = null;
    CloseableHttpClient httpclient = null;
    HTTPResponse httpResponse = new HTTPResponse();
    try {
        httpclient = (CloseableHttpClient) createHttpClient();
        post = new HttpPost(url);
        post.setEntity(new UrlEncodedFormEntity(params));
        for (String key : headers.keySet()) {
            post.setHeader(key, headers.get(key));
        }
        response = httpclient.execute(post);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyStoreException e) {
        e.printStackTrace();
    } catch (KeyManagementException e) {
        e.printStackTrace();
    }

    BufferedReader rd = null;
    try {
        rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    } catch (IOException e) {
        e.printStackTrace();
    }

    StringBuffer result = new StringBuffer();
    String line = "";
    try {
        while ((line = rd.readLine()) != null) {
            result.append(line);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    httpResponse.setResponseCode(response.getStatusLine().getStatusCode());
    httpResponse.setResponse(result.toString());
    return httpResponse;
}

From source file:org.samjoey.graphing.GraphUtility.java

public static void createGraphs(LinkedList<Game> games) {
    HashMap<String, XYSeriesCollection> datasets = new HashMap<>();
    for (Game game : games) {
        for (String key : game.getVarData().keySet()) {
            if (datasets.containsKey(key)) {
                try {
                    datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
                } catch (Exception e) {
                }//from  ww  w .  j a va  2 s.co  m
            } else {
                datasets.put(key, new XYSeriesCollection());
                datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
            }
        }
    }

    for (String key : datasets.keySet()) {
        JFrame f = new JFrame();
        JFreeChart chart = ChartFactory.createXYLineChart(key, // chart title
                "X", // x axis label
                "Y", // y axis label
                datasets.get(key), // data
                PlotOrientation.VERTICAL, false, // include legend
                true, // tooltips
                false // urls
        );
        XYPlot plot = chart.getXYPlot();
        XYItemRenderer rend = plot.getRenderer();
        for (int i = 0; i < games.size(); i++) {
            Game g = games.get(i);
            if (g.getWinner() == 1) {
                rend.setSeriesPaint(i, Color.RED);
            }
            if (g.getWinner() == 2) {
                rend.setSeriesPaint(i, Color.BLACK);
            }
            if (g.getWinner() == 0) {
                rend.setSeriesPaint(i, Color.PINK);
            }
        }
        ChartPanel chartPanel = new ChartPanel(chart);
        f.setContentPane(chartPanel);
        f.pack();
        RefineryUtilities.centerFrameOnScreen(f);
        f.setVisible(true);
    }
}

From source file:com.liferay.portal.action.LoginAction.java

public static void addSessionAttributes(HttpSession ses, HashMap map) {
    if (map == null)
        return;//  ww  w .  j  a  v a  2 s .  c o  m
    Set keys = map.keySet();
    if (keys == null)
        return;

    Iterator iter = keys.iterator();
    while (iter.hasNext()) {
        String name = (String) iter.next();
        ses.setAttribute(name, map.get(name));
    }
}