tech.deepdreams.worker.util.FamilyAllowanceRateExtrator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of worker-cmr-impl Show documentation
Show all versions of worker-cmr-impl Show documentation
Payroll Worker CMR Impl project for Java 17
package tech.deepdreams.worker.util;
import java.io.File;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
public class FamilyAllowanceRateExtrator {
private static Map cachedValues = new HashMap() ;
public static Float fetchRate (Long branchId) throws JAXBException {
if(! cachedValues.containsKey(branchId)) {
JAXBContext context = JAXBContext.newInstance(Branches.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
String fs = System.getProperty("file.separator") ;
URL resource = FamilyAllowanceRateExtrator.class.getClassLoader().getResource("data/family-allowance-rates-1973.xml");
Branches persons = (Branches) unmarshaller.unmarshal(new File(resource.getFile())) ;
Float rate = persons.getBranches().stream()
.filter(branch -> {
return branch.getId().equals(branchId) ;
})
.map(Branch::getRate)
.findFirst()
.orElse(null) ;
cachedValues.put(branchId, rate) ;
}
return cachedValues.get(branchId) ;
}
}