Skip to content
Permalink
Browse files

Improved: Remove useless ‘UtilGenerics#toMap’ overloads

(OFBIZ-11141)


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1863495 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Jul 20, 2019
1 parent fe96315 commit 95430bd0cf50101837be476855594784c8e233c7
@@ -19,7 +19,6 @@
package org.apache.ofbiz.base.util;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -108,50 +107,4 @@ private UtilGenerics() {}
}
return (Map<K, V>) object;
}

public static <K, V> Map<K, V> toMap(Class<K> keyType, Class<V> valueType, Object... data) {
if (data == null) {
return null;
}
if (data.length % 2 == 1) {
throw new IllegalArgumentException("You must pass an even sized array to the toMap method");
}
Map<K, V> map = new LinkedHashMap<>();
for (int i = 0; i < data.length;) {
Object key = data[i];
if (key != null && !(keyType.isInstance(key))) {
throw new IllegalArgumentException("Key(" + i + ") is not a " + keyType.getName() + ", was(" + key.getClass().getName() + ")");
}
i++;
Object value = data[i];
if (value != null && !(valueType.isInstance(value))) {
throw new IllegalArgumentException("Value(" + i + ") is not a " + keyType.getName() + ", was(" + key.getClass().getName() + ")");
}
i++;
map.put(keyType.cast(key), valueType.cast(value));
}
return map;
}

@SafeVarargs
@SuppressWarnings("hiding")
public static <K, Object> Map<K, Object> toMap(Class<K> keyType, Object... data) {
if (data == null) {
return null;
}
if (data.length % 2 == 1) {
throw new IllegalArgumentException("You must pass an even sized array to the toMap method");
}
Map<K, Object> map = new LinkedHashMap<>();
for (int i = 0; i < data.length;) {
Object key = data[i];
if (key != null && !(keyType.isInstance(key))) {
throw new IllegalArgumentException("Key(" + i + ") is not a " + keyType.getName() + ", was(" + key.getClass().getName() + ")");
}
i++;
Object value = data[i];
map.put(keyType.cast(key), value);
}
return map;
}
}
@@ -682,7 +682,7 @@ public static String getMessage(String resource, String name, Map<String, ? exte
}

public static String getMessageMap(String resource, String name, Locale locale, Object... context) {
return getMessage(resource, name, UtilGenerics.toMap(String.class, context), locale);
return getMessage(resource, name, UtilMisc.toMap(context), locale);
}

private static Set<String> resourceNotFoundMessagesShown = new HashSet<>();

0 comments on commit 95430bd

Please sign in to comment.
You can’t perform that action at this time.