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 encodeUrl(Map<String, String> param) {
    if (param == null) {
        return "";
    }/* w  w w  .j ava 2  s . c o m*/
    StringBuilder sb = new StringBuilder();
    Set<String> keys = param.keySet();
    boolean first = true;

    for (String key : keys) {
        String value = param.get(key);
        //pain...EditMyProfileDao params' values can be empty
        if (value != null || key.equals("description") || key.equals("url")) {
            if (first) {
                first = false;
            } else {
                sb.append("&");
            }
            try {
                sb.append(URLEncoder.encode(key, "UTF-8")).append("=")
                        .append(URLEncoder.encode(param.get(key), "UTF-8"));
            } catch (UnsupportedEncodingException e) {

            }
        }

    }

    return sb.toString();
}

From source file:Main.java

public static <K, V> void printMap(Map<K, V> A, File file)
        throws FileNotFoundException, UnsupportedEncodingException {
    file.getParentFile().mkdirs();//  w w w.ja  va  2s .  c o  m
    PrintWriter p = new PrintWriter(file, "UTF-8");
    for (K k : A.keySet())
        p.println(k + "\t" + A.get(k));
    p.close();
}

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

public static void test(Azure azure) throws Exception {
    final String accountName = "store" + String.valueOf(System.currentTimeMillis());
    System.out.println(String.format("Creating account named '%s'...", accountName));

    // Create a new storage account
    azure.storageAccounts().define(accountName).withRegion("West US").create();

    // List storage accounts
    Map<String, StorageAccount> storageAccounts = azure.storageAccounts().asMap();
    System.out.println("Available storage accounts:\n\t" + StringUtils.join(storageAccounts.keySet(), ",\n\t"));

    // Get storage account information
    StorageAccount storageAccount = azure.storageAccounts(accountName);
    System.out.println(String.format(
            "Found storage account: %s\n" + "\tAffinity group: %s\n" + "\tLabel: %s\n" + "\tDescription: %s\n"
                    + "\tGeo primary region: %s\n" + "\tGeo primary region status: %s\n"
                    + "\tGeo secondary region: %s\n" + "\tGeo secondary region status: %s\n"
                    + "\tLast geo failover time: %s\n" + "\tRegion: %s\n" + "\tStatus: %s\n"
                    + "\tEndpoints: %s\n" + "\tType: %s\n",

            storageAccount.id(), storageAccount.affinityGroup(), storageAccount.label(),
            storageAccount.description(), storageAccount.geoPrimaryRegion(),
            storageAccount.geoPrimaryRegionStatus(), storageAccount.geoSecondaryRegion(),
            storageAccount.geoSecondaryRegionStatus(),
            (storageAccount.lastGeoFailoverTime() != null) ? storageAccount.lastGeoFailoverTime().getTime()
                    : null,//from  w w  w.  ja va2s  .c  om
            storageAccount.region(), storageAccount.status(),
            StringUtils.join(storageAccount.endpoints(), ", "), storageAccount.type()));

    // Update storage info
    System.out.println(String.format("Updating storage account named '%s'...", accountName));

    azure.storageAccounts().update(accountName).withDescription("Updated").withLabel("Updated").apply();

    storageAccount = azure.storageAccounts(accountName);
    System.out.println(String.format("Updated storage account: %s\n" + "\tLabel: %s\n" + "\tDescription: %s\n",
            storageAccount.id(), storageAccount.label(), storageAccount.description()));

    // Delete the newly created storage account
    System.out.println(String.format("Deleting storage account named '%s'...", accountName));
    azure.storageAccounts().delete(accountName);
}

From source file:Main.java

public static String takeFromIntMap(final Map<String, Integer> pMap, final String dataSeparator) {
    String gotKey = "";
    Iterator<String> innerIter;
    final StringBuffer tempBuf = new StringBuffer();
    innerIter = pMap.keySet().iterator();
    while (innerIter.hasNext()) {
        gotKey = innerIter.next();//w  w  w. j a  va2  s . c  om
        tempBuf.append(gotKey + dataSeparator + pMap.get(gotKey).toString() + LINE_SEPARATOR);
    }
    return tempBuf.toString();
}

From source file:Main.java

private final static String sortedParams(Map<String, String> params) throws UnsupportedEncodingException {
    String vals[] = new String[params.size()];
    int idx = 0;/*  w  w w.  j av a 2s . c  o m*/
    for (String key : params.keySet()) {
        vals[idx++] = key;
    }
    Arrays.sort(vals);
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < vals.length; i++) {
        if (i > 0) {
            sb.append("&");
        }
        sb.append(vals[i]);
        sb.append("=");
        sb.append(encode(params.get(vals[i])));
    }
    return sb.toString();
}

From source file:Main.java

public static List<String> checkMapDiff(Map<String, List<String>> m1, Map<String, List<String>> m2) {
    List<String> diff = new ArrayList<>();
    //m2-m1//from w w  w  . j  av  a2s. c  om
    for (String k : m1.keySet()) {
        if (m2.containsKey(k)) {
            diff.addAll(getDiff(m1.get(k), m2.get(k)));
        } else {//m1 have, but m2 don't
            diff.addAll(m1.get(k));
        }
    }

    //m1-m2
    for (String k : m2.keySet()) {
        if (!m1.containsKey(k)) {//m2 have, but m1 don't
            diff.addAll(m2.get(k));
        }
    }

    return diff;
}

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

public static void test(Subscription subscription) throws Exception {
    LoadBalancer lb;/*from   w  ww  .  ja v a2 s.c  om*/
    String groupName = "lbtestgroup";
    String lbName = "marcinslb";

    // Create a new LB in a new resource group
    lb = subscription.loadBalancers().define(lbName).withRegion(Region.US_WEST).withNewResourceGroup(groupName)
            .withNewPublicIpAddress("marcinstest2").create();

    // Get info about a specific lb using its group and name
    lb = subscription.loadBalancers(lb.id());
    printLB(lb);

    // Listing all lbs
    Map<String, LoadBalancer> lbs = subscription.loadBalancers().asMap();
    System.out.println(String.format("Load Balancer ids: \n\t%s", StringUtils.join(lbs.keySet(), ",\n\t")));

    // Listing lbs in a specific resource group
    lbs = subscription.loadBalancers().asMap(groupName);
    System.out.println(String.format("Load balancer ids in group '%s': \n\t%s", groupName,
            StringUtils.join(lbs.keySet(), ",\n\t")));

    // Get info about a specific lb using its resource ID
    lb = subscription.loadBalancers(lb.resourceGroup(), lb.name());
    printLB(lb);

    // Delete the load balancer
    lb.delete();

    // Create a new lb in an existing resource group
    lb = subscription.loadBalancers().define(lbName + "2").withRegion(Region.US_WEST)
            .withExistingResourceGroup(groupName).withNewPublicIpAddress("marcinstest3").create();

    printLB(lb);

    // Delete the lb
    lb.delete();

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

From source file:gov.nist.healthcare.ttt.webapp.api.GetCCDAFolderTest.java

private static Map deepMerge(Map original, Map newMap) {
    for (Object key : newMap.keySet()) {
        if (newMap.get(key) instanceof Map && original.get(key) instanceof Map) {
            Map originalChild = (Map) original.get(key);
            Map newChild = (Map) newMap.get(key);
            original.put(key, deepMerge(originalChild, newChild));
        } else if (newMap.get(key) instanceof List && original.get(key) instanceof List) {
            List originalChild = (List) original.get(key);
            List newChild = (List) newMap.get(key);
            for (Object each : newChild) {
                if (originalChild.contains(each)) {
                    System.out.println("test");
                } else {
                    originalChild.add(each);
                }//w  w  w  .  j av  a2s .  c  om
            }
        } else {
            original.put(key, newMap.get(key));
        }
    }
    return original;
}

From source file:max.hubbard.bettershops.Utils.ItemUtils.java

public static ItemStack fromString(String s) {

    Map<String, Object> map = stringToMap(s);

    for (String s1 : map.keySet()) {
        if (s1.contains("damage")) {
            map.put(s1, Integer.valueOf((String) map.get(s1)));
            break;
        }//from w w  w  . j a  v a  2 s .co m
    }

    return ItemStack.deserialize(map);
}

From source file:com.bazaarvoice.jolt.SortrTest.java

private static String verifyMapOrder(Map<String, Object> actual, Map<String, Object> expected) {

    Iterator<String> actualIter = actual.keySet().iterator();
    Iterator<String> expectedIter = expected.keySet().iterator();

    for (int index = 0; index < actual.size(); index++) {
        String actualKey = actualIter.next();
        String expectedKey = expectedIter.next();

        if (!StringUtils.equals(actualKey, expectedKey)) {
            return "Found out of order keys '" + actualKey + "' and '" + expectedKey + "'";
        }/*from w w  w  . ja  v a  2s.  c  om*/

        String result = verifyOrder(actual.get(actualKey), expected.get(expectedKey));
        if (result != null) {
            return result;
        }
    }

    return null; // success
}