Пример #1
0
 /**
  * Convert a list of DTO into a List of Domain.
  *
  * <p>If no Converter exists, an empty list is returned.
  *
  * @param domClazz Domain Class
  * @param dtos DTOs to be converted
  * @param <D> Class of Domain
  * @param <J> Class of DTO
  * @return List of Domain objects.
  */
 @SuppressWarnings("unchecked")
 public static <D, J extends DTO> List<D> convertToDomain(Class<D> domClazz, List<J> dtos) {
   BasicConverter<D, J> converter = (BasicConverter<D, J>) CONVERTERS.get(domClazz);
   if (converter == null) {
     return new ArrayList<>(0);
   }
   List<D> doms = new ArrayList<>(dtos.size());
   for (J dto : dtos) {
     doms.add(domClazz.cast(converter.convertToDomainObject(dto)));
   }
   return doms;
 }
Пример #2
0
  /**
   * Convert a list of Domain into a List of DTO.
   *
   * <p>If no Converter exists, an empty list is returned.
   *
   * @param dtoClazz DTO Class
   * @param domClazz Domain Object Class.
   * @param doms List of Domain Object to be converted.
   * @return List of DTO.
   */
  @SuppressWarnings("unchecked")
  public static <D, J> List<J> convertToBasic(Class<J> dtoClazz, Class<D> domClazz, List<D> doms) {
    if (doms == null) return new ArrayList<>(0);

    BasicConverter<D, ?> converter = (BasicConverter<D, ?>) CONVERTERS.get(domClazz);
    if (converter == null) {
      return new ArrayList<>(0);
    }
    List<J> dtos = new ArrayList<>(doms.size());
    for (D dom : doms) {
      dtos.add(dtoClazz.cast(converter.convertToDataTransferObject(dom)));
    }
    return dtos;
  }