List of usage examples for java.util Map isEmpty
boolean isEmpty();
From source file:com.ultrapower.eoms.common.plugin.ecside.util.ECSideUtils.java
public static String getDefaultSortSQL(Map map){ // ww w. j av a2s. c om StringBuffer rs=new StringBuffer(); if (map!=null && !map.isEmpty()){ for (Iterator itor=map.keySet().iterator();itor.hasNext();){ Object field=itor.next(); String ord=(String)map.get(field); rs.append(" ORDER BY ").append(field).append(" ").append(ord); break; } } return rs.toString(); }
From source file:com.mywork.framework.util.RemoteHttpUtil.java
/** * ???json?post?/*from w ww . j ava 2 s . c om*/ * * @throws IOException * */ public static String fetchJsonHttpResponse(String contentUrl, Map<String, String> headerMap, String jsonBody) throws IOException { Executor executor = Executor.newInstance(httpClient); 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 (jsonBody != null) { request.bodyString(jsonBody, ContentType.APPLICATION_JSON); } long start = System.currentTimeMillis(); String response = executor.execute(request).returnContent().asString(); logger.info("url = " + contentUrl + " request spend time = " + (System.currentTimeMillis() - start)); return response; }
From source file:com.mywork.framework.util.RemoteHttpUtil.java
/** * ???json?post?/* ww w. j av a 2 s . c o m*/ * * @throws IOException * @throws * */ public static String fetchJsonHttpResponse(String contentUrl, Map<String, String> headerMap, JsonObject bodyJson) throws IOException { Executor executor = Executor.newInstance(httpClient); 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 (bodyJson != null) { request.bodyString(bodyJson.toString(), ContentType.APPLICATION_JSON); } return executor.execute(request).returnContent().asString(); }
From source file:com.exampleka.jksonlib.JacksonRequest.java
/** * Converts a base URL, endpoint, and parameters into a full URL * * @param method The {@link com.android.volley.Request.Method} of the URL * @param baseUrl The base URL//from w ww .j a v a 2s .c o m * @param endpoint The endpoint being hit * @param params The parameters to be appended to the URL if a GET method is used * * @return The full URL */ private static String getUrl(int method, String baseUrl, String endpoint, Map<String, String> params) { if (params != null) { for (Map.Entry<String, String> entry : params.entrySet()) { if (entry.getValue() == null || entry.getValue().equals("null")) { entry.setValue(""); } } } if (method == Method.GET && params != null && !params.isEmpty()) { final StringBuilder result = new StringBuilder(baseUrl + endpoint); final int startLength = result.length(); for (String key : params.keySet()) { try { final String encodedKey = URLEncoder.encode(key, "UTF-8"); final String encodedValue = URLEncoder.encode(params.get(key), "UTF-8"); if (result.length() > startLength) { result.append("&"); } else { result.append("?"); } result.append(encodedKey); result.append("="); result.append(encodedValue); } catch (Exception e) { } } return result.toString(); } else { return baseUrl + endpoint; } }
From source file:eu.squadd.reflections.mapper.ServiceModelTranslator.java
private static void assignMixedTypesValue(Class sourceType, Method getter, Object sourceValue, Class destType, Method setter, Object destInstance) { System.out.println("Source collection doesn't match the one on destination side, resolve their types..."); if (sourceValue == null || destInstance == null) return;/*from ww w. j a v a 2 s. c o m*/ if (Collection.class.isAssignableFrom(sourceType)) { if (((Collection) sourceValue).isEmpty()) return; Class sourceArgClass = detectSourceCollectionPayload(getter); if (sourceArgClass == null) { System.err.println("Failed to determine source Collection payload type, operation aborted !!!"); return; } // if source is a collection then destination must be a Map Map<Integer, Class> destMapTypes = detectDestMapPayload(setter); if (destMapTypes.isEmpty() || destMapTypes.size() != 2) { System.err.println("Failed to determine destination Map payload types, operation aborted !!!"); return; } Class firstDestArgClass = destMapTypes.get(0); Class secordDestArgsClass = destMapTypes.get(1); System.out.println("*** Both Collection types sorted, populating values..."); Map destItems = createMapOfTypes(firstDestArgClass, secordDestArgsClass); //for (Object key : sourceItems.entrySet()) { Collection sourceItems = (Collection) sourceValue; Iterator it = sourceItems.iterator(); Integer i = 0; while (it.hasNext()) { Object element = transposeModel(sourceArgClass, secordDestArgsClass, it.next()); destItems.put(++i, element); } try { setter.invoke(destInstance, destItems); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { Logger.getLogger(ServiceModelTranslator.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("*** done"); } else if (Map.class.isAssignableFrom(sourceType)) { if (((Map) sourceValue).isEmpty()) return; Map<Integer, Class> sourceMapTypes = detectSourceMapPayload(getter); if (sourceMapTypes.isEmpty() || sourceMapTypes.size() != 2) { System.err.println("Failed to determine source Map payload types, operation aborted !!!"); return; } //Class firstSourceArgClass = sourceMapTypes.get(0); // dummy, not used anywere Class secondSourceArgClass = sourceMapTypes.get(1); Map sourceItems = (Map) sourceValue; // if source is a Map then destination must be a Collection Class destArgClass = detectDestCollectionPayload(setter); if (destArgClass == null) { System.err .println("Failed to determine destination Collection payload type, operation aborted !!!"); return; } Collection destItems; switch (destType.getName()) { case "java.util.List": destItems = createListOfType(destArgClass); break; case "java.util.Set": destItems = createSetOfType(destArgClass); break; default: System.out.println("4: Unrecognized collection, can't populate values"); return; } for (Object value : sourceItems.values()) { Object destValue = transposeModel(secondSourceArgClass, destArgClass, value); destItems.add(destValue); } try { setter.invoke(destInstance, destItems); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { Logger.getLogger(ServiceModelTranslator.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("*** done"); } else { System.out.println("4: Unrecognized collection type, cannot proceed, type: " + sourceType.getName()); } }
From source file:net.pms.util.OpenSubtitle.java
public static Map<String, Object> findSubs(File f, RendererConfiguration r) throws IOException { Map<String, Object> res = findSubs(getHash(f), f.length(), null, null, r); if (res.isEmpty()) { // no good on hash! try imdb String imdb = ImdbUtil.extractImdb(f); if (StringUtils.isEmpty(imdb)) { imdb = fetchImdbId(f);/* w ww . j a v a 2 s . c o m*/ } res = findSubs(null, 0, imdb, null, r); } if (res.isEmpty()) { // final try, use the name res = querySubs(f.getName(), r); } return res; }
From source file:com.asakusafw.workflow.executor.TaskExecutors.java
private static String encodeBatchArguments(Map<String, String> arguments) { if (arguments.isEmpty()) { // NOTE: never empty for windows return ","; }//from ww w . j a v a2 s .c o m StringBuilder buf = new StringBuilder(); arguments.forEach((k, v) -> { if (buf.length() != 0) { buf.append(','); } escape(buf, k); buf.append('='); escape(buf, v); }); return buf.toString(); }
From source file:org.yardstickframework.gridgain.GridGainNode.java
/** * @param springCfgPath Spring configuration file path. * @return Grid configuration./*from w ww .j a va 2 s .c om*/ * @throws Exception If failed. */ private static GridConfiguration loadConfiguration(String springCfgPath) throws Exception { URL url; try { url = new URL(springCfgPath); } catch (MalformedURLException e) { url = GridUtils.resolveGridGainUrl(springCfgPath); if (url == null) throw new GridException("Spring XML configuration path is invalid: " + springCfgPath + ". Note that this path should be either absolute or a relative local file system path, " + "relative to META-INF in classpath or valid URL to GRIDGAIN_HOME.", e); } GenericApplicationContext springCtx; try { springCtx = new GenericApplicationContext(); new XmlBeanDefinitionReader(springCtx).loadBeanDefinitions(new UrlResource(url)); springCtx.refresh(); } catch (BeansException e) { throw new Exception("Failed to instantiate Spring XML application context [springUrl=" + url + ", err=" + e.getMessage() + ']', e); } Map<String, GridConfiguration> cfgMap; try { cfgMap = springCtx.getBeansOfType(GridConfiguration.class); } catch (BeansException e) { throw new Exception( "Failed to instantiate bean [type=" + GridConfiguration.class + ", err=" + e.getMessage() + ']', e); } if (cfgMap == null || cfgMap.isEmpty()) throw new Exception("Failed to find grid configuration in: " + url); return cfgMap.values().iterator().next(); }
From source file:Main.java
public static void updateNodeToXml(String nodeXpathStr, String xmlFilePath, String value, Map<String, String> attr) throws Exception { Document doc = null;// ww w .ja v a2 s . c o m if (xmlFilePath == null || nodeXpathStr == null) throw new Exception("some parameters can not be null!"); doc = dombuilder.parse(new File(xmlFilePath)); Node pNode = (Node) xpath.compile(nodeXpathStr).evaluate(doc, XPathConstants.NODE); if (pNode == null) throw new Exception("can not find the node specified in nodeXpathStr!"); ; pNode.setTextContent(value); if (attr != null && !attr.isEmpty()) { for (String key : attr.keySet()) ((Element) pNode).setAttribute(key, attr.get(key)); } writeToXmlFile(doc, xmlFilePath); }
From source file:org.apache.synapse.transport.passthru.util.PassThroughTransportUtils.java
/** * Remove unwanted headers from the http response of outgoing request. These are headers which * should be dictated by the transport and not the user. We remove these as these may get * copied from the request messages//from www. j a v a 2s . com * * @param msgContext the Axis2 Message context from which these headers should be removed * @param targetConfiguration configuration for the passThrough handler */ public static void removeUnwantedHeaders(MessageContext msgContext, TargetConfiguration targetConfiguration) { Map transportHeaders = (Map) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS); Map excessHeaders = (Map) msgContext.getProperty(NhttpConstants.EXCESS_TRANSPORT_HEADERS); if (transportHeaders != null && !transportHeaders.isEmpty()) { //a hack which takes the original content header if (transportHeaders.get(HTTP.CONTENT_LEN) != null) { msgContext.setProperty(PassThroughConstants.ORGINAL_CONTEN_LENGTH, transportHeaders.get(HTTP.CONTENT_LEN)); } removeUnwantedHeadersFromHeaderMap(transportHeaders, targetConfiguration); } if (excessHeaders != null && !excessHeaders.isEmpty()) { removeUnwantedHeadersFromHeaderMap(excessHeaders, targetConfiguration); } }