List of usage examples for java.util Map keySet
Set<K> keySet();
From source file:com.gson.oauth.Pay.java
/** * ??/* w w w . jav a2 s . c om*/ * @param params * @param encode * @return * @throws UnsupportedEncodingException */ public static String createSign(Map<String, String> params, boolean encode) throws UnsupportedEncodingException { Set<String> keysSet = params.keySet(); Object[] keys = keysSet.toArray(); Arrays.sort(keys); StringBuffer temp = new StringBuffer(); boolean first = true; for (Object key : keys) { if (first) { first = false; } else { temp.append("&"); } temp.append(key).append("="); Object value = params.get(key); String valueString = ""; if (null != value) { valueString = value.toString(); } if (encode) { temp.append(URLEncoder.encode(valueString, "UTF-8")); } else { temp.append(valueString); } } return temp.toString(); }
From source file:Main.java
/** * Copies the given {@link Map} into a new {@link Map}.<br> * /*from www. jav a 2s . co m*/ * @param <A> * the type of the keys of the map * @param <B> * the type of the values of the map * @param data * the given map * @return If the given map was empty, a {@link Collections#emptyMap()} is * returned<br> * If the given map contained only one entry, a * {@link Collections#singletonMap(Object, Object)}, containing * said entry, is returned <br> * If the given map contained more than one element, a * {@link Collections#unmodifiableMap(Map)}, containing the entries * of the given map, is returned. */ public static <A, B> Map<A, B> copy(Map<A, B> data) { final int size = data.size(); switch (size) { case 0: return Collections.emptyMap(); case 1: final A key = data.keySet().iterator().next(); return Collections.singletonMap(key, data.get(key)); default: return Collections.unmodifiableMap(new HashMap<A, B>(data)); } }
From source file:br.ajmarques.cordova.plugin.localnotification.LocalNotification.java
/** * Cancel all notifications that were created by this plugin. * * Android can only unregister a specific alarm. There is no such thing * as cancelAll. Therefore we rely on the Shared Preferences which holds * all our alarms to loop through these alarms and unregister them one * by one./* w ww . j ava2 s . c om*/ */ public static void cancelAll() { SharedPreferences settings = getSharedPreferences(); NotificationManager nc = getNotificationManager(); Map<String, ?> alarms = settings.getAll(); Set<String> alarmIds = alarms.keySet(); for (String alarmId : alarmIds) { cancel(alarmId); } nc.cancelAll(); }
From source file:org.apache.wink.test.mock.MockRequestConstructor.java
/** * Construct a mock request to be used in tests. * //from ww w .j av a 2 s. co m * @param method HTTP method * @param requestURI request URI * @param acceptHeader request Accept header * @param parameters request query parameters * @param attributes request attributes * @return new mock request */ public static MockHttpServletRequest constructMockRequest(String method, String requestURI, String acceptHeader, Map<?, ?> parameters, Map<String, Object> attributes) { MockHttpServletRequest mockRequest = constructMockRequest(method, requestURI, acceptHeader); if (attributes != null) { Set<String> attributeNames = attributes.keySet(); Object attributeValue; for (String attributeName : attributeNames) { attributeValue = attributes.get(attributeName); mockRequest.setAttribute(attributeName, attributeValue); } } mockRequest.setParameters(parameters); return mockRequest; }
From source file:com.android.volley.toolbox.HttpClientStack.java
@SuppressWarnings("unused") private static List<NameValuePair> getPostParameterPairs(Map<String, String> postParams) { List<NameValuePair> result = new ArrayList<NameValuePair>(postParams.size()); for (String key : postParams.keySet()) { result.add(new BasicNameValuePair(key, postParams.get(key))); }/* w w w . j av a 2s . c o m*/ return result; }
From source file:com.sirma.itt.cmf.integration.workflow.WorkflowUtil.java
/** * Prepares the given node for persistence in the workflow engine. * * @param node//from w w w . j a va 2 s . c o m * The node to package up for persistence * @return The map of data representing the node */ @SuppressWarnings("unchecked") public static Map<QName, Serializable> prepareTaskParams(Node node) { Map<QName, Serializable> params = new HashMap<QName, Serializable>(); // marshal the properties and associations captured by the property // sheet // back into a Map to pass to the workflow service // go through all the properties in the transient node and add them to // params map Map<String, Object> props = node.getProperties(); for (String propName : props.keySet()) { QName propQName = resolveToQName(propName); params.put(propQName, (Serializable) props.get(propName)); } // go through any associations that have been added to the start task // and build a list of NodeRefs representing the targets Map<String, Map<String, AssociationRef>> assocs = node.getAddedAssociations(); for (String assocName : assocs.keySet()) { QName assocQName = resolveToQName(assocName); // get the associations added and create list of targets Map<String, AssociationRef> addedAssocs = assocs.get(assocName); List<AssociationRef> originalAssocRefs = (List<AssociationRef>) node.getAssociations().get(assocName); List<NodeRef> targets = new ArrayList<NodeRef>(addedAssocs.size()); if (originalAssocRefs != null) { for (AssociationRef assoc : originalAssocRefs) { targets.add(assoc.getTargetRef()); } } for (AssociationRef assoc : addedAssocs.values()) { targets.add(assoc.getTargetRef()); } params.put(assocQName, (Serializable) targets); } // go through the removed associations and either setup or adjust the // parameters map accordingly assocs = node.getRemovedAssociations(); for (String assocName : assocs.keySet()) { QName assocQName = resolveToQName(assocName); // get the associations removed and create list of targets Map<String, AssociationRef> removedAssocs = assocs.get(assocName); List<NodeRef> targets = (List<NodeRef>) params.get(assocQName); if (targets == null) { // if there weren't any assocs of this type added get the // current // set of assocs from the node List<AssociationRef> originalAssocRefs = (List<AssociationRef>) node.getAssociations() .get(assocName); targets = new ArrayList<NodeRef>(originalAssocRefs.size()); for (AssociationRef assoc : originalAssocRefs) { targets.add(assoc.getTargetRef()); } } // remove the assocs the user deleted for (AssociationRef assoc : removedAssocs.values()) { targets.remove(assoc.getTargetRef()); } params.put(assocQName, (Serializable) targets); } // TODO: Deal with child associations if and when we need to support // them for workflow tasks, for now warn that they are being used Map<?, ?> childAssocs = node.getAddedChildAssociations(); if (childAssocs.size() > 0) { if (logger.isWarnEnabled()) logger.warn("Child associations are present but are not supported for workflow tasks, ignoring..."); } return params; }
From source file:com.elogiclab.vosao.plugin.FlickrUtils.java
public static String buildQueryString(Map<String, String> params, String apiSecret) { StringBuilder result = new StringBuilder(); StringBuffer unencoded = new StringBuffer(apiSecret); List keyList = new ArrayList(params.keySet()); Collections.sort(keyList);// w w w . ja v a2 s . c om Iterator it = keyList.iterator(); while (it.hasNext()) { if (result.length() > 0) { result.append("&"); } String key = it.next().toString(); result.append(key); result.append("="); result.append(params.get(key)); unencoded.append(key); unencoded.append(params.get(key)); } System.out.println(unencoded); String sig = digest(unencoded.toString()); result.append("&api_sig="); result.append(sig); return result.toString(); }
From source file:com.liveramp.cascading_ext.counters.Counters.java
private static String prettyTaps(Map<String, Tap> taps) { if (taps.keySet().isEmpty()) { return "[]"; }//from ww w . jav a 2 s . c o m Collection<Tap> values = taps.values(); Tap first = values.toArray(new Tap[values.size()])[0]; if (first == null) { return "[null tap]"; } if (taps.keySet().size() == 1) { return "[\"" + first.getIdentifier() + "\"]"; } else { return "[\"" + first.getIdentifier() + "\",...]"; } }
From source file:com.cloud.test.utils.UtilsForTest.java
public static boolean verifyTagValues(Map<String, String> params, Map<String, String> pattern) { boolean result = true; if (pattern != null) { for (String value : pattern.keySet()) { if (!pattern.get(value).equals(params.get(value))) { result = false;/*from w w w . j a va 2s . c om*/ System.out.println("Tag " + value + " has " + params.get(value) + " while expected value is: " + pattern.get(value)); } } } return result; }
From source file:gov.nih.nci.cabig.caaers.rules.common.CaaersRuleUtil.java
public static Map<String, Object> multiplexAndEvaluate(Object src, String path) { Map<String, Object> map = new HashMap<String, Object>(); String[] pathParts = path.split("\\[\\]\\."); if (pathParts.length < 2) return map; BeanWrapper bw = new BeanWrapperImpl(src); Object coll = bw.getPropertyValue(pathParts[0]); if (coll instanceof Collection) { int i = 0; for (Object o : (Collection) coll) { if (pathParts.length == 2) { String s = pathParts[0] + "[" + i + "]." + pathParts[1]; map.put(s, o);//from w ww .j a va 2 s . c o m } else { String s = pathParts[0] + "[" + i + "]"; String[] _newPathParts = new String[pathParts.length - 1]; System.arraycopy(pathParts, 1, _newPathParts, 0, _newPathParts.length); String _p = StringUtils.join(_newPathParts, "[]."); Map<String, Object> m = multiplexAndEvaluate(o, _p); //map.put(s, o); for (String k : m.keySet()) { map.put(s + "." + k, m.get(k)); } } i++; } } return map; }