Skip to content

Commit

Permalink
Improved: Remove useless ‘UtilGenerics#toMap’ overloads
Browse files Browse the repository at this point in the history
(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 95430bd
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -108,50 +107,4 @@ public static <K, V> Map<K, V> toMap(Object object) {
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<>();
Expand Down

0 comments on commit 95430bd

Please sign in to comment.