Example usage for java.util Map keySet

List of usage examples for java.util Map keySet

Introduction

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

Prototype

Set<K> keySet();

Source Link

Document

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

Usage

From source file:Main.java

public static String urlBuilderForGetMethod(Map<String, String> g_map) {

    StringBuilder sbr = new StringBuilder();
    int i = 0;/*from   w w w  . j  av  a2 s .c  o  m*/
    if (g_map.containsKey("url")) {
        sbr.append(g_map.get("url"));
        g_map.remove("url");
    }
    for (String key : g_map.keySet()) {
        if (i != 0) {
            sbr.append("&");
        }
        sbr.append(key + "=" + g_map.get(key));
        i++;
    }
    System.out.println("Builder url = " + sbr.toString());
    return sbr.toString();
}

From source file:com.sequenceiq.ambari.shell.support.TableRenderer.java

/**
 * Renders a 2 columns wide table with the given headers and rows. If headers are provided it should match with the
 * number of columns.//  w ww .j ava 2  s  .  c o m
 *
 * @param rows    rows of the table, each value will be added as a new row with the same key
 * @param headers headers of the table
 * @return formatted table
 */
public static String renderMultiValueMap(Map<String, List<String>> rows, String... headers) {
    Table table = createTable(headers);
    if (rows != null) {
        for (String key : rows.keySet()) {
            List<String> values = rows.get(key);
            if (values != null) {
                for (String value : values) {
                    table.addRow(key, value);
                }
            }
        }
    }
    return format(table);
}

From source file:net.jcreate.e3.table.html.HTMLTableHelper.java

public static NavRequest getNavRequest(String pTableID, WebContext pWebContext, int pPageSize) {

    Boolean enableStateManager = (Boolean) pWebContext
            .getSessionAttribute(TableConstants.ENABLED_STATE_MANAGER_PREFIX + pTableID);
    String start = pWebContext.getParameter(TableConstants.START_PARAM + "_" + pTableID);
    if (start == null) {//???????.
        if (enableStateManager != null) {
            if (enableStateManager.booleanValue() == true) {
                NavRequest result = getNavRequestFromState(pTableID, pWebContext);
                if (result != null) {
                    return result;
                }/*w ww .  j  a  v a 2 s. com*/
            }
        }
    }
    NavRequest result = new NavRequest();
    //?
    if (logger.isDebugEnabled()) {
        Map params = pWebContext.getParameterMap();
        java.util.Iterator paramKeys = params.keySet().iterator();
        while (paramKeys.hasNext()) {
            Object key = paramKeys.next();
            if (key instanceof String == false) {
                continue;
            }
            Object value = params.get(key);

            if (value instanceof String[] == false) {
                continue;
            }
            //?
            logger.debug((String) (key) + "=" + ((String[]) value)[0]);
        }
    }
    String pageSize = pWebContext.getParameter(TableConstants.PAGE_SIZE_PARAM + "_" + pTableID);
    String sortColumn = pWebContext.getParameter(TableConstants.SORT_PROPERTY_PARAM + "_" + pTableID);
    String sortName = pWebContext.getParameter(TableConstants.SORT_NAME_PARAM + "_" + pTableID);
    String sortDir = pWebContext.getParameter(TableConstants.SORT_DIR_PARAM + "_" + pTableID);

    if (start == null) {
        result.setStart(0);
        result.setPageSize(pPageSize);
    } else {
        result.setStart(Integer.parseInt(start));
        result.setPageSize(Integer.parseInt(pageSize));
    }

    result.setSortProperty(sortColumn);
    result.setSortDir(sortDir);
    result.setSortName(sortName);
    return result;

}

From source file:Main.java

/**
 * //w  w w  .  ja  v a 2s .  c o  m
 * @param pressingLength length of pause between clicks
 * @param mathExpectation mathExpectation values list 
 * @return dispersion values list
 */
public static List<Double> dispersion(Map<String, Long> pressingLength, List<Double> mathExpectation) {
    int N = pressingLength.size() - 1;
    //dispersion
    int i = 0;
    ArrayList<Double> dispersion = new ArrayList<Double>();
    for (String key : pressingLength.keySet()) {
        double x;
        double s = 0.0;
        for (String k : pressingLength.keySet()) {
            if (!k.equals(key)) {
                x = pressingLength.get(k) - mathExpectation.get(i);
                s += x * x;
            }
        }
        dispersion.add(sqrt(s / (N - 1)));
        i++;
    }
    return dispersion;
}

From source file:edu.txstate.dmlab.clusteringwiki.eval.ExecutionTimes.java

/**
 * Present times for all registered timers for an id
 * @return/*from w w w .j av  a 2 s . co  m*/
 */
public static String report(int id) {
    String s = "";
    Timer t;
    Map<String, Timer> tms = timers.get(id);
    for (String k : tms.keySet()) {
        t = tms.get(k);
        s += k + ": " + t + " \n";
    }
    return s;
}

