Example usage for java.util HashMap put

List of usage examples for java.util HashMap put

Introduction

In this page you can find the example usage for java.util HashMap put.

Prototype

public V put(K key, V value) 

Source Link

Document

Associates the specified value with the specified key in this map.

Usage

From source file:de.kasoki.jfeedly.model.FeedlyConnection.java

private static HashMap<String, String> createConnectionHashMap(String accessToken, String refreshToken,
        String plan, String tokenType, String id, String expireDate, String path) {

    HashMap<String, String> map = new HashMap<String, String>();

    map.put("access_token", accessToken);
    map.put("refresh_token", refreshToken);
    map.put("plan", plan);
    map.put("token_type", tokenType);
    map.put("id", id);
    map.put("expire_date", expireDate);
    map.put("connection_path", path);

    return map;/*from  w w w  .  ja va  2 s .co m*/
}

From source file:cd.go.contrib.elasticagents.docker.DockerContainer.java

private static HashMap<String, String> labelsFrom(CreateAgentRequest request) {
    HashMap<String, String> labels = new HashMap<>();

    labels.put(CREATED_BY_LABEL_KEY, Constants.PLUGIN_ID);
    if (StringUtils.isNotBlank(request.environment())) {
        labels.put(ENVIRONMENT_LABEL_KEY, request.environment());
    }//from  w ww.  j av  a2 s. c  om
    labels.put(CONFIGURATION_LABEL_KEY, GSON.toJson(request.properties()));
    return labels;
}

From source file:Main.java

public static void set(String key, Object obj) {
    HashMap map = (HashMap) s_var.get();
    if (map == null)
        throw new IllegalStateException("Thread local not exists!");
    if (obj == null)
        map.remove(key);//w  w  w. jav a2s  .co m
    else
        map.put(key, obj);
}

From source file:Main.java

private static HashMap<String, String> getValoresNodo(Node nodo) {
    HashMap<String, String> valores = new HashMap<String, String>();
    NodeList listaNodo = nodo.getChildNodes();
    for (int i = 0; i < listaNodo.getLength(); i++) {
        Node n = listaNodo.item(i);
        valores.put(n.getNodeName(), getValorNodo(n));
    }/*  w ww  .  j  a va2s. c  om*/
    return valores;
}

From source file:Main.java

@SuppressWarnings("rawtypes")
public static Map<String, String> swapStrKeysAndStrValues(Map<String, ?> hm) {
    HashMap<String, String> nhm = new HashMap<String, String>();
    Set<?> s = hm.entrySet();
    Iterator<?> it = s.iterator();
    while (it.hasNext()) {
        Map.Entry m = (Map.Entry) it.next();
        nhm.put((String) m.getValue(), (String) m.getKey());
    }//from w w w  .j a v a2 s.c o m
    return nhm;
}

From source file:Main.java

public static List<Map<String, String>> ReadFolderItemsFromFile(String path, String filename, String folderID) {

    List<Map<String, String>> results = new ArrayList<Map<String, String>>();

    try {/*from  w w  w  .  j av a 2s . com*/
        File fXmlFile = new File(path, filename);
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(fXmlFile);
        doc.getDocumentElement().normalize();

        NodeList nList = null;

        if (folderID == null) {
            // get all the children of the root
            nList = doc.getChildNodes().item(0).getChildNodes();
        } else {
            //Log.d("ReadItemsFromFile", "Current FolderID: " + folderID);

            NodeList folderList = doc.getElementsByTagName("folder");

            for (int i = 0; i < folderList.getLength(); i++) {

                Node curNode = folderList.item(i);
                if (curNode.getNodeType() == Node.ELEMENT_NODE) {
                    String curNodeId = ((Element) curNode).getElementsByTagName("id").item(0).getTextContent();
                    //Log.d("ReadItemsFromFile", "Number of items: " + curNodeId);

                    if (curNodeId.equals(folderID)) {
                        //Log.d("ReadItemsFromFile", "Found the folder");
                        NodeList folderChildren = curNode.getChildNodes();
                        for (int j = 0; j < folderChildren.getLength(); j++) {
                            //Log.d("ReadItemsFromFile", "node name: " + folderChildren.item(j).getNodeName());

                            if (folderChildren.item(j).getNodeName().equals("contents")) {
                                //Log.d("ReadItemsFromFile", "found the contents child");
                                nList = folderChildren.item(j).getChildNodes();
                                break;
                            }
                        }
                        break;
                    }
                }
            }
        }

        if (nList != null) {
            Log.d("ReadItemsFromFile", "-----------------------");
            Log.d("ReadItemsFromFile", "Number of items: " + nList.getLength());

            for (int temp = 0; temp < nList.getLength(); temp++) {

                Node nNode = nList.item(temp);
                //Log.d("ReadItemsFromFile", temp + ". node type: " + nNode.getNodeType());
                if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                    Element eElement = (Element) nNode;

                    Node elementNameNode = eElement.getElementsByTagName("name").item(0);
                    String elementNameString = elementNameNode.getTextContent();
                    //Log.d("ReadItemsFromFile", "Name: " + elementNameString);
                    HashMap<String, String> mapElement = new HashMap<String, String>();
                    mapElement.put("name", elementNameString);
                    mapElement.put("id", eElement.getElementsByTagName("id").item(0).getTextContent());
                    mapElement.put("type", nNode.getNodeName());
                    results.add(mapElement);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return results;

}

From source file:Main.java

/**
 * A static HashMap creator from a formatted string, 
 * the HashMap is specially used for the index mapper,
 * with the string(data of the node), and the integer
 * (index key of the node). /*from  www.  j  a v a2s. c o  m*/
 * @param str {k1=v1, k2=v2, ...}
 * @return
 */
public static HashMap<Integer, String> StringToHashMap(String str) {
    HashMap<Integer, String> keyMap = new HashMap<Integer, String>();
    String[] entry = removeBracketPair(str).split(", ");
    for (String value : entry) {
        String[] kv = value.split("=");
        keyMap.put(Integer.parseInt(kv[0]), kv[1]);
    }
    return keyMap;
}

From source file:eu.digitisation.idiomaident.utils.CorpusFilter.java

private static HashMap<String, File> getFolderList(File parent) {
    File[] folders = parent.listFiles(new FilenameFilter() {
        @Override//from w  w w .  ja v  a  2s . c  om
        public boolean accept(File file, String name) {
            return file.isDirectory();
        }
    });

    HashMap<String, File> map = new HashMap<>();

    for (File folder : folders) {
        map.put(folder.getName(), folder);
    }

    return map;
}

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

public static HashMap<String, Object> buildJson2(HashMap<String, Object> child, String[] path, boolean isFile,
        boolean isFirst) {
    if (path.length > 0) {
        String current = path[path.length - 1];
        HashMap<String, Object> res = new HashMap<>();
        res.put("name", current);
        if (Pattern.matches(extensionRegex, current)) {
            return buildJson2(res, Arrays.copyOf(path, path.length - 1), true, false);
        } else {//ww  w  . j av a 2  s  . c  om
            List childs = new ArrayList<>();
            if (!child.isEmpty()) {
                childs.add(child);
            }
            if (isFile) {
                res.put("files", childs);
            } else {
                res.put("dirs", childs);
            }
            return buildJson2(res, Arrays.copyOf(path, path.length - 1), false, false);
        }
    } else {
        return child;
    }
}

From source file:Main.java

@SuppressWarnings("rawtypes")
public static Map<Integer, String> swapStrKeysAndIntValues(Map<String, Integer> hm) {
    HashMap<Integer, String> nhm = new HashMap<Integer, String>();
    Set<?> s = hm.entrySet();
    Iterator<?> it = s.iterator();
    while (it.hasNext()) {
        Map.Entry m = (Map.Entry) it.next();
        nhm.put((Integer) m.getValue(), (String) m.getKey());
    }// ww  w . j a  v  a 2  s  . com
    return nhm;
}