List of usage examples for java.util Collections checkedMap
public static <K, V> Map<K, V> checkedMap(Map<K, V> m, Class<K> keyType, Class<V> valueType)
From source file:Main.java
public static void main(String args[]) { HashMap<String, String> hmap = new HashMap<String, String>(); hmap.put("1", "A"); hmap.put("2", "B"); hmap.put("3", "C"); hmap.put("4", "from java2s.com"); // get typesafe view of the map Map<String, String> tsmap = Collections.checkedMap(hmap, String.class, String.class); System.out.println(tsmap);/* w w w . ja v a2 s. c o m*/ }
From source file:io.sidecar.client.SidecarUserClient.java
@SuppressWarnings("unchecked") public Map<String, String> getUserMetadata() { try {/*w w w . j a va 2 s . c om*/ URL endpoint = clientConfig.fullUrlForPath("/rest/v1/provision/user"); SidecarGetRequest sidecarGetRequest = new SidecarGetRequest.Builder(accessKey.getKeyId(), "", accessKey.getSecret()).withSignatureVersion(ONE).withUrl(endpoint).build(); SidecarResponse response = sidecarGetRequest.send(); if (response.getStatusCode() == 200) { return Collections.checkedMap(mapper.readValue(response.getBody(), Map.class), String.class, String.class); } else { throw new SidecarClientException(response.getStatusCode(), response.getBody()); } } catch (Exception e) { throw propagate(e); } }
From source file:io.sidecar.client.SidecarUserClient.java
@SuppressWarnings("unchecked") public Map<String, String> getUserDeviceMetadata(String deviceId) { try {//from ww w. j av a 2s . c o m URL endpoint = clientConfig.fullUrlForPath("/rest/v1/provision/user/device/" + encode(deviceId)); SidecarGetRequest sidecarGetRequest = new SidecarGetRequest.Builder(accessKey.getKeyId(), "", accessKey.getSecret()).withSignatureVersion(ONE).withUrl(endpoint).build(); SidecarResponse response = sidecarGetRequest.send(); if (response.getStatusCode() == 200) { return Collections.checkedMap(mapper.readValue(response.getBody(), Map.class), String.class, String.class); } else { throw new SidecarClientException(response.getStatusCode(), response.getBody()); } } catch (Exception e) { throw propagate(e); } }
From source file:org.itracker.web.actions.admin.language.EditLanguageFormAction.java
@SuppressWarnings("unchecked") void putPropertiesKeys(Map<String, String> locItems, String locale) { try {/*from w w w. j a v a2 s .com*/ Hashtable<Object, Object> p; try { String path = File.separatorChar + ITrackerResources.RESOURCE_BUNDLE_NAME.replace('.', File.separatorChar) + (null != locale && !(ITrackerResources.BASE_LOCALE.equals(locale)) ? "_" + locale : "") + ".properties"; if (log.isDebugEnabled()) { log.debug("putPropertiesKeys: loading: " + path); } p = new PropertiesFileHandler(path).getProperties(); p = new Hashtable<>(p); if (log.isDebugEnabled()) { log.debug("putPropertiesKeys: loaded properties: " + p); } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("putPropertiesKeys", e); } p = new Properties(); } // overload properties by loc items from db if (log.isDebugEnabled()) { log.debug("putPropertiesKeys: overloading locItems: " + locItems); } p.putAll(locItems); locItems.putAll(Collections.checkedMap((Map) p, String.class, String.class)); } catch (RuntimeException e) { log.error("addPropertiesKeys: caught ", e); } }
From source file:uk.ac.imperial.clahrc.common.BugzillaProxy.java
@SuppressWarnings("unchecked") private Map<String, Number> logIn(XmlRpcClient XMLRPCClient) { Map<String, Number> loginResult = null; try {/*from w w w . j av a 2 s . co m*/ Map<String, Object> LoginMap = Collections.checkedMap(new HashMap<String, Object>(), String.class, Object.class); LoginMap.put("login", bugzillaConfigs.getProperty("login")); LoginMap.put("password", bugzillaConfigs.getProperty("pass")); loginResult = ((Map<String, Number>) XMLRPCClient.execute("User.login", new Object[] { LoginMap })); log.info("bugzillaProxy.submitBug() action logged to Bugzilla with id: " + loginResult.get("id")); } catch (Throwable twbl) { log.error("Throwable thrown while logging to Bugzilla - Problem Report Will Not Be Sent!", twbl); } return loginResult; }
From source file:uk.ac.imperial.clahrc.common.BugzillaProxy.java
@SuppressWarnings("unchecked") private Map<String, Number> submitBug(XmlRpcClient XMLRPCClient) { Map<String, Number> submitBugResult = null; Map<String, String> BugMap = Collections.checkedMap(new HashMap<String, String>(), String.class, String.class); try {/* ww w . j a v a 2 s .com*/ BugMap.put("product", "CLAHRC Web Tool"); BugMap.put("component", (distribution.getProperty("site") + ": " + this.toolComponent)); BugMap.put("version", "2.0.0"); BugMap.put("severity", "normal"); BugMap.put("platform", "All"); BugMap.put("op_sys", "All"); BugMap.put("priority", "Normal"); BugMap.put("status", "NEW"); BugMap.put("summary", this.summary); BugMap.put("description", this.appendReporter(this.description)); submitBugResult = ((Map<String, Number>) XMLRPCClient.execute("Bug.create", new Object[] { BugMap })); log.info("bugzillaProxy.submitBug() action submitted a bug with id: " + submitBugResult.get("id")); } catch (Throwable twbl) { log.error("Throwable thrown while submitting a bug - Problem Report Not Sent!", twbl); log.error("Attempted to report: " + Arrays.toString(BugMap.values().toArray())); } return submitBugResult; }
From source file:uk.ac.imperial.clahrc.common.BugzillaProxy.java
@SuppressWarnings("unchecked") private Map<String, Object> submitAttachment(XmlRpcClient XMLRPCClient, int BugId) { Map<String, Object> submitAttachmentResult = null; Map<String, Object> AttachmentMap = Collections.checkedMap(new HashMap<String, Object>(), String.class, Object.class); try {/*from w ww. j a v a2 s. c o m*/ AttachmentMap.put("ids", new String[] { String.valueOf(BugId) }); AttachmentMap.put("data", DatatypeConverter .parseBase64Binary(Base64.encodeBytes(this.imageAttachment, 0, this.imageAttachment.length))); AttachmentMap.put("file_name", "fileAttachmentForBug_" + BugId); AttachmentMap.put("summary", "fileAttachment for - " + this.summary); AttachmentMap.put("content_type", this.imageAttachmentContentType); submitAttachmentResult = ((Map<String, Object>) XMLRPCClient.execute("Bug.add_attachment", new Object[] { AttachmentMap })); log.info("bugzillaProxy.submitBug() action submitted a bugAttachment with id: " + ((Map<String, Object>) ((Map<String, Object>) submitAttachmentResult).get("attachments")) .keySet().toArray()[0]); } catch (Throwable twbl) { log.error("Throwable thrown while submitting a bug attachment - Problem Report Was Sent!", twbl); log.error("Attempted to report: " + Arrays.toString(AttachmentMap.values().toArray())); } return submitAttachmentResult; }