Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DB;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.io.Serializable;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.Iterator;
- import java.util.LinkedHashMap;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Map;
- import model.Bill;
- import model.Category;
- import model.Component;
- import model.Device;
- import model.User;
- import model.UserRole;
- import model.UserRole.Role;
- public class WebShop implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = 2290297723029097273L;
- private static WebShop instance = null;
- public static String filename = "webshop.txt";
- private LinkedHashMap<String, User> users;
- private LinkedHashMap<String, Category> categories;
- private LinkedHashMap<String, Component> components;
- private LinkedHashMap<String, Device> devices;
- private LinkedHashMap<Integer, Bill> bills;
- public LinkedHashMap<String, User> getUsers() {
- return users;
- }
- public LinkedHashMap<String, Category> getCategories() {
- return categories;
- }
- public LinkedHashMap<String, Component> getComponents() {
- return components;
- }
- public LinkedHashMap<String, Device> getDevices() {
- return devices;
- }
- public LinkedHashMap<Integer, Bill> getBills() {
- return bills;
- }
- public void addUser(User u)
- {
- System.out.println("[Debug]Adding user: " + u.getUsername());
- users.put(u.getUsername(), u);
- }
- protected WebShop()
- {
- users = new LinkedHashMap<String, User>();
- categories = new LinkedHashMap<String, Category>();
- components = new LinkedHashMap<String, Component>();
- devices = new LinkedHashMap<String, Device>();
- bills = new LinkedHashMap<Integer, Bill>();
- }
- public static WebShop getInstance()
- {
- if (instance == null)
- {
- WebShop ws = fetchData();
- if (ws != null)
- instance = ws;
- else
- {
- instance = new WebShop();
- instance.generateData();
- }
- }
- return instance;
- }
- public Boolean saveData()
- {
- if (instance != null)
- {
- try {
- FileOutputStream fos = new FileOutputStream(WebShop.filename);
- ObjectOutputStream oos = new ObjectOutputStream(fos);
- oos.writeObject(instance);
- oos.close();
- System.out.println("Saving data...should be true now :P");
- return true;
- } catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
- System.out.println("Something derped...:(");
- return false;
- }
- public void destroyData()
- {
- users = new LinkedHashMap<String, User>();
- categories = new LinkedHashMap<String, Category>();
- components = new LinkedHashMap<String, Component>();
- devices = new LinkedHashMap<String, Device>();
- bills = new LinkedHashMap<Integer, Bill>();
- generateData();
- }
- private static WebShop fetchData()
- {
- WebShop ws = null;
- try {
- FileInputStream fis = new FileInputStream(WebShop.filename);
- ObjectInputStream ois = new ObjectInputStream(fis);
- ws = (WebShop)ois.readObject();
- ois.close();
- // Let's assume everything went well even tho it didn't XD
- System.out.println("Got the dataZ: " + ws);
- } catch (Exception ex)
- {
- ex.printStackTrace();
- }
- return ws;
- }
- private void generateData()
- {
- // BRUTE-FORCE
- // User - Normal:
- User testUser = new User("test", "test", "Testko", "Testic", new UserRole(Role.USER), "+381000000", "[email protected]");
- // User - Moderator:
- User testUser2 = new User("test2", "test", "Testko #2", "Testic #2", new UserRole(Role.MODERATOR), "+381000001", "[email protected]");
- // User - Admin (RELEASE TEH POWER!)
- User adminUser = new User("test3", "test3", "Testko #3", "Testic #3", new UserRole(Role.ADMIN), "+381000002", "[email protected]");
- users.put(testUser.getKey(), testUser);
- users.put(testUser2.getKey(), testUser2);
- users.put(adminUser.getKey(), adminUser);
- // CATEGORY
- // Motherboard:
- Category mb = new Category("Matične ploče", "Opis matičnih ploča", null);
- // CPU
- Category cpu = new Category("Procesori", "Opis procesora", null);
- // GPU
- Category gpu = new Category("Grafičke kartice", "GPU - opis grafičkih kartica", null);
- // HDD
- Category hdd = new Category("Hard diskovi", "Hard Diskovi, Solid-State Diskovi, Interni diskovi", null);
- Category hdd1 = new Category("Interni Hard Diskovi", "Opis internih hard diskova", hdd);
- Category hdd2 = new Category("Solid-State Diskovi (SSD)", "Opis SSD-ova", hdd);
- // RAM
- Category ram = new Category("RAM", "Opis RAM-a", null);
- Category ram1 = new Category("DDR RAM", "Opis DDR RAM-a", ram);
- Category ram2 = new Category("DDR2 RAM", "Opis DDR2 RAM-a", ram1);
- Category ram3 = new Category("DDR3 RAM", "Opis DDR3 RAM-a", ram1);
- Category ram4 = new Category("SO-DIMM DDR", "Opis...", ram);
- Category ram5 = new Category("SO-DIM DDR2", "Opis...", ram4);
- Category ram6 = new Category("SO-DIM DDR3", "Opis...", ram4);
- // Coolers
- Category cooler = new Category("Cooler", "Cooleri za racunare...", null);
- Category cooler1 = new Category("CPU cooler", "Cooler za procesor", cooler);
- Category cooler2 = new Category("GPU cooler", "Cooler za graficke kartice", cooler);
- Category cooler3 = new Category("HDD cooler", "Cooler za hard diskove", cooler);
- Category cooler4 = new Category("RAM cooler", "Cooler za RAM memoriju", cooler);
- // Case
- Category cases = new Category("Kućišta", "Šta reći? Koju posluku porati? Kome??", null);
- // Add:
- categories.put(mb.getKey(), mb);
- categories.put(cpu.getKey(), cpu);
- categories.put(gpu.getKey(), gpu);
- categories.put(hdd.getKey(), hdd);
- categories.put(hdd1.getKey(), hdd1);
- categories.put(hdd2.getKey(), hdd2);
- categories.put(ram.getKey(), ram);
- categories.put(ram1.getKey(), ram1);
- categories.put(ram2.getKey(), ram2);
- categories.put(ram3.getKey(), ram3);
- categories.put(ram4.getKey(), ram4);
- categories.put(ram5.getKey(), ram5);
- categories.put(ram6.getKey(), ram6);
- categories.put(cooler.getKey(), cooler);
- categories.put(cooler1.getKey(), cooler1);
- categories.put(cooler2.getKey(), cooler2);
- categories.put(cooler3.getKey(), cooler3);
- categories.put(cases.getKey(), cases);
- // COMPONENT
- // Motherboard
- 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");
- 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");
- 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");
- 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");
- // CPU
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- // GPU
- 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");
- 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");
- 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");
- 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");
- // HDD
- 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");
- 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");
- 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");
- 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");
- // RAM
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- // Coolers
- 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");
- 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");
- 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");
- 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");
- 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");
- // Cases
- 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");
- 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");
- 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");
- 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");
- // EMAHGERD PERFERMENCE INIT:
- components.put(mb_x1.getKey(), mb_x1);
- components.put(mb_x2.getKey(), mb_x2);
- components.put(mb_x3.getKey(), mb_x3);
- components.put(mb_x4.getKey(), mb_x4);
- components.put(cpu_x1.getKey(), cpu_x1);
- components.put(cpu_x2.getKey(), cpu_x2);
- components.put(cpu_x3.getKey(), cpu_x3);
- components.put(cpu_x4.getKey(), cpu_x4);
- components.put(cpu_x5.getKey(), cpu_x5);
- components.put(cpu_x6.getKey(), cpu_x6);
- components.put(gpu_x1.getKey(), gpu_x1);
- components.put(gpu_x2.getKey(), gpu_x2);
- components.put(gpu_x3.getKey(), gpu_x3);
- components.put(gpu_x4.getKey(), gpu_x4);
- components.put(hdd_x1.getKey(), hdd_x1);
- components.put(hdd_x2.getKey(), hdd_x2);
- components.put(hdd_x3.getKey(), hdd_x3);
- components.put(hdd_x4.getKey(), hdd_x4);
- components.put(ram_x1.getKey(), ram_x1);
- components.put(ram_x2.getKey(), ram_x2);
- components.put(ram_x3.getKey(), ram_x3);
- components.put(ram_x4.getKey(), ram_x4);
- components.put(ram_x5.getKey(), ram_x5);
- components.put(ram_x6.getKey(), ram_x6);
- components.put(ram_x7.getKey(), ram_x7);
- components.put(ram_x8.getKey(), ram_x8);
- components.put(ram_x9.getKey(), ram_x9);
- components.put(ram_x10.getKey(), ram_x10);
- components.put(ram_x11.getKey(), ram_x11);
- components.put(ram_x12.getKey(), ram_x12);
- components.put(cl_x1.getKey(), cl_x1);
- components.put(cl_x2.getKey(), cl_x2);
- components.put(cl_x3.getKey(), cl_x3);
- components.put(cl_x4.getKey(), cl_x4);
- components.put(cl_x5.getKey(), cl_x5);
- components.put(case_x1.getKey(), case_x1);
- components.put(case_x2.getKey(), case_x2);
- components.put(case_x3.getKey(), case_x3);
- components.put(case_x4.getKey(), case_x4);
- // DEVICE
- Device d1 = new Device("SCARFACE", "Extremlly powerful PC so you could enjoy playing Solitaire!");
- d1.addComponents(new ArrayList<Component>(Arrays.asList(mb_x1, cpu_x4, hdd_x4, ram_x7, gpu_x4, case_x4)));
- Device d2 = new Device("KATAKLIZMA", "Šta je za reći...rastura Ping-Pong 3D samo tako!");
- d2.addComponents(new ArrayList<Component>(Arrays.asList(mb_x2, cpu_x3, hdd_x2, ram_x4, gpu_x3, case_x2)));
- Device d3 = new Device("VRISAK", "Od njegove snage počećete da vrištite, doslovno!");
- d3.addComponents(new ArrayList<Component>(Arrays.asList(mb_x4, cpu_x6, hdd_x4, ram_x8, gpu_x4, case_x3)));
- devices.put(d1.getKey(), d1);
- devices.put(d2.getKey(), d2);
- devices.put(d3.getKey(), d3);
- // meh
- SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH");
- try {
- // 1
- Bill bill_d = new Bill(20d, sdf.parse("27-06-2014 16"), testUser);
- bill_d.getItems().put(d1, 3);
- bill_d.setTotalPrice(d1.getPrice() * 3);
- bill_d.setId(1); // First!
- bills.put(bill_d.getId(), bill_d);
- // 2
- bill_d = new Bill(20d, sdf.parse("25-06-2014 12"), testUser);
- bill_d.getItems().put(d1, 1);
- bill_d.getItems().put(d2, 1);
- bill_d.setTotalPrice(d1.getPrice() + d2.getPrice());
- bill_d.setId(2);
- bills.put(bill_d.getId(), bill_d);
- // 3
- bill_d = new Bill(20d, sdf.parse("20-06-2014 15"), testUser);
- bill_d.getItems().put(d3, 7);
- bill_d.setTotalPrice(d3.getPrice() * 7);
- bill_d.setId(3);
- bills.put(bill_d.getId(), bill_d);
- // 4
- bill_d = new Bill(20d, sdf.parse("10.06.2014 11"), testUser2);
- bill_d.getItems().put(cpu_x1, 3);
- bill_d.getItems().put(ram_x4, 2);
- bill_d.getItems().put(gpu_x3, 1);
- bill_d.setTotalPrice(cpu_x1.getPrice() * 3 + ram_x4.getPrice() * 2 + gpu_x3.getPrice());
- bill_d.setId(4);
- bills.put(bill_d.getId(), bill_d);
- // 5
- bill_d = new Bill(20d, sdf.parse("05.05.2014 11"), testUser2);
- bill_d.getItems().put(cpu_x3, 1);
- bill_d.getItems().put(ram_x5, 4);
- bill_d.getItems().put(gpu_x4, 2);
- bill_d.setTotalPrice(cpu_x3.getPrice() + ram_x5.getPrice() * 4 + gpu_x4.getPrice() * 2);
- bill_d.setId(5);
- bills.put(bill_d.getId(), bill_d);
- // 5
- bill_d = new Bill(20d, sdf.parse("01.05.2014 08"), testUser2);
- bill_d.getItems().put(cpu_x4, 2);
- bill_d.getItems().put(ram_x6, 4);
- bill_d.getItems().put(gpu_x4, 2);
- bill_d.getItems().put(cl_x3, 3);
- bill_d.getItems().put(case_x3, 1);
- bill_d.setTotalPrice(cpu_x4.getPrice() * 2 + ram_x6.getPrice() * 4 + gpu_x4.getPrice() * 2 + cl_x3.getPrice() * 3 + case_x3.getPrice());
- bill_d.setId(6);
- bills.put(bill_d.getId(), bill_d);
- } catch (java.text.ParseException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- collectionSort(); // Sort stuff
- }
- @SuppressWarnings("unchecked")
- public void collectionSort()
- {
- users = sort(users);
- categories = sort(categories);
- components = sort(components);
- devices = sort(devices);
- bills = sort(bills);
- }
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private LinkedHashMap sort(LinkedHashMap map)
- {
- List list = new LinkedList(map.entrySet());
- Collections.sort(list, new Comparator() {
- public int compare(Object obj1, Object obj2)
- {
- return ((Comparable)((Map.Entry)(obj1)).getKey()).compareTo(((Map.Entry) (obj2)).getKey());
- }
- });
- LinkedHashMap sorted = new LinkedHashMap();
- for (Iterator itr = list.iterator(); itr.hasNext();)
- {
- Map.Entry entry = (Map.Entry)itr.next();
- sorted.put(entry.getKey(), entry.getValue());
- }
- return sorted;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement