Advertisement
LoganBlackisle

hashmap inside hashmap

Oct 17th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. package model;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map.Entry;
  5.  
  6. public class MainApp {
  7.     static ProductGroup bottle = new ProductGroup("Bottle", Unit.CL);
  8.     static ProductGroup glass = new ProductGroup("Glass", Unit.GLASS);
  9.     static Product product = new Product("name", 69, bottle);
  10.     static Price price = new Price(product, 96);
  11.     static SalesSituation bar = new SalesSituation("Bar");
  12.     static SalesSituation store = new SalesSituation("Store");
  13.    
  14.     public static void main(String[] args) {
  15.         HashMap<String, Integer> inner = new HashMap<>();
  16.         HashMap<String, HashMap<String, Integer>> map = new HashMap<>();
  17.  
  18.         Product p1 = new Product("Georgia Brown Ale", 60, bottle);
  19.         Product p2 = new Product("Easter Brew", 60, bottle);
  20.         Product p3 = new Product("Christmas Pale Ale", 60, glass);
  21.         Product p4 = new Product("Classic", 60, glass);
  22.         Product p5 = new Product("Newcastle", 60, glass);
  23.        
  24.         inner.put(bar.getName(), Price.getPrice());
  25.         inner.put(store.getName(), Price.getPrice());
  26.         map.put(p1.getName(), inner);
  27.         map.put(p2.getName(), inner);
  28.         map.put(p3.getName(), inner);
  29.         map.put(p4.getName(), inner);
  30.         map.put(p5.getName(), inner);
  31.  
  32.         for (Entry<String, HashMap<String, Integer>> m : map.entrySet()) {
  33.             System.out.println("Product: " + map.keySet() + " " + "SalesSituation: " + inner.keySet() + " " + "Price: " + inner.values());
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement