Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class AllergyRegister {
  2.  
  3.     private static AllergyRegister instance;
  4.     private Map<Integer, Allergy> allergies;
  5.  
  6.     public static AllergyRegister getInstance(){
  7.         if(instance == null)
  8.             instance = new AllergyRegister();
  9.         return instance;
  10.     }
  11.  
  12.     private AllergyRegister(){
  13.         this.allergies = new TreeMap<>();
  14.     }
  15.  
  16.     public void Register(Allergy allergy){
  17.         this.allergies.put(allergy.getId(), allergy);
  18.     }
  19.  
  20.     public Allergy getByProductAllergyID(int prodAllergyID){
  21.         for(Allergy allergy : allergies)
  22.             if(allergy.getProductAllergyID() == prodAllergyID)
  23.                 return allergy;
  24.         return null;
  25.     }
  26.  
  27.     public Map<Integer, Allergy> getAllAllergies(){
  28.         return  this.allergies;
  29.     }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement