List of usage examples for java.util HashMap put
public V put(K key, V value)
From source file:Main.java
public static HashMap<Integer, String> newDictLZW(String inMsg) { HashMap<Integer, String> dict = new HashMap<Integer, String>(); int j = 0;//from w w w .j a v a 2 s . c om for (int i = 0; i < inMsg.length(); i++) { if (dict.containsValue(Character.toString(inMsg.charAt(i))) == false && inMsg.charAt(i) != '\n') { dict.put((Integer) j, Character.toString(inMsg.charAt(i))); j++; } } return dict; }
From source file:com.google.appengine.tools.pipeline.impl.util.JsonUtils.java
/** * Convert an <code>org.json.JSONObject</code> into a <code>Map</code> and an * <code>org.json.JSONArray</code> into a <code>List</code> *//*from ww w . jav a 2s . c o m*/ private static Object convert(Object x) throws JSONException { if (x instanceof JSONObject) { JSONObject jsonObject = (JSONObject) x; String[] names = JSONObject.getNames(jsonObject); if (names == null || names.length == 0) { return new HashMap<>(0); } HashMap<String, Object> map = new HashMap<>(names.length); for (String name : names) { Object value = jsonObject.get(name); map.put(name, convert(value)); } return map; } else if (x instanceof JSONArray) { JSONArray jsonArray = (JSONArray) x; int length = jsonArray.length(); List<Object> list = new ArrayList<>(length); for (int i = 0; i < length; i++) { list.add(convert(jsonArray.get(i))); } return list; } else { return x; } }
From source file:com.imaginary.home.cloud.api.call.CommandCall.java
static public Map<String, Object> toJSON(PendingCommand cmd) throws PersistenceException { HashMap<String, Object> json = new HashMap<String, Object>(); Long t;//from www .j ava 2 s.co m json.put("commandId", cmd.getPendingCommandId()); json.put("timeout", cmd.getTimeout()); json.put("groupId", cmd.getGroupId()); json.put("command", cmd.getCommand()); json.put("state", cmd.getState().name()); json.put("issuedTimestamp", cmd.getIssuedTimestamp()); json.put("issuedBy", cmd.getIssuedBy()); Boolean b = cmd.getResult(); if (b != null) { json.put("result", b); } String error = cmd.getErrorMessage(); if (error != null) { json.put("errorMessage", error); } t = cmd.getSentTimestamp(); if (t != null) { json.put("sentTimestamp", t); } t = cmd.getCompletionTimestamp(); if (t != null) { json.put("completionTimestamp", t); } ArrayList<Map<String, Object>> devices = new ArrayList<Map<String, Object>>(); for (String id : cmd.getDeviceIds()) { Device device = Device.getDevice(id); if (device != null) { HashMap<String, Object> d = new HashMap<String, Object>(); d.put("deviceId", device.getVendorDeviceId()); d.put("systemId", device.getHomeAutomationSystemId()); devices.add(d); } } json.put("devices", devices); return json; }
From source file:com.clutch.ClutchAB.java
private static void downloadABMeta() { HashMap<String, String> params = new HashMap<String, String>(); params.put("guid", ClutchAPIClient.getFakeGUID()); ClutchAPIClient.callMethod("get_ab_metadata", params, new ClutchAPIResponseHandler() { @Override//from ww w . j a v a2s .c om public void onSuccess(JSONObject response) { JSONObject metadata = response.optJSONObject("metadata"); try { FileOutputStream fos = context.openFileOutput("__clutchab.json", Context.MODE_PRIVATE); fos.write(metadata.toString().getBytes()); fos.flush(); fos.close(); } catch (FileNotFoundException e) { Log.e(TAG, "Could not open the Clutch AB metadata file for output"); } catch (IOException e) { Log.e(TAG, "Could not write to the Clutch AB metadata file"); } } @Override public void onFailure(Throwable e, JSONObject errorResponse) { Log.e(TAG, "Failed to connect to the Clutch server to send AB logs: " + errorResponse); } }); }
From source file:edu.ucsb.nceas.ezid.test.EZIDServiceTest.java
/** * Generate DataCite compliant metadata for use in test data insertion. *//* w w w. j a va 2 s . com*/ public static HashMap<String, String> generateMetadata(String identifier) { HashMap<String, String> metadata = new HashMap<String, String>(); String title = "Test entry from ezid service for identifier: " + identifier; metadata.put("datacite.title", title); String creator = "Keyser Sze"; metadata.put("datacite.creator", creator); String publisher = "EZID Java Library"; metadata.put("datacite.publisher", publisher); String year = new Integer(Calendar.getInstance().get(Calendar.YEAR)).toString(); metadata.put("datacite.publicationyear", year); return metadata; }
From source file:lee.util.jtap.JTapCli.java
protected static HashMap<String, String> getMappedArgs(CommandLine cmd, String... argNames) { HashMap<String, String> argMap = new HashMap<String, String>(); String[] optArgs = cmd.getOptionValues("s"); for (int a = 0; a < optArgs.length; a++) { argMap.put(argNames[a], optArgs[a]); }/* w ww . j ava2s . c om*/ return argMap; }
From source file:Main.java
/** * Retrieves a Map of the value of child nodes in the form { [Node Name] => * [Node Value] }/*from w w w. ja va2 s . co m*/ * * @param node */ public static Map<String, String> getChildValueMap(Node node) { HashMap<String, String> map = new HashMap<String, String>(); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node n = children.item(i); String nodeName = n.getNodeName(); String nodeValue = getNodeValue(n); map.put(nodeName, nodeValue); } return map; }
From source file:Main.java
private static HashMap<String, String> parseContent(String src) { HashMap<String, String> map = new HashMap<String, String>(); String patternStr = "http://(.*)\\?chat_id=[-]?(\\d+)&chat_name=(.+)"; Pattern p = Pattern.compile(patternStr); Matcher m = p.matcher(src);//from w w w . ja v a 2 s . c om if (!m.find()) { return null; } else if (m.groupCount() == 3) { map.put("chat_id", m.group(2)); map.put("chat_name", m.group(3)); return map; } return null; }
From source file:com.gst.integrationtests.common.CenterHelper.java
public static int createCenter(final String name, final int officeId, final String externalId, final int staffId, final int[] groupMembers, final String activationDate, final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { final String CREATE_CENTER_URL = CENTERS_URL + "?" + Utils.TENANT_IDENTIFIER; HashMap hm = new HashMap(); hm.put("name", name); hm.put("officeId", officeId); hm.put("active", false); if (externalId != null) hm.put("externalId", externalId); if (staffId != -1) hm.put("staffId", staffId); if (groupMembers != null) hm.put("groupMembers", groupMembers); if (activationDate != null) { hm.put("active", true); hm.put("locale", "en"); hm.put("dateFormat", "dd MMM yyyy"); hm.put("activationDate", activationDate); }/*from w ww.j a va2 s . c o m*/ System.out.println("------------------------CREATING CENTER-------------------------"); return Utils.performServerPost(requestSpec, responseSpec, CREATE_CENTER_URL, new Gson().toJson(hm), "resourceId"); }
From source file:com.screenslicer.common.Crypto.java
private static Map<String, String> asMap(String... keysAndVals) { HashMap<String, String> map = new HashMap<String, String>(); int mid = keysAndVals.length / 2; for (int i = 0; i < mid; i++) { map.put(keysAndVals[i], keysAndVals[i + mid]); }//from w w w . j a v a 2s. com return map; }