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.alibaba.otter.manager.web.home.module.screen.CheckDelayStat.java

public static void main(String[] args) {
    Map<Long, Long> alertMap = parseAlert("20-1000000, 30-20000");

    for (Long pipelineId : alertMap.keySet()) {
        System.out.println(pipelineId + " : " + alertMap.get(pipelineId));
    }//from  www. java  2 s.c  o m
}

From source file:Main.java

public static void main(final String[] args) {
    Map<String, String> items;

    items = new HashMap<String, String>();
    items.put("A", "1");
    items.put("B", "2");
    items.put("C", "3");

    display(new RandomIterator<String>(items.keySet().iterator()));
    display(new RandomIterator<String>(items.keySet().iterator()));
}

From source file:Main.java

public static void main(String[] args) {
    Map<Integer, Integer> data = new HashMap<Integer, Integer>();
    data.put(10, 2);//  w w  w.  ja  v a2  s.co m
    data.put(20, 3);
    data.put(30, 5);
    data.put(40, 15);
    data.put(50, 4);

    SortedSet<Integer> keys = new TreeSet<Integer>(data.keySet());
    String s = "";
    for (Integer key : keys) {
        s += key + " : ";
        for (int i = 0; i < data.get(key); i++) {
            s += "*";
        }
        s += "\n";
    }
    System.out.println(s);
}

From source file:com.act.biointerpretation.metadata.Genus.java

public static void main(String[] args) throws Exception {
    Map<String, Genus> nameToGenus = Genus.parseGenuses();
    for (String name : nameToGenus.keySet()) {
        Genus genus = nameToGenus.get(name);
        if (genus == null) {
            System.err.println("Null genus");
            continue;
        }/* www . java 2 s  .  c  o m*/

        if (genus.Kingdom == null) {
            System.err.println("Null Kingdom " + name);
        }

        if (genus.Domain == null) {
            System.err.println("Null Domain " + name);
        }

        if (genus.Phylum == null) {
            System.err.println("Null Phylum " + name);
        }
    }
    System.out.println("done");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object keyObject = "";
    Object valueObject = "";
    Map<Object, Object> weakMap = new WeakHashMap<Object, Object>();

    weakMap.put(keyObject, valueObject);
    WeakReference weakValue = new WeakReference<Object>(valueObject);

    weakMap.put(keyObject, weakValue);/*from   w ww  .j  av  a 2  s. co  m*/

    Iterator it = weakMap.keySet().iterator();
    while (it.hasNext()) {
        Object key = it.next();
        weakValue = (WeakReference) weakMap.get(key);
        if (weakValue == null) {
            System.out.println("Value has been garbage-collected");
        } else {
            System.out.println("Get value");
            valueObject = weakValue.get();
        }
    }
}

From source file:edu.usu.sdl.wso2client.SampleWSRegistryClient.java

public static void main(String[] args) throws Exception {
    Registry registry = initialize();
    try {// ww w .  ja va2  s  .c  om
        //load component

        List<ComponentAll> components;
        try (InputStream in = new FileInputStream("C:\\temp\\components.json")) {
            components = StringProcessor.defaultObjectMapper().readValue(in,
                    new TypeReference<List<ComponentAll>>() {
                    });
        } catch (IOException ex) {
            throw ex;
        }

        ComponentAll componentAll = components.get(0);

        Resource resource = registry.newResource();
        resource.setContent(componentAll.getComponent().getDescription());

        resource.setDescription("Storefront Component");
        resource.setMediaType("application/openstorefront");
        resource.setUUID(componentAll.getComponent().getComponentId());

        try {
            Map fieldMap = BeanUtils.describe(componentAll.getComponent());
            fieldMap.keySet().stream().forEach((key) -> {
                if ("description".equals(key) == false) {
                    resource.setProperty(Component.class.getSimpleName() + "_" + key, "" + fieldMap.get(key));
                    //System.out.println("key  = " + Component.class.getSimpleName() + "_" + key);
                    //System.out.println("Value  = " + fieldMap.get(key));
                }
            });
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
            Logger.getLogger(StringProcessor.class.getName()).log(Level.SEVERE, null, ex);
        }

        String resourcePath = "/storefront/components/" + componentAll.getComponent().getComponentId();
        registry.put(resourcePath, resource);

        //
        System.out.println("A resource added to: " + resourcePath);
        //         registry.rateResource(resourcePath, 4);
        //
        //         System.out.println("Resource rated with 4 stars!");
        //         Comment comment = new Comment();
        //         comment.setText("Testing Connection");
        //         registry.addComment(resourcePath, comment);
        //         System.out.println("Comment added to resource");
        //
        //         Resource getResource = registry.get("/abc2");
        //         System.out.println("Resource retrived");
        //         System.out.println("Printing retrieved resource content: "
        //               + new String((byte[]) getResource.getContent()));

        //         Resource resource = registry.newResource();
        //         resource.setContent("Hello Out there!");
        //
        //         String resourcePath = "/abc3";
        //         registry.put(resourcePath, resource);
        //
        //         System.out.println("A resource added to: " + resourcePath);
        //
        //         registry.rateResource(resourcePath, 4);
        //
        //         System.out.println("Resource rated with 4 stars!");
        //         Comment comment = new Comment();
        //         comment.setText("Testing Connection");
        //         registry.addComment(resourcePath, comment);
        //         System.out.println("Comment added to resource");
        //
        //         Resource getResource = registry.get("/abc3");
        //         System.out.println("Resource retrived");
        //         System.out.println("Printing retrieved resource content: "
        //               + new String((byte[]) getResource.getContent()));
    } finally {
        //Close the session
        ((WSRegistryServiceClient) registry).logut();
    }
    System.exit(0);
}

From source file:CollectionAll.java

public static void main(String[] args) {
    List list1 = new LinkedList();
    list1.add("list");
    list1.add("dup");
    list1.add("x");
    list1.add("dup");
    traverse(list1);//from www. ja  va  2  s . c  o m
    List list2 = new ArrayList();
    list2.add("list");
    list2.add("dup");
    list2.add("x");
    list2.add("dup");
    traverse(list2);
    Set set1 = new HashSet();
    set1.add("set");
    set1.add("dup");
    set1.add("x");
    set1.add("dup");
    traverse(set1);
    SortedSet set2 = new TreeSet();
    set2.add("set");
    set2.add("dup");
    set2.add("x");
    set2.add("dup");
    traverse(set2);
    LinkedHashSet set3 = new LinkedHashSet();
    set3.add("set");
    set3.add("dup");
    set3.add("x");
    set3.add("dup");
    traverse(set3);
    Map m1 = new HashMap();
    m1.put("map", "Java2s");
    m1.put("dup", "Kava2s");
    m1.put("x", "Mava2s");
    m1.put("dup", "Lava2s");
    traverse(m1.keySet());
    traverse(m1.values());
    SortedMap m2 = new TreeMap();
    m2.put("map", "Java2s");
    m2.put("dup", "Kava2s");
    m2.put("x", "Mava2s");
    m2.put("dup", "Lava2s");
    traverse(m2.keySet());
    traverse(m2.values());
    LinkedHashMap /* from String to String */ m3 = new LinkedHashMap();
    m3.put("map", "Java2s");
    m3.put("dup", "Kava2s");
    m3.put("x", "Mava2s");
    m3.put("dup", "Lava2s");
    traverse(m3.keySet());
    traverse(m3.values());
}

From source file:Main.java

public static void main(String[] args) {
    Map errors = new HashMap();

    errors.put("404", "A.");
    errors.put("403", "B.");
    errors.put("500", "C.");

    String errorDesc = (String) errors.get("404");
    System.out.println("Error 404: " + errorDesc);

    Iterator iterator = errors.keySet().iterator();
    while (iterator.hasNext()) {
        String key = (String) iterator.next();
        System.out.println("Error " + key + " means " + errors.get(key));
    }//from   w ww  . j a va2 s.c om
}

From source file:com.ebay.spine.Launcher.java

public static void main(String[] args) throws Exception {

    // not using the default parsing for the hub. Creating a simple one from the default.
    GridHubConfiguration config = new GridHubConfiguration();

    // adding the VNC capable servlet.
    List<String> servlets = new ArrayList<String>();
    servlets.add("web.ConsoleVNC");
    config.setServlets(servlets);/*ww w.  j a  v  a  2  s .  c  o m*/

    // capabilities are dynamic for VMs.
    config.setThrowOnCapabilityNotPresent(false);

    // forcing the host from command line param as the hub gets confused by all the VMWare network interfaces.
    for (int i = 0; i < args.length; i++) {
        if (args[i].startsWith("hubhost=")) {
            config.setHost(args[i].replace("hubhost=", ""));
        }
    }

    Hub h = new Hub(config);
    h.start();

    // and the nodes.

    // load the node templates.
    Map<String, JSONObject> templatesByNameMap = getTemplates("eugrid.json");

    // get the template to use for each VM
    Map<String, String> vmsMapping = getVMtoTemplateMapping("nodes.properties");

    // register each node using its template.
    for (String id : vmsMapping.keySet()) {
        String templateName = vmsMapping.get(id);
        JSONObject request = templatesByNameMap.get(templateName);
        request.getJSONObject("configuration").put("vm", id);

        BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST",
                "http://" + hub + "/grid/register/");
        r.setEntity(new StringEntity(request.toString()));
        DefaultHttpClient client = new DefaultHttpClient();
        URL hubURL = new URL("http://" + hub);
        HttpHost host = new HttpHost(hubURL.getHost(), hubURL.getPort());
        HttpResponse response = client.execute(host, r);
    }

}

From source file:br.edimarmanica.weir2.rule.Loader.java

public static void main(String[] args) {
    Site site = br.edimarmanica.dataset.weir.book.Site.BOOKMOOCH;
    Map<String, String> entityValues = loadEntityValues(
            new File(Paths.PATH_INTRASITE + "/" + site.getPath() + "/extracted_values/rule_379.csv"),
            loadEntityID(site));//from   w  w w  .jav a 2s. co  m
    for (String entity : entityValues.keySet()) {
        System.out.println(entity + "->" + entityValues.get(entity));
    }
}