List of usage examples for java.util Collections emptyMap
@SuppressWarnings("unchecked") public static final <K, V> Map<K, V> emptyMap()
From source file:Main.java
public static <K, V> Map<K, V> copyNullSafeHashMapWithNullValues(Map<? extends K, ? extends V> map) { if (map.isEmpty()) { return Collections.emptyMap(); }/*w w w.j av a2s . c om*/ return Collections.unmodifiableMap(copyNullSafeMutableHashMapWithNullValues(map)); }
From source file:Main.java
/** * Returns an non null value based on the giving {@link Map} * * @param map/*w ww . j a v a 2 s. c o m*/ * value to evaluate * @return the original value or an empty {@link Map} * @since 4.2 */ public static <K, V> Map<K, V> nonNullMap(@Nullable final Map<K, V> map) { return map == null ? Collections.emptyMap() : map; }
From source file:Main.java
/** * Parses and returns CGI arguments./*from w ww .j av a 2s . co m*/ * * @param rest the string to parse * @return CGI arguments from <tt>rest</tt> */ public static Map<String, String> parseArgs(final String rest) { if (isEmpty(rest)) return Collections.emptyMap(); final Map<String, String> res = new HashMap<String, String>(3); for (StringTokenizer st = new StringTokenizer(rest, "&", false); st.hasMoreTokens();) { final String pair = st.nextToken(); final int ieq = pair.indexOf('='); String key, val; if (ieq == -1) { key = pair; val = null; } else { key = pair.substring(0, ieq); val = pair.substring(ieq + 1); } res.put(key.trim(), val == null ? val : val.trim()); } return res; }
From source file:Main.java
public static Map<String, Object> fromJson(String params) { try {/* ww w . j ava 2s .c o m*/ JavaType jType = getCollectionType(Map.class, String.class, Object.class); return mapper.readValue(params, jType); } catch (Exception e) { return Collections.emptyMap(); } }
From source file:Main.java
/** */ public static Map<QName, String> toQName(Map<String, String> setProps) { if (setProps == null) { return Collections.emptyMap(); }//www . j ava 2 s . co m Map<QName, String> result = new HashMap<QName, String>(setProps.size()); for (Map.Entry<String, String> entry : setProps.entrySet()) { result.put(createQNameWithCustomNamespace(entry.getKey()), entry.getValue()); } return result; }
From source file:Maps.java
public static <K, V> Map<K, V> create() { return Collections.emptyMap(); }
From source file:Main.java
/** * Wraps a possibly null map in an immutable wrapper. * * @param <K> the key type/*from ww w . j ava 2s. c o m*/ * @param <V> the value type * @param source Nullable map to wrap. * @return {@link Collections#unmodifiableMap(java.util.Map)} if given map is not null, otherwise * {@link java.util.Collections#emptyMap()}. */ public static <K, V> Map<K, V> wrap(final Map<K, V> source) { if (source != null) { return new HashMap<>(source); } return Collections.emptyMap(); }
From source file:Main.java
/** * Combines two lists into map, using first list as keys and second as values * * @param keys List used as keys//from w ww .ja v a 2 s. c o m * @param values List used as values * @param <K> Type of values in keys list * @param <V> Type of values in values list * @return {@link LinkedHashMap} */ public static <K, V> Map<K, V> combineLists(List<? extends K> keys, List<? extends V> values) { if (keys.size() != values.size()) { throw new IllegalArgumentException("Cannot combine lists with dissimilar sizes"); } if (keys.isEmpty() && values.isEmpty()) { return Collections.emptyMap(); } int size = values.size(); Map<K, V> map = new LinkedHashMap<>(size); for (int i = 0; i < size; i++) { map.put(keys.get(i), values.get(i)); } return map; }
From source file:Main.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static <K, V> Map newMap(Object... keysAndValues) { if (keysAndValues == null) { return Collections.emptyMap(); }//from ww w .jav a 2 s . c o m if (keysAndValues.length % 2 == 1) { throw new IllegalArgumentException("Must have an even number of keys and values"); } Map<K, V> map = new HashMap<K, V>(); for (int i = 0; i < keysAndValues.length; i += 2) { map.put((K) keysAndValues[i], (V) keysAndValues[i + 1]); } return map; }
From source file:Main.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static <K, V> Map newMap(Object... keysAndValues) { if (keysAndValues == null) { return Collections.emptyMap(); }/*from w w w.j a v a 2 s .co m*/ if (keysAndValues.length % 2 == 1) { throw new IllegalArgumentException("Must have an even number of keys and values"); } Map<K, V> map = new HashMap<>(); for (int i = 0; i < keysAndValues.length; i += 2) { map.put((K) keysAndValues[i], (V) keysAndValues[i + 1]); } return map; }