Advertisement
Lauda

WebShop init()

Jun 27th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 24.01 KB | None | 0 0
  1. package DB;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.FileOutputStream;
  5. import java.io.ObjectInputStream;
  6. import java.io.ObjectOutputStream;
  7. import java.io.Serializable;
  8. import java.text.SimpleDateFormat;
  9. import java.util.ArrayList;
  10. import java.util.Arrays;
  11. import java.util.Collections;
  12. import java.util.Comparator;
  13. import java.util.Iterator;
  14. import java.util.LinkedHashMap;
  15. import java.util.LinkedList;
  16. import java.util.List;
  17. import java.util.Map;
  18.  
  19. import model.Bill;
  20. import model.Category;
  21. import model.Component;
  22. import model.Device;
  23. import model.User;
  24. import model.UserRole;
  25. import model.UserRole.Role;
  26.  
  27. public class WebShop implements Serializable {
  28.  
  29.     /**
  30.      *
  31.      */
  32.     private static final long serialVersionUID = 2290297723029097273L;
  33.    
  34.     private static WebShop instance = null;
  35.     public static String filename = "webshop.txt";
  36.    
  37.     private LinkedHashMap<String, User> users;
  38.     private LinkedHashMap<String, Category> categories;
  39.     private LinkedHashMap<String, Component> components;
  40.     private LinkedHashMap<String, Device> devices;
  41.     private LinkedHashMap<Integer, Bill> bills;
  42.    
  43.     public LinkedHashMap<String, User> getUsers() {
  44.         return users;
  45.     }
  46.     public LinkedHashMap<String, Category> getCategories() {
  47.         return categories;
  48.     }
  49.     public LinkedHashMap<String, Component> getComponents() {
  50.         return components;
  51.     }
  52.     public LinkedHashMap<String, Device> getDevices() {
  53.         return devices;
  54.     }
  55.     public LinkedHashMap<Integer, Bill> getBills() {
  56.         return bills;
  57.     }
  58.    
  59.     public void addUser(User u)
  60.     {
  61.         System.out.println("[Debug]Adding user: " + u.getUsername());
  62.         users.put(u.getUsername(), u);
  63.        
  64.     }
  65.    
  66.     protected WebShop()
  67.     {
  68.         users = new LinkedHashMap<String, User>();
  69.         categories = new LinkedHashMap<String, Category>();
  70.         components = new LinkedHashMap<String, Component>();
  71.         devices = new LinkedHashMap<String, Device>();
  72.         bills = new LinkedHashMap<Integer, Bill>();
  73.     }
  74.    
  75.     public static WebShop getInstance()
  76.     {
  77.         if (instance == null)
  78.         {
  79.             WebShop ws = fetchData();
  80.            
  81.             if (ws != null)
  82.                 instance = ws;
  83.             else
  84.             {
  85.                 instance = new WebShop();
  86.                 instance.generateData();
  87.             }
  88.         }
  89.        
  90.         return instance;
  91.     }
  92.    
  93.     public Boolean saveData()
  94.     {
  95.         if (instance != null)
  96.         {
  97.             try {
  98.                 FileOutputStream fos = new FileOutputStream(WebShop.filename);
  99.                 ObjectOutputStream oos = new ObjectOutputStream(fos);
  100.                 oos.writeObject(instance);
  101.                 oos.close();
  102.                 System.out.println("Saving data...should be true now :P");
  103.                
  104.                 return true;
  105.             } catch (Exception ex)
  106.             {
  107.                 ex.printStackTrace();
  108.             }
  109.         }
  110.         System.out.println("Something derped...:(");
  111.         return false;
  112.     }
  113.    
  114.     public void destroyData()
  115.     {
  116.         users = new LinkedHashMap<String, User>();
  117.         categories = new LinkedHashMap<String, Category>();
  118.         components = new LinkedHashMap<String, Component>();
  119.         devices = new LinkedHashMap<String, Device>();
  120.         bills = new LinkedHashMap<Integer, Bill>();
  121.        
  122.         generateData();
  123.     }
  124.    
  125.     private static WebShop fetchData()
  126.     {
  127.         WebShop ws = null;
  128.        
  129.         try {
  130.             FileInputStream fis = new FileInputStream(WebShop.filename);
  131.             ObjectInputStream ois = new ObjectInputStream(fis);
  132.             ws = (WebShop)ois.readObject();
  133.             ois.close();
  134.            
  135.             // Let's assume everything went well even tho it didn't XD
  136.             System.out.println("Got the dataZ: " + ws);
  137.         } catch (Exception ex)
  138.         {
  139.             ex.printStackTrace();
  140.         }
  141.        
  142.         return ws;
  143.     }
  144.    
  145.     private void generateData()
  146.     {
  147.         // BRUTE-FORCE
  148.        
  149.         // User - Normal:
  150.         User testUser = new User("test", "test", "Testko", "Testic", new UserRole(Role.USER), "+381000000", "[email protected]");
  151.        
  152.         // User - Moderator:
  153.         User testUser2 = new User("test2", "test", "Testko #2", "Testic #2", new UserRole(Role.MODERATOR), "+381000001", "[email protected]");
  154.        
  155.         // User - Admin (RELEASE TEH POWER!)
  156.         User adminUser = new User("test3", "test3", "Testko #3", "Testic #3", new UserRole(Role.ADMIN), "+381000002", "[email protected]");
  157.        
  158.         users.put(testUser.getKey(), testUser);
  159.         users.put(testUser2.getKey(), testUser2);
  160.         users.put(adminUser.getKey(), adminUser);
  161.        
  162.         // CATEGORY
  163.        
  164.         // Motherboard:
  165.         Category mb = new Category("Matične ploče", "Opis matičnih ploča", null);
  166.        
  167.         // CPU
  168.         Category cpu = new Category("Procesori", "Opis procesora", null);
  169.        
  170.         // GPU
  171.         Category gpu = new Category("Grafičke kartice", "GPU - opis grafičkih kartica", null);
  172.        
  173.         // HDD
  174.         Category hdd = new Category("Hard diskovi", "Hard Diskovi, Solid-State Diskovi, Interni diskovi", null);
  175.         Category hdd1 = new Category("Interni Hard Diskovi", "Opis internih hard diskova", hdd);
  176.         Category hdd2 = new Category("Solid-State Diskovi (SSD)", "Opis SSD-ova", hdd);
  177.        
  178.         // RAM
  179.         Category ram = new Category("RAM", "Opis RAM-a", null);
  180.         Category ram1 = new Category("DDR RAM", "Opis DDR RAM-a", ram);
  181.         Category ram2 = new Category("DDR2 RAM", "Opis DDR2 RAM-a", ram1);
  182.         Category ram3 = new Category("DDR3 RAM", "Opis DDR3 RAM-a", ram1);
  183.         Category ram4 = new Category("SO-DIMM DDR", "Opis...", ram);
  184.         Category ram5 = new Category("SO-DIM DDR2", "Opis...", ram4);
  185.         Category ram6 = new Category("SO-DIM DDR3", "Opis...", ram4);
  186.        
  187.         // Coolers
  188.         Category cooler = new Category("Cooler", "Cooleri za racunare...", null);
  189.         Category cooler1 = new Category("CPU cooler", "Cooler za procesor", cooler);
  190.         Category cooler2 = new Category("GPU cooler", "Cooler za graficke kartice", cooler);
  191.         Category cooler3 = new Category("HDD cooler", "Cooler za hard diskove", cooler);
  192.         Category cooler4 = new Category("RAM cooler", "Cooler za RAM memoriju", cooler);
  193.        
  194.         // Case
  195.         Category cases = new Category("Kućišta", "Šta reći? Koju posluku porati? Kome??", null);
  196.        
  197.         // Add:
  198.         categories.put(mb.getKey(), mb);
  199.         categories.put(cpu.getKey(), cpu);
  200.         categories.put(gpu.getKey(), gpu);
  201.         categories.put(hdd.getKey(), hdd);
  202.         categories.put(hdd1.getKey(), hdd1);
  203.         categories.put(hdd2.getKey(), hdd2);
  204.         categories.put(ram.getKey(), ram);
  205.         categories.put(ram1.getKey(), ram1);
  206.         categories.put(ram2.getKey(), ram2);
  207.         categories.put(ram3.getKey(), ram3);
  208.         categories.put(ram4.getKey(), ram4);
  209.         categories.put(ram5.getKey(), ram5);
  210.         categories.put(ram6.getKey(), ram6);
  211.         categories.put(cooler.getKey(), cooler);
  212.         categories.put(cooler1.getKey(), cooler1);
  213.         categories.put(cooler2.getKey(), cooler2);
  214.         categories.put(cooler3.getKey(), cooler3);
  215.         categories.put(cases.getKey(), cases);
  216.        
  217.         // COMPONENT
  218.        
  219.         // Motherboard
  220.         Component mb_x1 = new Component("Asus M5A97 R2.0", "Matična ploča 'MB AM3+ 970 Asus M5A97 R2.0, PCIe/DDR3/SATA3/GLAN/RAID/7.1/USB3<br />Idealna ploca za Vas novi FX procesor.", 8699.00, 10, mb, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/maticne-ploce/maticna-ploca-mb-am3-970-asus-m5a97-r2-0-pcie-ddr3-sata3-glan-raid-7-1-usb3-1155200.html", "mb_asus_M5A97.jpg");
  221.         Component mb_x2 = new Component("ASRock Fatal1ty Z87 Professional", "Matična ploča 'MB LGA1150 Z87 ASRock Fatal1ty Z87 Professional, PCIe/DDR3/SATA3/GLAN/7.1", 23999.00, 5, mb, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/maticne-ploce/maticna-ploca-mb-lga1150-z87-asrock-fatal1ty-z87-professional-pcie-ddr3-sata3-glan-7-1-1191504.html", "mb_asrock_fatality.jpg");
  222.         Component mb_x3 = new Component("Gigabyte GA-970A-DS3P", "Matična ploča 'MB AM3+ 970 Gigabyte GA-970A-DS3P, PCIe/DDR3/SATA3/GLAN/7.1", 7699.00, 18, mb, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/maticne-ploce/maticna-ploca-mb-am3-970-gigabyte-ga-970a-ds3p-pcie-ddr3-sata3-glan-7-1-1179238.html", "mb_gigabyte_ga970a.jpg");
  223.         Component mb_x4 = new Component("MSI B85M-E43 DASH", "Matična ploča 'MB LGA1150 B85 MSI B85M-E43 DASH, PCIe/DDR3/SATA3/GLAN/7.1", 8899.00, 7, mb, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/maticne-ploce/maticna-ploca-mb-lga1150-b85-msi-b85m-e43-dash-pcie-ddr3-sata3-glan-7-1-1188841.html", "mb_msi_b85mdash.jpg");
  224.    
  225.         // CPU
  226.         Component cpu_x1 = new Component("AMD A4-4000", "Procesor 'APU FM2 AMD A4-4000, 3.0GHz/ Radeon™ HD 7480D", 4299.00, 9, cpu, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/procesori/procesor-apu-fm2-amd-a4-4000-3-0ghz-radeontm-hd-7480d-1171972.html", "amd_cpu.jpg");
  227.         Component cpu_x2 = new Component("AMD A10-7700K", "Procesor 'APU FM2+ AMD A10-7700K, 3.4GHz/ Radeon™ R7 Series", 15999.00, 11, cpu, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/procesori/procesor-apu-fm2-amd-a10-7700k-3-4ghz-radeontm-r7-series-1186212.html", "amd_cpu_2.jpg");
  228.         Component cpu_x3 = new Component("AMD FX-9590", "Procesor CPU AM3+ AMD FX-9590, 4.7GHz Black Edition 32nm", 32999.00, 0, cpu, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/procesori/procesor-cpu-am3-amd-fx-9590-4-7ghz-black-edition-32nm-1175043.html", "amd_cpu_3.jpg");
  229.         Component cpu_x4 = new Component("Intel Core i5-4460", "Procesori Intel CPU LGA1150 Intel® Core™ i5-4460, 3.2GHz BOX 22nm", 21999.00, 21, cpu, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/procesori/procesori-intel-cpu-lga1150-intelr-coretm-i5-4460-3-2ghz-box-22nm-1193133.html", "intel_cpu_1.jpg");
  230.         Component cpu_x5 = new Component("Intel Core i7-4790", "Procesori Intel CPU LGA1150 Intel® Core™ i7-4790, 3.60GHz BOX 22nm", 33799.00, 7, cpu, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/procesori/procesori-intel-cpu-lga1150-intelr-coretm-i7-4790-3-60ghz-box-22nm-1191915.html", "intel_cpu_2.jpg");
  231.         Component cpu_x6 = new Component("Intel Core i7-4930K", "Procesori Intel CPU LGA2011 Intel® Core™ i7-4930K, 3.40GHz BOX 22nm", 61990.00, 12, cpu, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/procesori/procesori-intel-cpu-lga2011-intelr-coretm-i7-4930k-3-40ghz-box-22nm-1181257.html", "intel_cpu_3.jpg");
  232.        
  233.         // GPU
  234.         Component gpu_x1 = new Component("AMD Radeon R5 230", "Grafička kartica AMD Radeon R5 230 ASUS 1GB GDDR3, DVI/HDMI/64bit/R5230-SL-1GD3-L", 5199.00, 2, gpu, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/graficke-kartice/graficka-kartica-amd-radeon-r5-230-asus-1gb-gddr3-dvi-hdmi-64bit-r5230-sl-1gd3-l-1193256.html", "amd_gpu_1.jpg");
  235.         Component gpu_x2 = new Component("AMD Radeon R9 290", "Grafička kartica AMD Radeon R9 290 ASUS 4GB GDDR5, DVI/HDMI/DP/R9290-4GD5", 46999.00, 6, gpu, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/graficke-kartice/graficka-kartica-amd-radeon-r9-290-asus-4gb-gddr5-dvi-hdmi-dp-r9290-4gd5-1182631.html", "amd_gpu_2.jpg");
  236.         Component gpu_x3 = new Component("GeForce GTX780-Ti ASUS", "Grafička kartica GeForce GTX780-Ti ASUS OC 3GB DDR5, HDMI/DVI/DP/384bit/MATRIX-GTX780TI-P-3GD5", 89999.00, 7, gpu, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/graficke-kartice/graficka-kartica-geforce-gtx780-ti-asus-oc-3gb-ddr5-hdmi-dvi-dp-384bit-matrix-gtx780ti-p-3gd5-1193035.html", "amd_gpu_3.jpg");
  237.         Component gpu_x4 = new Component("GeForce GTX780-Ti Gigabyte", "Grafička kartica GeForce GTX780-Ti Gigabyte OC 3GB DDR5, HDMI/DVI/DP/384bit/GV-N78TOC-3GD", 79999.00, 1, gpu, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/graficke-kartice/graficka-kartica-geforce-gtx780-ti-gigabyte-oc-3gb-ddr5-hdmi-dvi-dp-384bit-gv-n78toc-3gd-1186161.html", "amd_gpu_4.jpg");
  238.    
  239.         // HDD
  240.         Component hdd_x1 = new Component("500GB Toshiba", "Hard disk 'HDD SATA2 2.5\" 5400 500GB Toshiba MQ Series, PX1826E-1HE0, 8MB 2 godine,Retail", 6399.00, 11, hdd, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/hdd-ssd-i-oprema/interni-hard-diskovi/hard-disk-hdd-sata2-2-5-5400-500gb-toshiba-mq-series-px1826e-1he0-8mb-2-godine-retail-1191561.html", "hdd_2.jgp");
  241.         Component hdd_x2 = new Component("1TB Toshiba", "Hard disk 'HDD SATA2 2.5\" 5400 1TB Toshiba MQ Series PX1829E-1HJ0,8MB 2 godine,Retail Pack", 8899.00, 40, hdd1, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/hdd-ssd-i-oprema/interni-hard-diskovi/hard-disk-hdd-sata2-2-5-5400-1tb-toshiba-mq-series-px1829e-1hj0-8mb-2-godine-retail-pack-1191565.html", "hdd_1.jpg");
  242.         Component hdd_x3 = new Component("Kingston mS200", "SSD mSATA3 120GB Kingston mS200 550/520MB/s, SMS200S3/120G", 11499.00, 10, hdd2, "http://www.winwin.rs/ssd-msata3-120gb-kingston-ms200-550-520mb-s-sms200s3-120g-1177229.html", "ssd_1.jpg");
  243.         Component hdd_x4 = new Component("Kingston E100", "SSD SATA3 100GB Kingston E100 535/500MB/s, SE100S37/100G",49999.00, 9, hdd2, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/hdd-ssd-i-oprema/ssd-diskovi/ssd-sata3-100gb-kingston-e100-535-500mb-s-se100s37-100g-1187164.html", "ssd_2.jpg");
  244.        
  245.         // RAM
  246.         Component ram_x1 = new Component("Genesis KHX1600", "Memorija 12GB 1600MHz DDR3 Non-ECC CL9 DIMM (Kit of 3) XMP,KHX1600C9D3K3/12GX", 17999.00, 5, ram, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/ram-memorije/memorija-12gb-1600mhz-ddr3-non-ecc-cl9-dimm-kit-of-3-xmp-khx1600c9d3k3-12gx-1187194.html", "ram_1.jpg");
  247.         Component ram_x2 = new Component("Corsair VS1GB400C3", "Memorija DIMM DDR 1GB 400MHz Corsair CL3, VS1GB400C3", 3499.00, 11, ram1, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/ram-memorije/memorija-memorija-dimm-ddr-1gb-400mhz-corsair-cl3-vs1gb400c3-1193321.html", "ram_2.jpg");
  248.         Component ram_x3 = new Component("TRANSCEND JM388D643A-5L-B", "Memorija DIMM DDR 1GB 400MHz TRANSCEND CL3, JM388D643A-5L-B", 3699.00, 13, ram1, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/ram-memorije/memorija-memorija-dimm-ddr-1gb-400mhz-transcend-cl3-jm388d643a-5l-b-1155059.html", "ram_3.jpg");
  249.         Component ram_x4 = new Component("Crucial CT12864AA800", "Memorija DIMM DDR2 1GB 800MHz Crucial CL6, CT12864AA800", 2199.00, 6, ram2, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/ram-memorije/memorija-dimm-ddr2-1gb-800mhz-crucial-cl6-ct12864aa800-1193322.html", "ram_4.jpg");
  250.         Component ram_x5 = new Component("Kingston D25664G60", "Memorija DIMM DDR2 2GB 800MHz Kingston CL6, D25664G60", 4499.00, 22, ram2, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/ram-memorije/memorija-dimm-ddr2-2gb-800mhz-kingston-cl6-d25664g60-1185692.html", "ram_5.jpg");
  251.         Component ram_x6 = new Component("Kingston HyperX KHX16C10P1K2/16", "Memorija 16GB 1600MHz DDR3 Non-ECC CL10 DIMM (Kit of 2) HyperX, KHX16C10P1K2/16", 22445.00, 7, ram3, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/ram-memorije/memorija-16gb-1600mhz-ddr3-non-ecc-cl10-dimm-kit-of-2-hyperx-khx16c10p1k2-16-1187237.html", "ram_6.jgp");
  252.         Component ram_x7 = new Component("Kingston KHX18C10AT3K2/16X", "Memorija 16GB 1866MHz DDR3 Non-ECC CL10 (Kit of 2) XMP Beast,KHX18C10AT3K2/16X", 23091.00, 4, ram3, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/ram-memorije/memorija-16gb-1866mhz-ddr3-non-ecc-cl10-kit-of-2-xmp-beast-khx18c10at3k2-16x-1187253.html", "ram_7.jpg");
  253.         Component ram_x8 = new Component("Transcend TS128MSD64V4A", "Memorija SODIMM DDR 1GB 400MHz Transcend CL3,TS128MSD64V4A", 4299.00, 0, ram4, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/ram-memorije/memorija-sodimm-ddr-1gb-400mhz-transcend-cl3-ts128msd64v4a-1152726.html", "ram_8.jpg");
  254.         Component ram_x9 = new Component("Transcend TS64MSD64V4J", "Memorija SODIMM DDR 512MB DRAM 400MHz Transcend CL3, TS64MSD64V4J", 2399.00, 2, ram4, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/ram-memorije/memorija-sodimm-ddr-512mb-dram-400mhz-transcend-cl3-ts64msd64v4j-1145916.html", "ram_9.jpg");
  255.         Component ram_x10 = new Component("Transcend JM800QSU-2G", "Memorija SODIMM DDR2 2GB 800MHz Transcend, JM800QSU-2G", 3699.00, 3, ram5, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/ram-memorije/memorija-sodimm-ddr2-2gb-800mhz-transcend-jm800qsu-2g-1181897.html", "ram_10.jpg");
  256.         Component ram_x11 = new Component("Kingston KVR13S9K2/16", "Memorija 16GB 1333MHz DDR3 Non-ECC CL9 SODIMM (Kit of 2),KVR13S9K2/16", 20707.00, 5, ram6, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/ram-memorije/memorija-16gb-1333mhz-ddr3-non-ecc-cl9-sodimm-kit-of-2-kvr13s9k2-16-1187220.html", "ram_11.jpg");
  257.         Component ram_x12 = new Component("Silicon Power SP002GBSTU133V02", "Memorija SODIMM DDR3 2GB 1333MHz Silicon Power, SP002GBSTU133V02", 2299.00, 14, ram6, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/ram-memorije/memorija-sodimm-ddr3-2gb-1333mhz-silicon-power-sp002gbstu133v02-1191652.html", "ram_12.jpg");
  258.        
  259.         // Coolers
  260.         Component cl_x1 = new Component("Noctua NH-L9a", "CPU Hladnjak AM3+/FM2+ Noctua NH-L9a, 92mm fan", 4499.00, 22, cooler, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/hladnjaci-ventilatori-i-oprema/cpu-hladnjak-am3-fm2-noctua-nh-l9a-92mm-fan-1180855.html", "cooler_1.jpg");
  261.         Component cl_x2 = new Component("Corsair H110", "CPU Hladnjak 775/1155/1150/2011/AM3+/FM2+ Corsair Cooling Hydro Series H110", 15999.00, 11, cooler1, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/hladnjaci-ventilatori-i-oprema/cpu-hladnjak-775-1155-1150-2011-am3-fm2-corsair-cooling-hydro-series-h110-1171943.html", "cooler_2.jpg");
  262.         Component cl_x3 = new Component("Accelero L2", "Hladnjak VGA Arctic Accelero L2 Plus", 1999.00, 33, cooler2, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/hladnjaci-ventilatori-i-oprema/hladnjak-vga-arctic-accelero-l2-plus-1151314.html", "cooler_3.jpg");
  263.         Component cl_x4 = new Component("Revoltec RS045", "HDD Hladnjak Revoltec RS045", 750.00, 17, cooler3, "http://www.winwin.rs/hdd-hladnjak-revoltec-rs045-1155773.html", "cooler_4.jpg");
  264.         Component cl_x5 = new Component("KHX-FAN", "Hladnjak za memoriju KHX-FAN", 2650.00, 9, cooler4, "http://www.winwin.rs/hladnjak-za-memoriju-khx-fan-1189175.html", "cooler_5.jpg");
  265.    
  266.         // Cases
  267.         Component case_x1 = new Component("Raidmax Phantom", "Kućište Raidmax Phantom, Black", 5499.00, 11, cases, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/kucista/kuciste-raidmax-phantom-black-1176960.html", "case_1.jpg");
  268.         Component case_x2 = new Component("Thermaltake Urban S71", "Kućište Thermaltake Urban S71 Black full tower, No Window/SECC", 12399.00, 4, cases, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/kucista/kuciste-thermaltake-urban-s71-black-full-tower-no-window-secc-1190653.html", "case_2.jpg");
  269.         Component case_x3 = new Component("CoolerMaster HAF X", "Kuciste Big Tower Cooler Master HAF X, RC-942-KKN1", 19499.00, 8, cases, "http://www.winwin.rs/racunari-i-komponente/racunarske-komponente/kucista/kuciste-big-tower-cooler-master-haf-x-rc-942-kkn1-1131599.html", "case_3.jpg");
  270.         Component case_x4 = new Component("Thermaltake Overseer RX-I", "Kućište Thermaltake Overseer RX-I, HDDock/20cmLEDfan/window/black/USB 3.0", 12499.00, 10, cases, "http://www.winwin.rs/kuciste-thermaltake-overseer-rx-i-hddock-20cmledfan-window-black-usb-3-0-1142516.html", "case_4.jpg");
  271.        
  272.         // EMAHGERD PERFERMENCE INIT:
  273.         components.put(mb_x1.getKey(), mb_x1);
  274.         components.put(mb_x2.getKey(), mb_x2);
  275.         components.put(mb_x3.getKey(), mb_x3);
  276.         components.put(mb_x4.getKey(), mb_x4);
  277.        
  278.         components.put(cpu_x1.getKey(), cpu_x1);
  279.         components.put(cpu_x2.getKey(), cpu_x2);
  280.         components.put(cpu_x3.getKey(), cpu_x3);
  281.         components.put(cpu_x4.getKey(), cpu_x4);
  282.         components.put(cpu_x5.getKey(), cpu_x5);
  283.         components.put(cpu_x6.getKey(), cpu_x6);
  284.        
  285.         components.put(gpu_x1.getKey(), gpu_x1);
  286.         components.put(gpu_x2.getKey(), gpu_x2);
  287.         components.put(gpu_x3.getKey(), gpu_x3);
  288.         components.put(gpu_x4.getKey(), gpu_x4);
  289.        
  290.         components.put(hdd_x1.getKey(), hdd_x1);
  291.         components.put(hdd_x2.getKey(), hdd_x2);
  292.         components.put(hdd_x3.getKey(), hdd_x3);
  293.         components.put(hdd_x4.getKey(), hdd_x4);
  294.        
  295.         components.put(ram_x1.getKey(), ram_x1);
  296.         components.put(ram_x2.getKey(), ram_x2);
  297.         components.put(ram_x3.getKey(), ram_x3);
  298.         components.put(ram_x4.getKey(), ram_x4);
  299.         components.put(ram_x5.getKey(), ram_x5);
  300.         components.put(ram_x6.getKey(), ram_x6);
  301.         components.put(ram_x7.getKey(), ram_x7);
  302.         components.put(ram_x8.getKey(), ram_x8);
  303.         components.put(ram_x9.getKey(), ram_x9);
  304.         components.put(ram_x10.getKey(), ram_x10);
  305.         components.put(ram_x11.getKey(), ram_x11);
  306.         components.put(ram_x12.getKey(), ram_x12);
  307.        
  308.         components.put(cl_x1.getKey(), cl_x1);
  309.         components.put(cl_x2.getKey(), cl_x2);
  310.         components.put(cl_x3.getKey(), cl_x3);
  311.         components.put(cl_x4.getKey(), cl_x4);
  312.         components.put(cl_x5.getKey(), cl_x5);
  313.        
  314.         components.put(case_x1.getKey(), case_x1);
  315.         components.put(case_x2.getKey(), case_x2);
  316.         components.put(case_x3.getKey(), case_x3);
  317.         components.put(case_x4.getKey(), case_x4);
  318.        
  319.         // DEVICE
  320.         Device d1 = new Device("SCARFACE", "Extremlly powerful PC so you could enjoy playing Solitaire!");
  321.         d1.addComponents(new ArrayList<Component>(Arrays.asList(mb_x1, cpu_x4, hdd_x4, ram_x7, gpu_x4, case_x4)));
  322.        
  323.         Device d2 = new Device("KATAKLIZMA", "Šta je za reći...rastura Ping-Pong 3D samo tako!");
  324.         d2.addComponents(new ArrayList<Component>(Arrays.asList(mb_x2, cpu_x3, hdd_x2, ram_x4, gpu_x3, case_x2)));
  325.        
  326.         Device d3 = new Device("VRISAK", "Od njegove snage počećete da vrištite, doslovno!");
  327.         d3.addComponents(new ArrayList<Component>(Arrays.asList(mb_x4, cpu_x6, hdd_x4, ram_x8, gpu_x4, case_x3)));
  328.        
  329.         devices.put(d1.getKey(), d1);
  330.         devices.put(d2.getKey(), d2);
  331.         devices.put(d3.getKey(), d3);
  332.        
  333.         // meh
  334.        
  335.         SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH");
  336.        
  337.         try {
  338.             // 1
  339.             Bill bill_d = new Bill(20d, sdf.parse("27-06-2014 16"), testUser);
  340.             bill_d.getItems().put(d1, 3);
  341.             bill_d.setTotalPrice(d1.getPrice() * 3);
  342.             bill_d.setId(1); // First!
  343.             bills.put(bill_d.getId(), bill_d);
  344.            
  345.             // 2
  346.             bill_d = new Bill(20d, sdf.parse("25-06-2014 12"), testUser);
  347.             bill_d.getItems().put(d1, 1);
  348.             bill_d.getItems().put(d2, 1);
  349.             bill_d.setTotalPrice(d1.getPrice() + d2.getPrice());
  350.             bill_d.setId(2);
  351.             bills.put(bill_d.getId(), bill_d);
  352.            
  353.             // 3
  354.             bill_d = new Bill(20d, sdf.parse("20-06-2014 15"), testUser);
  355.             bill_d.getItems().put(d3, 7);
  356.             bill_d.setTotalPrice(d3.getPrice() * 7);
  357.             bill_d.setId(3);
  358.             bills.put(bill_d.getId(), bill_d);
  359.            
  360.             // 4
  361.             bill_d = new Bill(20d, sdf.parse("10.06.2014 11"), testUser2);
  362.             bill_d.getItems().put(cpu_x1, 3);
  363.             bill_d.getItems().put(ram_x4, 2);
  364.             bill_d.getItems().put(gpu_x3, 1);
  365.             bill_d.setTotalPrice(cpu_x1.getPrice() * 3 + ram_x4.getPrice() * 2 + gpu_x3.getPrice());
  366.             bill_d.setId(4);
  367.             bills.put(bill_d.getId(), bill_d);
  368.            
  369.             // 5
  370.             bill_d = new Bill(20d, sdf.parse("05.05.2014 11"), testUser2);
  371.             bill_d.getItems().put(cpu_x3, 1);
  372.             bill_d.getItems().put(ram_x5, 4);
  373.             bill_d.getItems().put(gpu_x4, 2);
  374.             bill_d.setTotalPrice(cpu_x3.getPrice() + ram_x5.getPrice() * 4 + gpu_x4.getPrice() * 2);
  375.             bill_d.setId(5);
  376.             bills.put(bill_d.getId(), bill_d);
  377.            
  378.             // 5
  379.             bill_d = new Bill(20d, sdf.parse("01.05.2014 08"), testUser2);
  380.             bill_d.getItems().put(cpu_x4, 2);
  381.             bill_d.getItems().put(ram_x6, 4);
  382.             bill_d.getItems().put(gpu_x4, 2);
  383.             bill_d.getItems().put(cl_x3, 3);
  384.             bill_d.getItems().put(case_x3, 1);
  385.             bill_d.setTotalPrice(cpu_x4.getPrice() * 2 + ram_x6.getPrice() * 4 + gpu_x4.getPrice() * 2 + cl_x3.getPrice() * 3 + case_x3.getPrice());
  386.             bill_d.setId(6);
  387.             bills.put(bill_d.getId(), bill_d);
  388.            
  389.         } catch (java.text.ParseException e) {
  390.             // TODO Auto-generated catch block
  391.             e.printStackTrace();
  392.         }
  393.        
  394.         collectionSort(); // Sort stuff
  395.     }
  396.    
  397.     @SuppressWarnings("unchecked")
  398.     public void collectionSort()
  399.     {
  400.         users = sort(users);
  401.         categories = sort(categories);
  402.         components = sort(components);
  403.         devices = sort(devices);
  404.         bills = sort(bills);
  405.     }
  406.    
  407.     @SuppressWarnings({ "rawtypes", "unchecked" })
  408.     private LinkedHashMap sort(LinkedHashMap map)
  409.     {
  410.         List list = new LinkedList(map.entrySet());
  411.        
  412.         Collections.sort(list, new Comparator() {
  413.             public int compare(Object obj1, Object obj2)
  414.             {
  415.                 return ((Comparable)((Map.Entry)(obj1)).getKey()).compareTo(((Map.Entry) (obj2)).getKey());
  416.             }
  417.         });
  418.        
  419.         LinkedHashMap sorted = new LinkedHashMap();
  420.         for (Iterator itr = list.iterator(); itr.hasNext();)
  421.         {
  422.             Map.Entry entry = (Map.Entry)itr.next();
  423.             sorted.put(entry.getKey(), entry.getValue());
  424.         }
  425.         return sorted;
  426.     }
  427.  
  428. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement