All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.oasp.module.beanmapping.common.base.AbstractBeanMapper Maven / Gradle / Ivy

Go to download

Minimal shim for bean mapping to convert between compatible Java beans (e.g. JPA entity to transfer-object and vice versa).

There is a newer version: 3.0.0
Show newest version
package io.oasp.module.beanmapping.common.base;

import io.oasp.module.beanmapping.common.api.BeanMapper;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * The abstract base implementation of {@link BeanMapper}.
 *
 */
public abstract class AbstractBeanMapper implements BeanMapper {

  /**
   * The constructor.
   */
  public AbstractBeanMapper() {

    super();
  }

  @Override
  public  T mapTypesafe(Class apiClass, S source, Class targetClass) {

    return map(source, targetClass);
  }

  @Override
  public  List mapList(List source, Class targetClass) {

    return mapList(source, targetClass, false);
  }

  @Override
  public  List mapList(List source, Class targetClass, boolean suppressNullValues) {

    if ((source == null) || (source.isEmpty())) {
      return new ArrayList<>();
    }
    List result = new ArrayList<>(source.size());
    for (Object sourceObject : source) {
      if ((sourceObject != null) || !suppressNullValues) {
        result.add(map(sourceObject, targetClass));
      }
    }
    return result;
  }

  @Override
  public  Set mapSet(Set source, Class targetClass) {

    return mapSet(source, targetClass, false);
  }

  @Override
  public  Set mapSet(Set source, Class targetClass, boolean suppressNullValues) {

    if ((source == null) || (source.isEmpty())) {
      return new HashSet<>();
    }
    Set result = new HashSet<>(source.size());
    for (Object sourceObject : source) {
      if ((sourceObject != null) || !suppressNullValues) {
        result.add(map(sourceObject, targetClass));
      }
    }
    return result;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy