示例#1
0
 @SuppressWarnings("unchecked")
 <O, R> R convert(O input, Class<R> type) {
   Class<O> inputType = (Class<O>) input.getClass();
   if (inputType == type) {
     return (R) input;
   }
   ETransformer<O, R> transformer = transformerManager.getTransformerSafe(inputType, type);
   return transformer.from(input);
 }
示例#2
0
  @SuppressWarnings("unchecked")
  <O, R> List<R> convert(Iterable<O> inputs, Class<R> type) {
    Iterator<O> iterator = inputs.iterator();
    if (!iterator.hasNext()) {
      return Collections.emptyList();
    }

    List<R> results = new ArrayList<R>();
    ETransformer<O, R> transformer = null;
    for (O t : inputs) {
      if (transformer == null) {
        Class<O> inputType = (Class<O>) t.getClass();
        transformer = transformerManager.getTransformerSafe(inputType, type);
      }
      results.add(transformer.from(t));
    }

    return results;
  }