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

tech.deepdreams.worker.util.FamilyAllowanceRateExtrator Maven / Gradle / Ivy

There is a newer version: 0.1.2-RELEASE
Show newest version
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) ;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy