List of usage examples for java.util Map keySet
Set<K> keySet();
From source file:eu.trentorise.smartcampus.geocoder.manager.OSMGeocoder.java
private static String generateQueryString(Map<String, Object> parameters) { String queryString = "?"; if (parameters != null) { for (String param : parameters.keySet()) { Object value = parameters.get(param); if (value == null) { if (queryString.length() > 1) { queryString += "&"; }/*from ww w . j a v a 2 s. co m*/ queryString += param + "="; } else if (value instanceof List) { for (Object v : ((List<?>) value)) { if (queryString.length() > 1) { queryString += "&"; } queryString += param + "=" + encodeValue(v.toString()); } } else { if (queryString.length() > 1) { queryString += "&"; } queryString += param + "=" + encodeValue(value.toString()); } } } return queryString.length() > 1 ? queryString : ""; }
From source file:com.ecofactor.qa.automation.util.HttpUtil.java
/** * Gets the.//from w w w .j a v a 2 s. com * @param url the url * @return the http response */ public static String get(String url, Map<String, String> params, int expectedStatus) { String content = null; HttpClient httpClient = new DefaultHttpClient(); HttpGet request = new HttpGet(url); URIBuilder builder = new URIBuilder(request.getURI()); Set<String> keys = params.keySet(); for (String key : keys) { builder.addParameter(key, params.get(key)); } HttpResponse response = null; try { request.setURI(builder.build()); DriverConfig.setLogString("URL " + request.getURI().toString(), true); response = httpClient.execute(request); content = IOUtils.toString(response.getEntity().getContent()); DriverConfig.setLogString("Content " + content, true); Assert.assertEquals(response.getStatusLine().getStatusCode(), expectedStatus); } catch (Exception e) { LOGGER.error(e.getMessage()); } finally { request.releaseConnection(); } return content; }
From source file:net.eledge.android.europeana.search.model.record.abstracts.Resource.java
protected static Map<String, String[]> mergeMapArrays(Map<String, String[]> source1, Map<String, String[]> source2) { Map<String, String[]> merged = new HashMap<>(); if (source1 != null) { merged.putAll(source1);/*from w w w . j a v a2 s .c om*/ } else { return source2; } if (source2 != null) { for (String key : source2.keySet()) { if (merged.containsKey(key)) { merged.put(key, mergeArray(merged.get(key), source2.get(key))); } else { merged.put(key, source2.get(key)); } } } return merged; }
From source file:org.wso2.dss.integration.test.odata.ODataTestUtils.java
public static Object[] sendGET(String endpoint, Map<String, String> headers) throws IOException { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(endpoint); for (String headerType : headers.keySet()) { httpGet.setHeader(headerType, headers.get(headerType)); }//from ww w. ja va 2 s . c o m HttpResponse httpResponse = httpClient.execute(httpGet); if (httpResponse.getEntity() != null) { BufferedReader reader = new BufferedReader( new InputStreamReader(httpResponse.getEntity().getContent())); String inputLine; StringBuilder response = new StringBuilder(); while ((inputLine = reader.readLine()) != null) { response.append(inputLine); } reader.close(); return new Object[] { httpResponse.getStatusLine().getStatusCode(), response.toString() }; } else { return new Object[] { httpResponse.getStatusLine().getStatusCode() }; } }
From source file:org.wso2.dss.integration.test.odata.ODataTestUtils.java
public static int sendPATCH(String endpoint, String content, Map<String, String> headers) throws IOException { HttpClient httpClient = new DefaultHttpClient(); HttpPatch httpPatch = new HttpPatch(endpoint); for (String headerType : headers.keySet()) { httpPatch.setHeader(headerType, headers.get(headerType)); }// w ww . j a v a2 s . co m if (null != content) { HttpEntity httpEntity = new ByteArrayEntity(content.getBytes("UTF-8")); if (headers.get("Content-Type") == null) { httpPatch.setHeader("Content-Type", "application/json"); } httpPatch.setEntity(httpEntity); } HttpResponse httpResponse = httpClient.execute(httpPatch); return httpResponse.getStatusLine().getStatusCode(); }
From source file:com.ExtendedAlpha.SWI.SeparatorLib.BookSeparator.java
public static EnchantmentStorageMeta getEnchantedBookMeta(JSONObject json) { try {// w w w .j ava 2s . c om ItemStack dummyItems = new ItemStack(Material.ENCHANTED_BOOK, 1); EnchantmentStorageMeta meta = (EnchantmentStorageMeta) dummyItems.getItemMeta(); if (json.has("enchantments")) { Map<Enchantment, Integer> enchants = EnchantmentSeparator .getEnchantments(json.getString("enchantments")); for (Enchantment e : enchants.keySet()) { meta.addStoredEnchant(e, enchants.get(e), true); } } return meta; } catch (JSONException e) { e.printStackTrace(); return null; } }
From source file:de.quamoco.qm.util.qiesl.QIESLVerificator.java
/** Produces a variable map with dummy values */ private static Map<String, Object> obtainVariables(Map<String, Type> measures) throws QIESLException { Map<String, Object> result = new HashMap<String, Object>(); for (String name : measures.keySet()) { if (measures.get(name) == Type.NUMBER) { result.put(name, QPoints.valueOf(1)); } else if (measures.get(name) == Type.FINDINGS) { FindingCollection dummyFindingCollection = new FindingCollection(); dummyFindingCollection//from ww w .ja va 2 s . c o m .add(new FindingReport().getOrCreateCategory("").createFindingGroup("").createFinding("")); result.put(name, dummyFindingCollection); } else { throw new QIESLException("unknown measure type: " + measures.get(name)); } } return result; }
From source file:Main.java
/** * Move a single entry (indicated by its key) up or down by one step inside an insert sorted map (e.g. a {@link LinkedHashMap}). * // w ww . j a v a 2 s . c om * @param <K> * type of the map's keys * @param <V> * type of the map's values * @param insertSortedMap * map containing the entry to be moved; should be a map implementation preserving the insert order (e.g. a {@link LinkedHashMap}) * @param entryKey * key of the entry to be moved up/down by one step * @param increaseIndexByOne * if the entry's index should be increased by one (i.e. moved down); otherwise decrease the entry's index by one (i.e. moved up) * @throws IllegalArgumentException * <ul> * <li>if the given map does not contain the specified key,</li> * <li>if the specified entry is the first in the map and cannot be moved further up, or</li> * <li>if the specified entry is the last in the map and cannot be moved further down</li> * </ul> */ public static <K, V> void moveEntryInInsertSortedMap(final Map<K, V> insertSortedMap, final K entryKey, final boolean increaseIndexByOne) { // #1 create a copy of the original key order as list (to make it accessible via index) final List<K> keyList = new ArrayList<K>(insertSortedMap.keySet()); // #2 determine the designated entry's current position final int index = keyList.indexOf(entryKey); // #3 determine the entry's new position final int indexToSwitchWith; if (increaseIndexByOne) { indexToSwitchWith = index + 1; } else { indexToSwitchWith = index - 1; } final int totalEntryCount = keyList.size(); if (index == -1 || indexToSwitchWith == -1 || indexToSwitchWith == totalEntryCount) { // the entry cannot be moved as indicated throw new IllegalArgumentException(); } // #4 create a copy of the unchanged relation template groups map final Map<K, V> groupsCopy = new LinkedHashMap<K, V>(insertSortedMap); // #5 remove all mapping from the original relation template groups map, starting at the affected groups' indices insertSortedMap.keySet().retainAll(keyList.subList(0, Math.min(index, indexToSwitchWith))); final K entryToSwitchWith = keyList.get(indexToSwitchWith); // #6 re-insert the two affected groups in their new (inverse) order if (increaseIndexByOne) { insertSortedMap.put(entryToSwitchWith, groupsCopy.get(entryToSwitchWith)); insertSortedMap.put(entryKey, groupsCopy.get(entryKey)); } else { insertSortedMap.put(entryKey, groupsCopy.get(entryKey)); insertSortedMap.put(entryToSwitchWith, groupsCopy.get(entryToSwitchWith)); } // #7 re-insert all groups that are following the affected two relation tempate groups final int firstTrailingRetainedIndex = Math.max(index, indexToSwitchWith) + 1; if (firstTrailingRetainedIndex < totalEntryCount) { // there is at least one more value behind the affected two entries that needs to be re-inserted groupsCopy.keySet().retainAll(keyList.subList(firstTrailingRetainedIndex, totalEntryCount)); insertSortedMap.putAll(groupsCopy); } }
From source file:Main.java
/** * This utilty takes an xpath that uses namespace prefixes (such as * /a:B/a:C) and converts it to one without prefixes, by using the * appropriate operators instead (such as * /*[namespace-uri()='http://DOMAIN.COM/SCHEMA' and * local-name()='B']/*[namespace-uri()='http://DOMAIN.COM/SCHEMA' and * local-name()='C']). THe only conceivable use for this funciton is to * write sane xpath and convert it to the insane xpath globus index service * supports.//from w w w .j a v a 2 s . c o m * * NOTE: This isn't perfect. The known limitations are: 1) its * overly agressive, and will replace QName-looking string literals, 2) it * won't work if you have namespaces attributes 3) it will silently not * replace any QNames that you haven't supplied a prefix mapping for * * @param prefixedXpath * An xpath [optionally] using namespace prefixes in nodetests * @param namespaces * A Map<String,String> keyed on namespace prefixes to resolve * in the xpath, where the value is the actual namespace that * should be used. * @return a converted, conformant, xpath */ public static String translateXPath(String prefixedXpath, Map namespaces) { // don't process an empty Xpath, or one with not ns prefixes if (prefixedXpath == null || prefixedXpath.trim().length() == 0 || prefixedXpath.indexOf(":") < 0) { return prefixedXpath; } else if (namespaces == null || namespaces.keySet().size() == 0) { throw new IllegalArgumentException( "You specified an XPath with prefixes, yet didn't define any prefix mappings."); } // process all the replacements based on prefixes Iterator iterator = namespaces.keySet().iterator(); while (iterator.hasNext()) { String prefix = (String) iterator.next(); String ns = (String) namespaces.get(prefix); // replace the last thing in the xpath being a qname prefixedXpath = prefixedXpath.replaceAll(prefix + NS_START_REGEX + "[\\s]*$", URI_REPLACEMENT + ns + LOCAL_REPLACEMENT + "]"); // replace any qname that is starting a predicate prefixedXpath = prefixedXpath.replaceAll(prefix + NS_START_REGEX + "\\[", URI_REPLACEMENT + ns + LOCAL_REPLACEMENT + " and "); // replace any other qname (has some character after the qname that // isn't the start of a predicate) prefixedXpath = prefixedXpath.replaceAll(prefix + NS_START_REGEX + "([^\\[]){1,1}", URI_REPLACEMENT + ns + LOCAL_REPLACEMENT + "]$2"); } return prefixedXpath; }