com.transferwise.tasks.utils.DomainUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tw-tasks-core Show documentation
Show all versions of tw-tasks-core Show documentation
Transferwise Tasks Executor - Fire and forget until Alert.
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() + ".");
}
}