Exemple #1
0
  public static <TO, FROM> List<TO> mapFilterNulls(
      Function<FROM, TO> converter, Collection<FROM> fromCollection) {

    ArrayList<TO> toList = new ArrayList<>(fromCollection.size());

    for (FROM from : fromCollection) {
      TO converted = converter.apply(from);
      if (converted != null) {
        toList.add(converted);
      }
    }

    return toList;
  }
Exemple #2
0
 public static Collection toCollection(Object value) {
   if (value instanceof Collection) {
     return (Collection) value;
   } else if (value == null) {
     return new ArrayList();
   } else if (value instanceof Map) {
     return ((Map) value).entrySet();
   } else {
     ArrayList list = new ArrayList(Boon.len(value));
     Iterator<Object> iterator = iterator(Typ.object, value);
     while (iterator.hasNext()) {
       list.add(iterator.next());
     }
     return list;
   }
 }
Exemple #3
0
 @SuppressWarnings({"rawtypes", "unchecked"})
 public static List toList(Object value) {
   if (value instanceof List) {
     return (List) value;
   } else if (value instanceof Collection) {
     return new ArrayList((Collection) value);
   } else if (value == null) {
     return new ArrayList();
   } else if (value instanceof Map) {
     return new ArrayList(((Map) value).entrySet());
   } else {
     ArrayList list = new ArrayList(Boon.len(value));
     Iterator<Object> iterator = iterator(Typ.object, value);
     while (iterator.hasNext()) {
       list.add(iterator.next());
     }
     return list;
   }
 }