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

com.transferwise.tasks.utils.DomainUtils Maven / Gradle / Ivy

The newest version!
package com.transferwise.tasks.utils;

import com.transferwise.tasks.dao.ITaskDao;
import com.transferwise.tasks.domain.BaseTask;

/**
 * Only allows conversion from wider type to narrower type, as there should be no data loss.
 */
public final class DomainUtils {

  private DomainUtils() {
    throw new AssertionError();
  }

  @SuppressWarnings("unchecked")
  public static  T convert(ITaskDao.StuckTask task, Class resultClass) {
    if (task == null) {
      return null;
    }

    if (resultClass.equals(BaseTask.class)) {
      return (T) new BaseTask()
          .setId(task.getVersionId().getId())
          .setPriority(task.getPriority())
          .setType(task.getType())
          .setVersion(task.getVersionId().getVersion());
    }
    throw new IllegalArgumentException("No conversion is supprorted from " + resultClass.getCanonicalName() + ".");
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy