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:com.microsoft.azure.shortcuts.resources.samples.VirtualMachinesSample.java

public static void test(Subscription subscription) throws Exception {
    // Creating a Windows VM
    String deploymentId = String.valueOf(System.currentTimeMillis());
    String groupName = "group" + deploymentId;

    VirtualMachine vmWin = subscription.virtualMachines().define("vm" + deploymentId).withRegion(Region.US_WEST)
            .withNewResourceGroup(groupName).withNewNetwork("net" + deploymentId, "10.0.0.0/28")
            .withPrivateIpAddressDynamic().withNewPublicIpAddress().withAdminUsername("shortcuts")
            .withAdminPassword("Abcd.1234")
            .withLatestImage("MicrosoftWindowsServer", "WindowsServer", "2008-R2-SP1")
            .withSize(Size.Type.BASIC_A1).withNewStorageAccount().withNewDataDisk(100)
            //.withExistingAvailabilitySet(new URI("/subscriptions/9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef/resourceGroups/marcinsrg123/providers/Microsoft.Compute/availabilitySets/marcinsas123"))
            //.withExistingDataDisk("https://vm1455045717874store.blob.core.windows.net/vm1455045717874/disk0.vhd")
            .create();/*from w w  w .j a  v a2s.c om*/

    printVM(vmWin);

    // Listing all virtual machine ids in a subscription
    Map<String, VirtualMachine> vms = subscription.virtualMachines().asMap();
    System.out.println(String.format("Virtual machines: \n\t%s", StringUtils.join(vms.keySet(), "\n\t")));

    // Adding a Linux VM to the same group and VNet
    VirtualMachine vmLinux = subscription.virtualMachines().define("lx" + deploymentId)
            .withRegion(Region.US_WEST).withExistingResourceGroup(groupName)
            .withExistingNetwork(subscription.networks(groupName, "net" + deploymentId)).withSubnet("subnet1")
            .withPrivateIpAddressDynamic().withNewPublicIpAddress().withAdminUsername("shortcuts")
            .withAdminPassword("Abcd.1234").withLatestImage("Canonical", "UbuntuServer", "14.04.3-LTS")
            .withSize(Size.Type.BASIC_A1).create();

    // Listing vms in a specific group
    Map<String, VirtualMachine> vmsInGroup = subscription.virtualMachines().asMap(groupName);
    System.out
            .println(String.format("Virtual machines: \n\t%s", StringUtils.join(vmsInGroup.keySet(), "\n\t")));

    // Listing virtual machines as objects
    String vmID = null;
    for (VirtualMachine vm : vms.values()) {
        if (vmID == null) {
            vmID = vm.id();
        }
        printVM(vm);
    }

    // Getting a specific virtual machine using its id
    VirtualMachine vm = subscription.virtualMachines(vmID);
    printVM(vm);

    // Getting a specific virtual machine using its group and name
    vm = subscription.virtualMachines(vm.resourceGroup(), vm.name());
    printVM(vm);

    // Restart the VM
    vmWin.restart();

    // Deallocate the VM
    vmWin.deallocate();

    // Delete VM
    vmWin.delete();

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

From source file:bencoding.securely.Converters.java

@SuppressWarnings("rawtypes")
public static Object toJSON(Object object) throws JSONException {
    if (object instanceof HashMap) {
        JSONObject json = new JSONObject();
        HashMap hashmap = (HashMap) object;
        for (Object key : hashmap.keySet()) {
            json.put(key.toString(), toJSON(hashmap.get(key)));
        }//from   w  ww .j  av  a2 s. co m
        return json;
    } else if (object instanceof Map) {
        JSONObject json = new JSONObject();
        Map map = (Map) object;
        for (Object key : map.keySet()) {
            json.put(key.toString(), toJSON(map.get(key)));
        }
        return json;
    } else if (object instanceof Iterable) {
        JSONArray json = new JSONArray();
        for (Object value : ((Iterable) object)) {
            json.put(toJSON(value));
        }
        return json;
    } else {
        return object;
    }
}

From source file:Main.java

public static String openPostConnection(String urlString, Map<String, String> map) {
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(urlString);
    List<NameValuePair> nameValuePairs = new ArrayList<>();
    for (String key : map.keySet()) {
        nameValuePairs.add(new BasicNameValuePair(key, map.get(key)));
    }//  w ww .j  a  va 2s  .c o  m
    try {
        post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    try {
        HttpResponse httpResponse = client.execute(post);
        BufferedReader br = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
        StringBuilder json = new StringBuilder("");
        String line = null;
        while ((line = br.readLine()) != null) {
            json.append(line);
        }
        return json.toString();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.microfocus.application.automation.tools.octane.executor.ExecutorConnectivityService.java

private static void checkPermissions(Jenkins jenkins, List<String> result,
        Map<Permission, String> permissions) {
    for (Permission permission : permissions.keySet()) {
        if (!jenkins.hasPermission(permission)) {
            result.add(permissions.get(permission));
        }/*from w  ww.j av a 2  s.  co  m*/
    }
}

From source file:com.xerox.amazonws.ec2.EC2Utils.java

/**
 * This method encodes key/value pairs into a user-data string
 *
 *//* w  w  w  .  j a v a  2 s .  c o m*/
public static String encodeUserParams(Map<String, String> params) {
    StringBuilder ret = new StringBuilder();
    for (String key : params.keySet()) {
        ret.append(key);
        ret.append("=");
        ret.append(params.get(key));
        ret.append(";");
    }
    return ret.toString();
}

From source file:com.phoenixnap.oss.ramlapisync.naming.RamlHelper.java

/**
 * Tree merging algorithm, if a resource already exists it will not overwrite and add all children to the existing resource 
 * @param existing The existing resource in the model
 * @param resource The resource to merge in
 * @param addActions If true it will copy all actions even if the resource itself isnt copied
 *//*  ww w. j a  v  a2  s  .co m*/
public static void mergeResources(RamlResource existing, RamlResource resource, boolean addActions) {
    Map<String, RamlResource> existingChildResources = existing.getResources();
    Map<String, RamlResource> newChildResources = resource.getResources();
    for (String newChildKey : newChildResources.keySet()) {
        if (!existingChildResources.containsKey(newChildKey)) {
            existing.addResource(newChildKey, newChildResources.get(newChildKey));
        } else {
            mergeResources(existingChildResources.get(newChildKey), newChildResources.get(newChildKey),
                    addActions);
        }
    }

    if (addActions) {
        existing.addActions(resource.getActions());
    }
}

From source file:edu.cmu.cs.lti.ark.fn.identification.latentmodel.LatentAlphabetCreationThreaded.java

/**
 * Combines the multiple alphabet files created by createLocalAlphabets into one
 * alphabet file//from  ww w  .  j  a va2s. co m
 */
public static void combineAlphabets(File alphabetDir) throws IOException {
    final String[] files = alphabetDir.list(LOCAL_ALPHABET_FILENAME_FILTER);
    final Set<String> alphabet = Sets.newHashSet();
    for (String file : files) {
        final String path = alphabetDir.getAbsolutePath() + "/" + file;
        if (logger.isLoggable(Level.INFO))
            logger.info("reading path: " + path);
        final Map<String, Integer> localAlphabet = readAlphabetFile(path);
        alphabet.addAll(localAlphabet.keySet());
    }
    writeAlphabetFile(alphabet, alphabetDir.getAbsolutePath() + "/" + ALPHABET_FILENAME);
}

From source file:fedora.utilities.Log4J.java

/**
 * Initializes Log4J from a properties file.
 * //from  w w w.  jav a  2  s .co m
 * @param propFile the Log4J properties file.
 * @param options a set of name-value pairs to use while expanding any
 *                replacement variables (e.g. ${some.name}) in the 
 *                properties file.  These may also be specified in
 *                the properties file itself.  If found, the value
 *                in the properties file will take precendence.
 * @throws IOException if configuration fails due to problems with the file.
 */
public static void initFromPropFile(File propFile, Map<String, String> options) throws IOException {
    Properties props = new Properties();
    props.load(new FileInputStream(propFile));
    if (options != null) {
        for (String name : options.keySet()) {
            String value = options.get(name);
            if (!props.containsKey(name)) {
                props.setProperty(name, value);
            }
        }
    }
    PropertyConfigurator.configure(props);
}

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

/**
 * Renders a 3 columns wide table with the given headers and rows. If headers are provided it should match with the
 * number of columns.//w  w w .j a  v a  2s .  c  o m
 *
 * @param rows    rows of the table, value map will be added as the last 2 columns to the table
 * @param headers headers of the table
 * @return formatted table
 */
public static String renderMapValueMap(Map<String, Map<String, String>> rows, String... headers) {
    Table table = createTable(headers);
    if (rows != null) {
        for (String key1 : rows.keySet()) {
            Map<String, String> values = rows.get(key1);
            if (values != null) {
                for (String key2 : values.keySet()) {
                    table.addRow(key1, key2, values.get(key2));
                }
            }
        }
    }
    return format(table);
}

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

public static ArrayList<String> mapValuesToList(Map map) {
    Iterator<String> iter = map.keySet().iterator();
    ArrayList<String> result = new ArrayList<>();

    int row = 0;/*  w  w  w . j av  a2  s  . com*/
    String key;
    Object value;
    while (iter.hasNext()) {
        key = iter.next();
        value = map.get(key);

        if (value instanceof String || value instanceof ArrayList) {
            result.add(value.toString());
        } else if (value instanceof Map) {
            result.add(mapValuesToString((Map) value));
        }
        // result += value;
        row++;
    }
    return result;
}