From source file:Main.java

public static String getElementStartTagWithAttributes(String elementName, Map<String, String> attributes) {

    if (notEmptyStr(elementName) && attributes != null) {
        StringBuffer buffer = new StringBuffer();
        buffer.append(TAG_START).append(elementName);

        for (String key : attributes.keySet()) {
            String value = attributes.get(key);

            if (value == null) {
                value = "";
            }//from  w w  w. j av  a 2  s. co m
            buffer.append(" ").append(key).append("=").append("\"").append(value).append("\"");
        }
        return buffer.append(TAG_END).toString();
    }
    return null;
}

From source file:com.microsoft.azure.shortcuts.resources.samples.StorageAccountsSample.java

public static void test(Subscription subscription) throws Exception {
    String newStorageAccountName = "store" + String.valueOf(System.currentTimeMillis());
    String newGroupName = "testgroup";

    // Provision a new storage account with minimum parameters
    StorageAccount storageAccount = subscription.storageAccounts().define(newStorageAccountName)
            .withRegion(Region.US_WEST).withNewResourceGroup().create();

    printStorageAccount(storageAccount);

    String groupName = storageAccount.resourceGroup();

    // Listing all storage accounts
    Map<String, StorageAccount> storageAccounts = subscription.storageAccounts().asMap();
    System.out.println(/* w w w. j  a v a2 s  . c  o  m*/
            String.format("Storage accounts ids: \n\t%s", StringUtils.join(storageAccounts.keySet(), ",\n\t")));

    // Listing storage accounts in a specific resource group
    storageAccounts = subscription.storageAccounts().asMap(groupName);
    System.out.println(String.format("Storage account ids in group '%s': \n\t%s", groupName,
            StringUtils.join(storageAccounts.keySet(), ",\n\t")));

    // Get info about a specific storage account using its group and name
    storageAccount = subscription.storageAccounts(groupName, newStorageAccountName);
    printStorageAccount(storageAccount);

    // Delete this storage account
    storageAccount.delete();

    // Delete the group
    subscription.resourceGroups().delete(groupName);

    // Provision a test group
    ResourceGroup resourceGroup = subscription.resourceGroups().define(newGroupName).withRegion(Region.US_WEST)
            .create();

    // Provision a new storage account in an existing resource group
    storageAccount = subscription.storageAccounts().define(newStorageAccountName).withRegion(Region.US_WEST)
            .withExistingResourceGroup(newGroupName).withAccountType(AccountType.StandardLRS).create();

    printStorageAccount(storageAccount);

    // Delete the storage account
    storageAccount.delete();

    // Delete the groups
    resourceGroup.delete();
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step5GoldLabelEstimator.java

/**
 * Gets turker's relative rank (1 = the best one, ...) given his/her ID.
 *
 * @param turkerID            id/*  w  ww . j a  va  2s . c  o m*/
 * @param sortedCompetenceMap map (turkerID, competence) sorted by values descending!!
 * @return rank
 */
public static int getTurkerRank(String turkerID, Map<String, Double> sortedCompetenceMap) {
    int i = 0;
    for (String s : sortedCompetenceMap.keySet()) {
        if (turkerID.equals(s)) {
            return i;
        }

        i++;
    }

    throw new IllegalStateException("Turker " + turkerID + " not present in " + sortedCompetenceMap);
}

From source file:hudson.scm.util.ParamUtils.java

/**
 * Populates text with parameter values.
 *
 * @param text input text to process/* w  w  w .  ja  v  a  2  s .co  m*/
 * @param parameters map with parameters.
 * @return populated text.
 */
public static String populateParamValues(String text, Map<String, String> parameters) {
    if (MapUtils.isEmpty(parameters) || StringUtils.isEmpty(text)) {
        return text;
    }
    List<String> searchList = new ArrayList<String>(parameters.keySet().size());
    List<String> replacementList = new ArrayList<String>(parameters.keySet().size());
    for (String key : parameters.keySet()) {
        searchList.add(String.format(PARAM_FORMAT, key));
        replacementList.add(parameters.get(key));
    }
    return org.apache.commons.lang.StringUtils.replaceEach(text,
            searchList.toArray(new String[searchList.size()]),
            replacementList.toArray(new String[replacementList.size()]));
}

From source file:com.cprassoc.solr.auth.util.Utils.java

public static String mapKeysAndValuesToString(Map map) {
    Iterator<String> iter = map.keySet().iterator();
    String result = "";
    int row = 0;/* w  ww.  ja  v  a2 s. c o  m*/
    String key, value;
    while (iter.hasNext()) {
        key = iter.next();
        value = (String) map.get(key);
        if (row > 0) {
            result += ",";
        }
        result += key + ":" + value;
        row++;
    }
    return result;
}