List of usage examples for java.util Map isEmpty
boolean isEmpty();
From source file:info.archinnov.achilles.internal.validation.Validator.java
public static void validateNotEmpty(Map<?, ?> arg, String message, Object... args) { if (arg == null || arg.isEmpty()) { throw new AchillesException(format(message, args)); }//from w w w . jav a 2s . co m }
From source file:com.zotoh.maedr.device.netty.NettpHplr.java
private static void getParams(HttpEvent ev, String uri) { QueryStringDecoder dec = new QueryStringDecoder(uri); Map<String, List<String>> params = dec.getParameters(); if (!params.isEmpty()) { for (Entry<String, List<String>> p : params.entrySet()) { ev.addParam(p.getKey(), p.getValue().toArray(new String[0])); }/*from w ww .j av a 2 s . c o m*/ } }
From source file:io.parallec.core.util.PcStringUtils.java
/** * Str map to str./* w w w .j a v a 2 s . c om*/ * * @param map * the map * @return the string */ public static String strMapToStr(Map<String, String> map) { StringBuilder sb = new StringBuilder(); if (map == null || map.isEmpty()) return sb.toString(); for (Entry<String, String> entry : map.entrySet()) { sb.append("< " + entry.getKey() + ", " + entry.getValue() + "> "); } return sb.toString(); }
From source file:Main.java
/** * Determine if the contents of two maps are the same, i.e. the same keys are mapped to the same values in both maps. * @param a the first {@link Map}/* w w w . ja va 2 s .c o m*/ * @param b the secound {@link Map} * @return <code>true</code> if the contents are the same, <code>false</code> otherwise. */ public static <K, V> boolean equalContents(Map<? extends K, ? extends V> a, Map<? extends K, ? extends V> b) { if (a == b) { return true; } else if (a.isEmpty() && b.isEmpty()) { return true; } if (a.size() != b.size()) { return false; } else { for (Map.Entry entryA : a.entrySet()) { if (!b.containsKey(entryA.getKey()) || !b.get(entryA.getKey()).equals(entryA.getValue())) { return false; } } return true; } }
From source file:com.exxonmobile.ace.hybris.storefront.servlets.util.FilterSpringUtil.java
/** * The same as {@link #getSpringBean(HttpServletRequest, String, Class)} but uses ServletContext as the first * parameter. It might be used in places, where HttpServletRequest is not available, but ServletContext is. *//*w w w . jav a 2 s. c o m*/ public static <T> T getSpringBean(final ServletContext servletContext, final String beanName, final Class<T> beanClass) { T ret = null; final WebApplicationContext appContext = WebApplicationContextUtils .getRequiredWebApplicationContext(servletContext); if (StringUtils.isNotBlank(beanName)) { try { ret = (T) appContext.getBean(beanName); } catch (final NoSuchBeanDefinitionException ex) { LOG.warn("No bean found with the specified name. Trying to resolve bean using type..."); } } if (ret == null) { if (beanClass == null) { LOG.warn("No bean could be resolved. Reason: No type specified."); } else { final Map<String, T> beansOfType = appContext.getBeansOfType(beanClass); if (beansOfType != null && !beansOfType.isEmpty()) { if (beansOfType.size() > 1) { LOG.warn("More than one matching bean found of type " + beanClass.getSimpleName() + ". Returning the first one found."); } ret = beansOfType.values().iterator().next(); } } } return ret; }
From source file:com.acc.filter.FilterSpringUtil.java
/** * The same as {@link #getSpringBean(HttpServletRequest, String, Class)} but uses ServletContext as the first * parameter. It might be used in places, where HttpServletRequest is not available, but ServletContext is. *//*from w ww . ja va 2 s.c o m*/ public static <T> T getSpringBean(final ServletContext servletContext, final String beanName, final Class<T> beanClass) { T ret = null; final WebApplicationContext appContext = WebApplicationContextUtils .getRequiredWebApplicationContext(servletContext); if (StringUtils.isNotBlank(beanName)) { try { ret = (T) appContext.getBean(beanName); } catch (final NoSuchBeanDefinitionException nsbde) { LOG.warn("No bean found with the specified name. Trying to resolve bean using type..."); } } if (ret == null) { if (beanClass == null) { LOG.warn("No bean could be resolved. Reason: No type specified."); } else { final Map<String, T> beansOfType = appContext.getBeansOfType(beanClass); if (beansOfType != null && !beansOfType.isEmpty()) { if (beansOfType.size() > 1) { LOG.warn("More than one matching bean found of type " + beanClass.getSimpleName() + ". Returning the first one found."); } ret = beansOfType.values().iterator().next(); } } } return ret; }
From source file:Main.java
/** * Returns the ordered keys of the given map * /*w w w. j ava2 s . co m*/ * @param map * the map * @return the ordered keys */ public final static List<String> getOrderedKeys(final Map<String, Object> map) { List<String> keys = new LinkedList<String>(); if (!map.isEmpty()) { keys.addAll(map.keySet()); Collections.sort(keys, new Comparator<String>() { /** * {@inheritDoc} */ public int compare(String o1, String o2) { if (o1 == o2) { return 0; } int n1 = -1; int n2 = -1; try { n1 = Integer.parseInt(o1.substring(1)); } catch (NumberFormatException e) { // IGNORE } try { n2 = Integer.parseInt(o2.substring(1)); } catch (NumberFormatException e) { // IGNORE } /* * n1 is a number */ if (n1 != -1) { /* * n2 is a number */ if (n2 != -1) { return n1 - n2; } /* * n2 is a string literal */ return -1; } /* * n1 is a literal and n2 is a number */ if (n2 != -1) { return -1; } /* * both are literals */ return o1.compareTo(o2); } }); } return keys; }
From source file:edu.mayo.cts2.framework.webapp.rest.view.jsp.Beans.java
private static Map returnSummary(Map summary, Object bean) { if (summary.isEmpty()) { summary.put("Entry", bean.getClass().getSimpleName()); }// w w w.j av a 2 s. c om return summary; }
From source file:org.apache.calcite.adapter.elasticsearch.ElasticsearchSchemaFactory.java
/** * Builds elastic rest client from user configuration * @param coordinates list of {@code hostname/port} to connect to * @return newly initialized low-level rest http client for ES *//*from w ww. j a va 2s .com*/ private static RestClient connect(Map<String, Integer> coordinates) { Objects.requireNonNull(coordinates, "coordinates"); Preconditions.checkArgument(!coordinates.isEmpty(), "no ES coordinates specified"); final Set<HttpHost> set = new LinkedHashSet<>(); for (Map.Entry<String, Integer> entry : coordinates.entrySet()) { set.add(new HttpHost(entry.getKey(), entry.getValue())); } return RestClient.builder(set.toArray(new HttpHost[0])).build(); }
From source file:net.logstash.logback.composite.JsonWritingUtils.java
/** * Writes a map as String fields to the generator if and only if the fieldName and values are not null. */// www .j a v a 2 s .c o m public static void writeMapStringFields(JsonGenerator generator, String fieldName, Map<String, String> map) throws IOException, JsonMappingException { if (shouldWriteField(fieldName) && map != null && !map.isEmpty()) { generator.writeObjectFieldStart(fieldName); for (Map.Entry<String, String> entry : map.entrySet()) { writeStringField(generator, entry.getKey(), entry.getValue()); } generator.writeEndObject(); } }