Github user cestella commented on a diff in the pull request:

    https://github.com/apache/incubator-metron/pull/397#discussion_r92836067
  
    --- Diff: 
metron-platform/metron-common/src/main/java/org/apache/metron/common/utils/ConversionUtils.java
 ---
    @@ -18,23 +18,41 @@
     
     package org.apache.metron.common.utils;
     
    +import com.google.common.collect.Lists;
     import org.apache.commons.beanutils.BeanUtilsBean2;
     import org.apache.commons.beanutils.ConvertUtilsBean;
     
    +import java.util.List;
    +
     public class ConversionUtils {
    -  private static ThreadLocal<ConvertUtilsBean> UTILS_BEAN  = new 
ThreadLocal<ConvertUtilsBean>() {
    +  private static ThreadLocal<ConvertUtilsBean> UTILS_BEAN = new 
ThreadLocal<ConvertUtilsBean>() {
         @Override
         protected ConvertUtilsBean initialValue() {
           ConvertUtilsBean ret = 
BeanUtilsBean2.getInstance().getConvertUtils();
           ret.deregister();
    -      ret.register(false,true, 1);
    +      ret.register(false, true, 1);
           return ret;
         }
       };
    +
       public static <T> T convert(Object o, Class<T> clazz) {
    -    if(o == null) {
    +    if (o == null) {
           return null;
         }
         return clazz.cast(UTILS_BEAN.get().convert(o, clazz));
       }
    +
    +  /**
    +   * Performs naive List type conversion.
    +   *
    +   * @param from Source list
    +   * @param clazz Class type to cast the List elements to
    +   * @param <T> Source element type
    +   * @param <U> Desired element type
    +   * @return New List with the elements cast to the desired type
    +   */
    +  public static <T, U> List<U> convertList(List<T> from, Class<U> clazz) {
    +    return Lists.transform(from, s -> clazz.cast(s));
    --- End diff --
    
    My issue with this is that above we are calling `convert` and is a coercive 
operation (e.g. convert("1", Integer.class) == 1) rather than just a simple 
cast.  Can you make `convertList` call `convert` on the elements?  If you 
really want a naive version of this, feel free to make a `castList` method.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to