List of usage examples for java.util Collections emptyMap
@SuppressWarnings("unchecked") public static final <K, V> Map<K, V> emptyMap()
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.SelectListGeneratorVTwo.java
public static Map<String, String> getOptions(EditConfigurationVTwo editConfig, String fieldName, WebappDaoFactory wDaoFact) {//from www.j av a 2 s. com if (editConfig == null) { log.error("fieldToSelectItemList() must be called with a non-null EditConfigurationVTwo "); return Collections.emptyMap(); } if (fieldName == null) { log.error("fieldToSelectItemList() must be called with a non-null fieldName"); return Collections.emptyMap(); } FieldVTwo field = editConfig.getField(fieldName); if (field == null) { log.error("no field \"" + fieldName + "\" found from editConfig."); return Collections.emptyMap(); } if (field.getFieldOptions() == null) { return Collections.emptyMap(); } try { return field.getFieldOptions().getOptions(editConfig, fieldName, wDaoFact); } catch (Exception e) { log.error("Error runing getFieldOptionis()", e); return Collections.emptyMap(); } }
From source file:Main.java
/** * Functions as per {@link Collections#unmodifiableMap(Map)} with the exception that if the * given map is null, this method will return an unmodifiable empty map as per * {@link Collections#emptyMap()}./*from w w w . j av a2 s . c o m*/ * * @param map the map for which an unmodifiable view is to be returned * @return an unmodifiable view of the specified set, or an unmodifiable empty set if the given * set is null */ public static <K, V> Map<K, V> unmodifiableMapNullSafe(Map<? extends K, ? extends V> map) { if (map == null) { return Collections.emptyMap(); } return Collections.unmodifiableMap(map); }
From source file:Main.java
public static <K, V> Map<K, V> nullToEmpty(Map<K, V> map) { return map == null ? Collections.emptyMap() : map; }
From source file:com.axibase.tsd.util.AtsdUtil.java
public static Map<String, String> toMap(String... tagNamesAndValues) { if (tagNamesAndValues == null || tagNamesAndValues.length == 0) { return Collections.emptyMap(); }/*from w w w . j av a 2s .co m*/ if (tagNamesAndValues.length % 2 == 1) { throw new IllegalArgumentException("Key without value"); } Map<String, String> result = new HashMap<String, String>(); for (int i = 0; i < tagNamesAndValues.length; i++) { result.put(tagNamesAndValues[i], tagNamesAndValues[++i]); } return result; }
From source file:com.weibo.api.motan.config.ConfigUtil.java
/** * export fomart: protocol1:port1,protocol2:port2 * //from w w w. ja v a 2 s . c o m * @param export * @return */ @SuppressWarnings("unchecked") public static Map<String, Integer> parseExport(String export) { if (StringUtils.isBlank(export)) { return Collections.emptyMap(); } Map<String, Integer> pps = new HashMap<String, Integer>(); String[] protocolAndPorts = MotanConstants.COMMA_SPLIT_PATTERN.split(export); for (String pp : protocolAndPorts) { if (StringUtils.isBlank(pp)) { continue; } String[] ppDetail = pp.split(":"); if (ppDetail.length == 2) { pps.put(ppDetail[0], Integer.parseInt(ppDetail[1])); } else if (ppDetail.length == 1) { if (MotanConstants.PROTOCOL_INJVM.equals(ppDetail[0])) { pps.put(ppDetail[0], MotanConstants.DEFAULT_INT_VALUE); } else { int port = MathUtil.parseInt(ppDetail[0], 0); if (port <= 0) { throw new MotanServiceException("Export is malformed :" + export); } else { pps.put(MotanConstants.PROTOCOL_MOTAN, port); } } } else { throw new MotanServiceException("Export is malformed :" + export); } } return pps; }
From source file:Main.java
/** * Creates a new sorted map, based on the values from the given map and Comparator. * // w w w.j av a 2 s. c o m * @param map the map which needs to be sorted * @param valueComparator the Comparator * @return a new sorted map */ public static <K, V> Map<K, V> sortMapByValue(Map<K, V> map, Comparator<Entry<K, V>> valueComparator) { if (map == null) { return Collections.emptyMap(); } List<Entry<K, V>> entriesList = new LinkedList<>(map.entrySet()); // Sort based on the map's values Collections.sort(entriesList, valueComparator); Map<K, V> orderedMap = new LinkedHashMap<>(entriesList.size()); for (Entry<K, V> entry : entriesList) { orderedMap.put(entry.getKey(), entry.getValue()); } return orderedMap; }
From source file:Main.java
/** * Returns a map of the passed node's attributes * @param node The nopde to get an attribute map for * @return a [possibly empty] map of the node's attributes *///from w w w. j av a2 s.c o m public static Map<String, String> getAttributeMap(final Node node) { if (node == null) throw new IllegalArgumentException("The passed node was null"); final NamedNodeMap nnm = node.getAttributes(); final int size = nnm.getLength(); if (size == 0) return Collections.emptyMap(); final Map<String, String> map = new LinkedHashMap<String, String>(size); for (int i = 0; i < size; i++) { final Attr attr = (Attr) nnm.item(i); map.put(attr.getName(), attr.getValue()); } return map; }
From source file:Main.java
/** * Wraps a Map with the {@code Collections.unmodifiableMap}, but only once. * * <p>Checks the {@link Map} passed to ensure that it is not already a {@code Collections.unmodifiableMap}. * If the parameter is a null or empty, then it returns {@code Collections.emptyMap}. * * @param map {@link Map} to wrap with {@code Collections.unmodifiableMap} * @param <K> Key type//from w w w. j av a2 s. com * @param <V> Value type * @return An unmodifiable Map */ public static <K, V> Map<K, V> unmodifiableMap(final Map<K, V> map) { if (isNotEmpty(map)) { if (!(exampleUnmodifiableMap.getClass().equals(map.getClass()))) { return Collections.unmodifiableMap(map); } return map; } return Collections.emptyMap(); }
From source file:com.linecorp.armeria.server.docs.FunctionInfo.java
static FunctionInfo of(Method method, Map<Class<?>, ? extends TBase<?, ?>> sampleRequests) throws ClassNotFoundException { return of(method, sampleRequests, null, Collections.emptyMap()); }
From source file:com.google.mr4c.util.CustomFormat.java
public static CustomFormat createInstance(String pattern) { Map<String, String> empty = Collections.emptyMap(); return createInstance(pattern, empty); }