List of usage examples for java.util Map isEmpty
boolean isEmpty();
From source file:io.cloudslang.content.amazon.utils.InputsUtil.java
public static String getHeadersOrParamsString(Map<String, String> headersOrParamsMap, String separator, String suffix, boolean deleteLastChar) { if (headersOrParamsMap.isEmpty()) { return EMPTY; }/* ww w . j a va2 s. c o m*/ StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> entry : headersOrParamsMap.entrySet()) { sb.append(entry.getKey()); sb.append(separator); sb.append(entry.getValue()); sb.append(suffix); } if (deleteLastChar) { return sb.deleteCharAt(sb.length() - ONE).toString(); } return sb.toString(); }
From source file:com.inmobi.grill.server.metastore.JAXBUtils.java
/** * Convert string map to XProperties/*from w w w. j a v a2 s . c om*/ */ public static XProperties xPropertiesFromMap(Map<String, String> map) { if (map != null && !map.isEmpty()) { XProperties xp = XCF.createXProperties(); List<XProperty> xpList = xp.getProperties(); for (Map.Entry<String, String> e : map.entrySet()) { XProperty property = XCF.createXProperty(); property.setName(e.getKey()); property.setValue(e.getValue()); xpList.add(property); } return xp; } return null; }
From source file:com.mywork.framework.util.RemoteHttpUtil.java
/** * ?getpost????// w ww . j av a2 s .c o m */ public static String fetchSimpleHttpResponse(String method, String contentUrl, Map<String, String> headerMap, Map<String, String> bodyMap) throws IOException { Executor executor = Executor.newInstance(httpClient); if (HttpGet.METHOD_NAME.equalsIgnoreCase(method)) { String result = contentUrl; StringBuilder sb = new StringBuilder(); sb.append(contentUrl); if (bodyMap != null && !bodyMap.isEmpty()) { if (contentUrl.indexOf("?") > 0) { sb.append("&"); } else { sb.append("?"); } result = Joiner.on("&").appendTo(sb, bodyMap.entrySet()).toString(); } return executor.execute(Request.Get(result)).returnContent().asString(); } if (HttpPost.METHOD_NAME.equalsIgnoreCase(method)) { Request request = Request.Post(contentUrl); if (headerMap != null && !headerMap.isEmpty()) { for (Map.Entry<String, String> m : headerMap.entrySet()) { request.addHeader(m.getKey(), m.getValue()); } } if (bodyMap != null && !bodyMap.isEmpty()) { Form form = Form.form(); for (Map.Entry<String, String> m : bodyMap.entrySet()) { form.add(m.getKey(), m.getValue()); } request.bodyForm(form.build()); } return executor.execute(request).returnContent().asString(); } return null; }
From source file:com.github.ipaas.ifw.front.FisResource.java
/** * ????URI,uri,map.json?/*from www.j a v a 2 s .c om*/ * * @param key * - ?key,static/css/blog.css * @return String * @throws FisException */ private static String getResourceUri(String name, Map<String, Map> nsResMap, Map<String, Object> res) throws FisException { String uri = ""; if (res == null || res.isEmpty()) { throw new FisException("undefined resource \"" + name); } if (res.containsKey("pkg")) { Map pkg = (Map) nsResMap.get("pkg").get(res.get("pkg")); uri = (String) pkg.get("uri"); } else { uri = (String) res.get("uri"); } return uri; }
From source file:com.glaf.core.util.http.HttpClientUtils.java
/** * ??GET// ww w.ja va2s .c o m * * @param url * ?? * @param encoding * * @param dataMap * ? * * @return */ public static String doGet(String url, String encoding, Map<String, String> dataMap) { StringBuffer buffer = new StringBuffer(); HttpGet httpGet = null; InputStreamReader is = null; BufferedReader reader = null; BasicCookieStore cookieStore = new BasicCookieStore(); HttpClientBuilder builder = HttpClientBuilder.create(); CloseableHttpClient client = builder.setDefaultCookieStore(cookieStore).build(); try { if (dataMap != null && !dataMap.isEmpty()) { StringBuffer sb = new StringBuffer(); for (Map.Entry<String, String> entry : dataMap.entrySet()) { String name = entry.getKey().toString(); String value = entry.getValue(); sb.append("&").append(name).append("=").append(value); } if (StringUtils.contains(url, "?")) { url = url + sb.toString(); } else { url = url + "?xxxx=1" + sb.toString(); } } httpGet = new HttpGet(url); HttpResponse response = client.execute(httpGet); HttpEntity entity = response.getEntity(); is = new InputStreamReader(entity.getContent(), encoding); reader = new BufferedReader(is); String tmp = reader.readLine(); while (tmp != null) { buffer.append(tmp); tmp = reader.readLine(); } } catch (IOException ex) { ex.printStackTrace(); throw new RuntimeException(ex); } finally { IOUtils.closeStream(reader); IOUtils.closeStream(is); if (httpGet != null) { httpGet.releaseConnection(); } try { client.close(); } catch (IOException ex) { } } return buffer.toString(); }
From source file:com.liferay.blade.cli.command.InstallExtensionCommandTest.java
private static void _testJarsDiff(File warFile1, File warFile2) throws IOException { DifferenceCalculator differenceCalculator = new DifferenceCalculator(warFile1, warFile2); differenceCalculator.setFilenameRegexToIgnore(Collections.singleton(".*META-INF.*")); differenceCalculator.setIgnoreTimestamps(true); Differences differences = differenceCalculator.getDifferences(); if (!differences.hasDifferences()) { return;/*w ww . j av a 2s . co m*/ } StringBuilder message = new StringBuilder(); message.append("WAR "); message.append(warFile1); message.append(" and "); message.append(warFile2); message.append(" do not match:"); message.append(System.lineSeparator()); boolean realChange; Map<String, ZipArchiveEntry> added = differences.getAdded(); Map<String, ZipArchiveEntry[]> changed = differences.getChanged(); Map<String, ZipArchiveEntry> removed = differences.getRemoved(); if (added.isEmpty() && !changed.isEmpty() && removed.isEmpty()) { realChange = false; ZipFile zipFile1 = null; ZipFile zipFile2 = null; try { zipFile1 = new ZipFile(warFile1); zipFile2 = new ZipFile(warFile2); for (Map.Entry<String, ZipArchiveEntry[]> entry : changed.entrySet()) { ZipArchiveEntry[] zipArchiveEntries = entry.getValue(); ZipArchiveEntry zipArchiveEntry1 = zipArchiveEntries[0]; ZipArchiveEntry zipArchiveEntry2 = zipArchiveEntries[0]; if (zipArchiveEntry1.isDirectory() && zipArchiveEntry2.isDirectory() && (zipArchiveEntry1.getSize() == zipArchiveEntry2.getSize()) && (zipArchiveEntry1.getCompressedSize() <= 2) && (zipArchiveEntry2.getCompressedSize() <= 2)) { // Skip zipdiff bug continue; } try (InputStream inputStream1 = zipFile1 .getInputStream(zipFile1.getEntry(zipArchiveEntry1.getName())); InputStream inputStream2 = zipFile2 .getInputStream(zipFile2.getEntry(zipArchiveEntry2.getName()))) { List<String> lines1 = StringTestUtil.readLines(inputStream1); List<String> lines2 = StringTestUtil.readLines(inputStream2); message.append(System.lineSeparator()); message.append("--- "); message.append(zipArchiveEntry1.getName()); message.append(System.lineSeparator()); message.append("+++ "); message.append(zipArchiveEntry2.getName()); message.append(System.lineSeparator()); Patch<String> diff = DiffUtils.diff(lines1, lines2); for (Delta<String> delta : diff.getDeltas()) { message.append('\t'); message.append(delta.getOriginal()); message.append(System.lineSeparator()); message.append('\t'); message.append(delta.getRevised()); message.append(System.lineSeparator()); } } realChange = true; break; } } finally { ZipFile.closeQuietly(zipFile1); ZipFile.closeQuietly(zipFile2); } } else { realChange = true; } Assert.assertFalse(message.toString(), realChange); }
From source file:Main.java
public static void addNodeToXml(String nodeParentXpathStr, String xmlFilePath, String nodeName, String value, Map<String, String> attr) throws Exception { Document doc = null;// www . jav a 2s . c o m if (xmlFilePath == null || nodeParentXpathStr == null || nodeName == null || nodeParentXpathStr == null) throw new Exception("some parameters can not be null!"); doc = dombuilder.parse(new File(xmlFilePath)); Node pNode = (Node) xpath.compile(nodeParentXpathStr).evaluate(doc, XPathConstants.NODE); if (pNode == null) throw new Exception("can not find the node specified in nodeParentXpathStr!"); ; Element newNode = doc.createElement(nodeName); newNode.setTextContent(value); if (attr != null && !attr.isEmpty()) { for (String key : attr.keySet()) newNode.setAttribute(key, attr.get(key)); } pNode.appendChild(newNode); writeToXmlFile(doc, xmlFilePath); }
From source file:org.frontcache.core.FCUtils.java
public static boolean isWebComponentCacheableForClientType(Map<String, Long> expireTimeMap, String clientType) { if (expireTimeMap.isEmpty()) { // not a case -> log it logger.error("isWebComponentCacheableForClientType() - expireTimeMap must not be empty for clientType=" + clientType);/* ww w. j a v a 2s . c o m*/ return false; } Long expireTimeMillis = expireTimeMap.get(clientType); if (null == expireTimeMillis) { // not a case -> log it logger.error( "isWebComponentCacheableForClientType() - expireTimeMillis must be in expireTimeMap for clientType=" + clientType); return false; } if (CacheProcessor.NO_CACHE == expireTimeMillis) return false; return true; }
From source file:org.frontcache.core.FCUtils.java
/** * Check with current time if expired/* w w w.j a v a 2 s. c om*/ * * @param clientType {bot | browser} * @return */ public static boolean isWebComponentExpired(Map<String, Long> expireTimeMap, String clientType) { if (expireTimeMap.isEmpty()) { // not a case -> log it logger.error("isWebComponentExpired() - expireTimeMap must not be empty for clientType=" + clientType); return true; } Long expireTimeMillis = expireTimeMap.get(clientType); if (null == expireTimeMillis) { // not a case -> log it logger.error("isWebComponentExpired() - expireTimeMillis must be in expireTimeMap for clientType=" + clientType); return true; } if (CacheProcessor.CACHE_FOREVER == expireTimeMillis) return false; if (System.currentTimeMillis() > expireTimeMillis) return true; return false; }
From source file:com.telefonica.iot.perseo.Utils.java
/** * Converts an Event to a JSONObject. In case of error the returned object * will containf an 'errors' field with a "map" key-> error generated by the * key/*ww w .j a v a 2 s . c o m*/ * * @param event Esper event * @return JSONObject */ public static JSONObject Event2JSONObject(EventBean event) { JSONObject jo = new JSONObject(); Map<String, Object> errors = new HashMap<String, Object>(); String[] propertyNames = event.getEventType().getPropertyNames(); for (String propertyName : propertyNames) { try { jo.put(propertyName, event.get(propertyName)); } catch (JSONException je) { errors.put(propertyName, je.getMessage()); logger.error(je.getMessage()); } } if (!errors.isEmpty()) { jo.put("errors", errors); } return jo; }