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
static <K, V> Map<K, V> getMap(Map<K, V> orig) { if (orig == null || orig.size() == 0) { return Collections.emptyMap(); } else if (orig.size() == 1) { final Map.Entry<K, V> entry = orig.entrySet().iterator().next(); return Collections.singletonMap(entry.getKey(), entry.getValue()); } else {/*from w ww . j a v a2s . com*/ return Collections.unmodifiableMap(new TreeMap<>(orig)); } }
From source file:Main.java
public static <V, K> Map<V, K> safe(Map<V, K> collection) { return collection == null ? Collections.emptyMap() : collection; }
From source file:Main.java
/** * Returns an unmodifiable view of the specified {@code mapSet}. This * method allows modules to provide users with "read-only" access to * {@link Map}, but also to the value {@link Set}. * * @param <K>/*from w ww . ja v a2 s . co m*/ * the class of the map keys * @param <V> * the class of the set values * @param mapSet * the {@link Map} of {@link Set} for which an unmodifiable view * is to be returned * @return an unmodifiable view of the specified map. * * @see Collections#unmodifiableMap(Map) * @see Collections#unmodifiableSet(Set) * @since 4.2 */ @Nonnull public static <K, V> Map<K, Set<V>> unmodifiableMapSet(@Nullable final Map<K, Set<V>> mapSet) { if (mapSet == null) { return Collections.emptyMap(); } for (final Map.Entry<K, Set<V>> entry : mapSet.entrySet()) { final K key = entry.getKey(); final Set<V> value = entry.getValue(); mapSet.replace(key, Collections.unmodifiableSet(value)); } return Collections.unmodifiableMap(mapSet); }
From source file:Main.java
private static Map<Object, Object> createMap(Object... keysAndValues) { switch (keysAndValues.length) { case 0:/* ww w .j a va 2s. c o m*/ return Collections.emptyMap(); case 2: return Collections.singletonMap(keysAndValues[0], keysAndValues[1]); } if (keysAndValues.length % 2 == 1) { throw new IllegalArgumentException("Odd number of createMap arguments"); } final Map<Object, Object> map = new HashMap<Object, Object>(); for (int i = 0; i < keysAndValues.length; i += 2) { map.put(keysAndValues[i], keysAndValues[i + 1]); } return map; }
From source file:Main.java
/** * Creates an empty element mapping.//from w ww. ja v a 2s. c om * * @return the empty mapping */ private static Map<Node, Node> emptyElementMapping() { return Collections.emptyMap(); }
From source file:Main.java
public static Map<String, String> extractParameters(String exString) { exString = exString.trim();//from www . j a va 2 s . c om int leftParIndex = exString.indexOf(LEFT_PARENTHESIS); if (leftParIndex == -1) { return Collections.emptyMap(); } String paramsStr; if (exString.endsWith(")")) { paramsStr = exString.substring(leftParIndex + 1, exString.lastIndexOf(")")); } else { paramsStr = exString.substring(leftParIndex + 1, exString.length()); } Map<String, String> parameters = new LinkedHashMap<String, String>(); String[] paramsPairs = paramsStr.trim().split(","); for (String paramsPair : paramsPairs) { String[] keyValue = paramsPair.trim().split("="); if (keyValue.length == 2) { parameters.put(keyValue[0].trim(), keyValue[1].trim()); } } return parameters; }
From source file:com.linecorp.armeria.server.docs.FieldInfo.java
static FieldInfo of(FieldMetaData fieldMetaData) { return of(fieldMetaData, null, Collections.emptyMap()); }
From source file:com.linecorp.armeria.server.docs.MapInfo.java
static MapInfo of(MapMetaData mapMetaData) { return of(mapMetaData, null, Collections.emptyMap()); }
From source file:Main.java
public static Map<String, String> attributesToMap(String scope, XMLStreamReader reader) { int numAttrs = reader.getAttributeCount(); if (numAttrs == 0) { return Collections.emptyMap(); }/* w w w. j a v a 2 s .c o m*/ Map<String, String> rtn = new HashMap<String, String>(numAttrs); for (int i = 0; i < numAttrs; i++) { StringBuilder attrName = new StringBuilder(); if (scope.length() > 0) { attrName.append(scope).append(SCOPE_SEP); } attrName.append(reader.getAttributeName(i).toString()); rtn.put(attrName.toString(), reader.getAttributeValue(i)); } return rtn; }
From source file:com.openshift.internal.util.URIUtils.java
public static Map<String, String> splitFragment(String location) { if (StringUtils.isEmpty(location)) { return Collections.emptyMap(); }/*from w w w.j a va2s. c om*/ URI uri = null; try { uri = new URI(location); } catch (URISyntaxException e) { throw new RuntimeException(e); } return splitFragment(uri); }