Advertisement
kubpica

Komunikaty

Jun 3rd, 2018
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.util.Collection;
  2. import java.util.HashMap;
  3. import java.util.Map.Entry;
  4.  
  5. public class Komunikaty {
  6.     private static HashMap<Integer, HashMap<Integer, String>> komunikaty = new HashMap<>();
  7.     static {
  8.         komunikaty.put(0, new HashMap<>()); //polski
  9.         komunikaty.put(1, new HashMap<>()); //angielski
  10.     }
  11.    
  12.     public static void dodaj(int język, int id, String s) {
  13.         if(!komunikaty.containsKey(język))
  14.             komunikaty.put(język, new HashMap<>());
  15.         komunikaty.get(język).put(id, s);
  16.     }
  17.    
  18.     public static String tłumacz(String s, int językDocelowy) {
  19.         Collection<HashMap<Integer, String>> zestawyJęzykowe = komunikaty.values();
  20.         for(HashMap<Integer, String> zestaw : zestawyJęzykowe) {
  21.             for(Entry<Integer, String> komunikat : zestaw.entrySet()) {
  22.                 if(komunikat.getValue().equals(s)) {
  23.                     int idKomunikatu = komunikat.getKey();
  24.                     return komunikaty.get(językDocelowy).get(idKomunikatu);
  25.                 }
  26.             }
  27.         }
  28.        
  29.         return null;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement