Example usage for java.util Map get

List of usage examples for java.util Map get

Introduction

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

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:LogTest.java

public static void main(String[] args) throws IOException {
    String inputfile = args[0];//w  w  w  .  ja va2  s . com
    String outputfile = args[1];

    Map<String, Integer> map = new TreeMap<String, Integer>();

    Scanner scanner = new Scanner(new File(inputfile));
    while (scanner.hasNext()) {
        String word = scanner.next();
        Integer count = map.get(word);
        count = (count == null ? 1 : count + 1);
        map.put(word, count);
    }
    scanner.close();

    List<String> keys = new ArrayList<String>(map.keySet());
    Collections.sort(keys);

    PrintWriter out = new PrintWriter(new FileWriter(outputfile));
    for (String key : keys)
        out.println(key + " : " + map.get(key));
    out.close();
}

From source file:edu.sjsu.cmpe275.lab2.model.HibernateUtil.java

public static void main(final String[] args) throws Exception {
    Session session = getSessionFactory().openSession();

    try {/*from  w  w  w  . j a  va  2 s.  c o m*/
        System.out.println("querying all the managed entities...");
        final Map metadataMap = session.getSessionFactory().getAllClassMetadata();
        for (Object key : metadataMap.keySet()) {
            final ClassMetadata classMetadata = (ClassMetadata) metadataMap.get(key);
            final String entityName = classMetadata.getEntityName();
            final Query query = session.createQuery("from " + entityName);
            System.out.println("executing: " + query.getQueryString());
            for (Object o : query.list()) {
                System.out.println("  " + o);
            }
        }
    } finally {
        session.close();
    }
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document document = new Document(new Rectangle(100, 100));
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("sun_tutorial_with_text.pdf"));
    document.open();//  www . j  a v a  2s.  c  o  m
    PdfContentByte cb = writer.getDirectContent();
    PdfTemplate tp = cb.createTemplate(100, 100);
    DefaultFontMapper mapper = new DefaultFontMapper();
    mapper.insertDirectory("c:/windows/fonts");
    String name;
    Map map = mapper.getMapper();
    for (Iterator i = map.keySet().iterator(); i.hasNext();) {
        name = (String) i.next();
        System.out.println(name + ": " + ((DefaultFontMapper.BaseFontParameters) map.get(name)).fontName);
    }
    Graphics2D g2 = tp.createGraphics(100, 100, mapper);
    g2.setColor(Color.black);
    java.awt.Font thisFont = new java.awt.Font("Garamond", java.awt.Font.PLAIN, 18);
    g2.setFont(thisFont);
    String pear = "Pear";
    FontMetrics metrics = g2.getFontMetrics();
    int width = metrics.stringWidth(pear);
    g2.drawString(pear, (100 - width) / 2, 20);
    g2.dispose();
    cb.addTemplate(tp, 0, 0);
    document.close();
}

From source file:com.roncoo.pay.permission.utils.EncryptUtil.java

public static void main(String[] args) {
    String loginName = "513781560@qq.com";
    Long timeStamp = System.currentTimeMillis();
    String key = "rcPayLoginSign268";
    String sign = RonCooSignUtil.getSign(key, timeStamp, loginName);

    String url = "http://192.168.1.181:8080/roncoo-dev-admin/mydata/getByLoginName";
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("userName", loginName);
    params.put("timeStamp", timeStamp);
    params.put("sign", sign);
    String json = JSON.toJSONString(params);

    String httpResponse = RoncooHttpClientUtils.post(url, json);
    Map<String, Object> parseObject = JSONObject.parseObject(httpResponse, Map.class);
    String code = (String) parseObject.get("code");
    String desc = (String) parseObject.get("desc");
    System.out.println(code);//from   w w w .  j av  a 2 s .  c om
    JSONObject data = (JSONObject) parseObject.get("data");

    Map<String, Object> mapInfo = JSONObject.parseObject(data.toJSONString(), Map.class);
    String returnPWD = (String) mapInfo.get("pwd");
    String userId = (String) mapInfo.get("userId");
    System.out.println(httpResponse);
}

From source file:Main.java

public static void main(String[] args) {
    Map<Integer, String> map = new HashMap<>();

    for (int i = 0; i < 10; i++) {
        map.putIfAbsent(i, "val" + i);
    }/*from w  w  w . j  a v a2  s.  c  o  m*/

    map.forEach((id, val) -> System.out.println(val));

    map.remove(3, "val3");
    System.out.println(map.get(3)); // val33

    map.remove(3, "val33");
    System.out.println(map.get(3)); // null
}

From source file:MainClass.java

public static void main(String[] args) {
    Map charSets = Charset.availableCharsets();
    Iterator it = charSets.keySet().iterator();
    while (it.hasNext()) {
        String csName = (String) it.next();
        System.out.print(csName);
        Iterator aliases = ((Charset) charSets.get(csName)).aliases().iterator();
        if (aliases.hasNext())
            System.out.print(": ");
        while (aliases.hasNext()) {
            System.out.print(aliases.next());
            if (aliases.hasNext())
                System.out.print(", ");
        }/*from  w  w  w. j  a  v  a2 s.c  o  m*/
        System.out.println();
    }
}

From source file:com.github.fastjson.MapPractice.java

/**
 * @param args/* w w  w .ja  va 2 s.c  o  m*/
 */
public static void main(String[] args) {
    Map<String, String> map = new HashMap<>();
    map.put("name", "doctor");
    map.put("age", "1118");
    map.put("sex", "man");
    String jsonString = JSON.toJSONString(map);
    System.out.println(jsonString);

    InputStream resourceAsStream = MapPractice.class.getResourceAsStream("/fastjson/map1.json");
    String jString = null;
    try {
        jString = IOUtils.toString(resourceAsStream);

    } catch (IOException e) {
        e.printStackTrace();
    }

    Map<?, ?> parse = JSON.parseObject(jString, Map.class);
    System.out.println(parse);
    for (Object key : parse.keySet()) {
        System.out.println(key + ":" + parse.get(key));
    }

    InputStream resourceAsStream2 = MapPractice.class.getResourceAsStream("/fastjson/map2.json");
    String jString2 = null;
    try {
        jString2 = IOUtils.toString(resourceAsStream2);
    } catch (IOException e) {
        e.printStackTrace();
    }
    Map<?, ?> parseObject = JSON.parseObject(jString2, Map.class);
    System.out.println(JSON.toJSON(parseObject));

    System.out.println("??");

    Object object = parseObject.get("currentKey");
    System.out.println("currentKey" + ":" + object);
    Map<?, ?> object2 = (Map<?, ?>) parseObject.get("keyMap");
    for (Object key : object2.keySet()) {
        System.out.println(key + ":" + object2.get(key));
    }
}

From source file:com.ankang.report.util.GsonUtil.java

public static void main(String[] args) {
    //      Gson gson = new GsonBuilder().create();
    //      List<Map<String, String>> list=new ArrayList();
    //      Map<String, String> map=new HashMap();
    //      map.put("key", "xxxxxxx");
    //      map.put("value", "xxxxxxx");
    //      Map<String, String> map2=new HashMap();
    //      map2.put("key", "");
    //      map2.put("value", "zzz");
    //      list.add(map);
    //      list.add(map2);
    /* String content = "{\"total\":68,\"count\":68,\"data\":{\"openid\":[\"oFOtTuAEOyqvx1uPQIm4LrFqRdiU\",\"oFOtTuKuop2XtLZe-RMdirW6IWvM\",\"oFOtTuFa4Yzs6uhTX4OAZTcZXbao\",\"oFOtTuB8JRu638EQyruVS55rUD3s\",\"oFOtTuKZA_H1wDPwl_Gxh_0VPk5c\",\"oFOtTuAn5EW41AMZg5Wu05qu-IfI\",\"oFOtTuMBX7xosmbivFjq2-yUpazc\",\"oFOtTuOYPqLdbda89uwz3VPVEruw\",\"oFOtTuAvO4uBeKkQBgwGA57H_NM8\",\"oFOtTuJ8mgp1BUcSXcbND1AAsT9M\",\"oFOtTuCx6zBTgzSuJYf-7MUVXX_E\",\"oFOtTuJNx5lCzDAJiGa-02GZHpRs\",\"oFOtTuDCLucdAf01g-A5CNh_P5fw\",\"oFOtTuLIhivtQM7BGBPFtCtipDIw\",\"oFOtTuCFke2OsyOtJnnCLmB6M8k4\",\"oFOtTuMxVoMz971_U7xv5PKDJqAs\",\"oFOtTuMQG615biXYLfvNY4LXJvF4\",\"oFOtTuGiqsTTOoTKgQV7y658bMpE\",\"oFOtTuBTPMVq7ocOlZTWIAoqBCLY\",\"oFOtTuO59OezL98n4FMAmRQmn-Tc\",\"oFOtTuLxLKWMA6m6DobnEta2ZZe0\",\"oFOtTuIL3-y58JbsQNIYCce89rxI\",\"oFOtTuCfIcz9k-QTEsKSG215_vFA\",\"oFOtTuAqHse1BmHU9iqAdsaUqWkk\",\"oFOtTuIOhikiKzb1R_tguTaxua9A\",\"oFOtTuOKdpri8GzBcYXIsocqk1CQ\",\"oFOtTuGmZZPiOieW0ZZR81D8kjfU\",\"oFOtTuLaS3zZEJsWT_LWwpy0D05A\",\"oFOtTuF2x35yBjzE2FiN4WLVSEi8\",\"oFOtTuEtNJGuq2WHtsTtiPqiSjaE\",\"oFOtTuNZn9iXN_8m-fqEzI0CGa90\",\"oFOtTuFZUtGDSjN0A6hLeVuIhZYc\",\"oFOtT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VI2NnEcrrZl5_6CuiMA\",\"oFOtTuO0fDkxvJ_ma_fUd_dHViL8\",\"oFOtTuAxrKYfbGRLmcK4pqw4tmpU\"]},\"next_openid\":\"oFOtTuAxrKYfbGRLmcK4pqw4tmpU\"}";
            /*from w  w w .ja  v a2  s.c  om*/
     JSONObject dataJson = JSONObject.parseObject(content);
     JSONObject data = dataJson.getJSONObject("data");
     JSONArray openid = data.getJSONArray("openid");
     String info = openid.getString(0);
     String province = openid.getString(1);
     System.out.println(info + province);*/

    Studens s = new Studens();
    s.setAge(1);
    s.setSize(133);
    Map<String, Object> jsonToMapEx = GsonUtil.jsonToMapEx(toJson(s));

    System.out.println(jsonToMapEx.get("age"));
    System.out.println(jsonToMapEx.get("size"));
}

From source file:cn.dehui.zbj1984105.GetRelatedKeywords.java

public static void main(String[] args) {
    try {/*from w  w  w  .  j  a va  2  s. co m*/
        // Log SOAP XML request and response.
        AdWordsServiceLogger.log();

        // Get AdWordsUser from "~/adwords.properties".
        AdWordsUser user = new AdWordsUser("adwords.properties");

        // Get the TargetingIdeaService.
        TargetingIdeaServiceInterface targetingIdeaService = user
                .getService(AdWordsService.V201209.TARGETING_IDEA_SERVICE);

        // Create selector.
        TargetingIdeaSelector selector = new TargetingIdeaSelector();
        selector.setRequestType(RequestType.IDEAS);
        selector.setIdeaType(IdeaType.KEYWORD);
        selector.setRequestedAttributeTypes(new AttributeType[] { AttributeType.KEYWORD_TEXT,
                AttributeType.SEARCH_VOLUME, AttributeType.CATEGORY_PRODUCTS_AND_SERVICES });

        // Set selector paging (required for targeting idea service).
        Paging paging = new Paging();
        paging.setStartIndex(0);
        paging.setNumberResults(10);
        selector.setPaging(paging);

        // Create related to query search parameter.
        RelatedToQuerySearchParameter relatedToQuerySearchParameter = new RelatedToQuerySearchParameter();
        relatedToQuerySearchParameter.setQueries(new String[] { "mars cruise" });
        selector.setSearchParameters(new SearchParameter[] { relatedToQuerySearchParameter });

        // Get related keywords.
        TargetingIdeaPage page = targetingIdeaService.get(selector);

        // Display related keywords.
        if (page.getEntries() != null && page.getEntries().length > 0) {
            for (TargetingIdea targetingIdea : page.getEntries()) {
                Map<AttributeType, Attribute> data = MapUtils.toMap(targetingIdea.getData());
                StringAttribute keyword = (StringAttribute) data.get(AttributeType.KEYWORD_TEXT);
                IntegerSetAttribute categories = (IntegerSetAttribute) data
                        .get(AttributeType.CATEGORY_PRODUCTS_AND_SERVICES);
                String categoriesString = "(none)";
                if (categories != null && categories.getValue() != null) {
                    categoriesString = StringUtils.join(ArrayUtils.toObject(categories.getValue()), ", ");
                }
                Long averageMonthlySearches = ((LongAttribute) data.get(AttributeType.SEARCH_VOLUME))
                        .getValue();
                System.out.println(
                        "Keyword with text '" + keyword.getValue() + "' and average monthly search volume '"
                                + averageMonthlySearches + "' was found with categories: " + categoriesString);
            }
        } else {
            System.out.println("No related keywords were found.");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.google.com/index.html");
    URLConnection connection = url.openConnection();

    Map responseMap = connection.getHeaderFields();
    for (Iterator iterator = responseMap.keySet().iterator(); iterator.hasNext();) {
        String key = (String) iterator.next();
        System.out.println(key + " = ");

        List values = (List) responseMap.get(key);
        for (int i = 0; i < values.size(); i++) {
            Object o = values.get(i);
            System.out.println(o + ", ");
        }/*from  w  ww.  j a  v a 2 s  . c  o  m*/
    }
}