tech.deepdreams.worker.api.context.HourlySalaryContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of worker-api Show documentation
Show all versions of worker-api Show documentation
Payroll Worker API project for Java 17
package tech.deepdreams.worker.api.context;
import java.util.Map;
import java.util.ServiceLoader ;
import java.util.ServiceLoader.Provider;
import tech.deepdreams.worker.api.enums.CountryCode;
import tech.deepdreams.worker.api.exceptions.ServiceNotFoundException;
import tech.deepdreams.worker.api.services.HourlySalaryService;
public class HourlySalaryContext {
private HourlySalaryService hourlySalaryService ;
public HourlySalaryContext(CountryCode countryCode, String code, int version){
this.hourlySalaryService = ServiceLoader.load(HourlySalaryService.class)
.stream()
.map(Provider::get)
.filter(service -> service.country().equals(countryCode) && service.code().equals(code) && service.version() == version)
.findAny()
.orElseThrow(() -> new ServiceNotFoundException()) ;
}
public Double calculate(Map params) {
return hourlySalaryService.calculate(params) ;
}
}