Guest User

Untitled

a guest
Mar 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. /**
  2. *
  3. */
  4. package dao;
  5.  
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. import org.springframework.stereotype.Repository;
  10.  
  11. import model.Product;
  12.  
  13. /**
  14. * @author suleymancan Mar 7, 2018
  15. */
  16.  
  17. @Repository
  18. public class ProductDAOImpl implements ProductDAO {
  19.  
  20. private List<Product> listOfProducts = new ArrayList<Product>();
  21.  
  22. // bu dalatar injavawetrust (levent ergüder'e) ait
  23. public ProductDAOImpl() {
  24. Product iphone = new Product("P1001", "iPhone 5s", 549.99);
  25. iphone.setDescription("Apple iPhone 5s smartphone with 4.00-inch 640x1136 display and 8-megapixel rear camera");
  26. iphone.setCategory("SmartPhone");
  27. iphone.setManufacturer("Apple");
  28. iphone.setUnitsInStock(1000);
  29.  
  30. Product laptopDell = new Product("P1002", "Dell Inspiron", 799.99);
  31. laptopDell.setDescription("Dell Inspiron 14-inch Laptop (Black) with 3rd Generation Intel Core processors");
  32. laptopDell.setCategory("Laptop");
  33. laptopDell.setManufacturer("Dell");
  34. laptopDell.setUnitsInStock(1000);
  35.  
  36. Product laptopDell133 = new Product("P1003", "Dell Inspiron 13.3", 900);
  37. laptopDell133.setDescription("6th Gen Intel Core i5 processor; 13.3");
  38. laptopDell133.setCategory("Laptop");
  39. laptopDell133.setManufacturer("Dell");
  40. laptopDell133.setUnitsInStock(500);
  41.  
  42. Product tabletNexus = new Product("P1004", "Nexus 7", 298.99);
  43. tabletNexus.setDescription(
  44. "Google Nexus 7 is the lightest 7 inch tablet With a quad-core Qualcomm Snapdragon S4 Pro processor");
  45. tabletNexus.setCategory("Tablet");
  46. tabletNexus.setManufacturer("Google");
  47. tabletNexus.setUnitsInStock(400);
  48.  
  49. Product tabletSamsungS297 = new Product("P1005", "Galaxy Tab S2 9.7", 575.99);
  50. tabletSamsungS297.setDescription("9.7 Super AMOLED touch-screen display with 2048 x 1536 resolution");
  51. tabletSamsungS297.setCategory("Tablet");
  52. tabletSamsungS297.setManufacturer("Samsung");
  53. tabletSamsungS297.setUnitsInStock(300);
  54.  
  55. Product tabletSamsungS280 = new Product("P1006", "Galaxy Tab S2 8.0", 349.99);
  56. tabletSamsungS280.setDescription("8.0 Super AMOLED touch-screen display with 2048 x 1536 resolution");
  57. tabletSamsungS280.setCategory("Tablet");
  58. tabletSamsungS280.setManufacturer("Samsung");
  59. tabletSamsungS280.setUnitsInStock(300);
  60.  
  61. Product laptopAppleAir = new Product("P1007", "Apple - MacBook Air", 999.99);
  62. laptopAppleAir
  63. .setDescription("5th Gen Intel® Core i5 processor; 13.3 display; 4GB memory; 128GB flash storage");
  64. laptopAppleAir.setCategory("Laptop");
  65. laptopAppleAir.setManufacturer("Apple");
  66. laptopAppleAir.setUnitsInStock(100);
  67.  
  68. Product laptopAppleMacbook = new Product("P1007", "Apple - MacBook Pro", 1299.99);
  69. laptopAppleMacbook
  70. .setDescription("MacBook Pro with Retina display - 13.3 Display - 8GB Memory - 128GB Flash Storage");
  71. laptopAppleMacbook.setCategory("Laptop");
  72. laptopAppleMacbook.setManufacturer("Apple");
  73. laptopAppleMacbook.setUnitsInStock(100);
  74.  
  75. listOfProducts.add(iphone);
  76. listOfProducts.add(laptopDell);
  77. listOfProducts.add(laptopDell133);
  78. listOfProducts.add(tabletNexus);
  79. listOfProducts.add(tabletSamsungS297);
  80. listOfProducts.add(tabletSamsungS280);
  81. listOfProducts.add(laptopAppleAir);
  82. listOfProducts.add(laptopAppleMacbook);
  83.  
  84. }
  85.  
  86. @Override
  87. public List<Product> getAllProducts() {
  88. // TODO Auto-generated method stub
  89. return listOfProducts;
  90. }
  91.  
  92. @Override
  93. public Product getProductById(String productId) {
  94. for (Product product : listOfProducts) {
  95. if (product.getProductId().equals(productId)) {
  96. return product;
  97. }
  98. }
  99. return null;
  100. }
  101.  
  102. @Override
  103. public List<Product> getProductsByCategory(String categoryName) {
  104. List<Product> productsByCategory = new ArrayList<>();
  105. for (Product product : listOfProducts) {
  106. if (product.getCategory().equalsIgnoreCase(categoryName)) {
  107. productsByCategory.add(product);
  108. }
  109. }
  110. return productsByCategory;
  111. }
  112.  
  113. /*
  114. * (non-Javadoc)
  115. *
  116. * @see dao.ProductDAO#getProductsByBrands(java.util.List)
  117. */
  118. @Override
  119. public List<Product> getProductsByBrands(List<String> brands) {
  120. //
  121.  
  122. List<Product> productsByBrands = new ArrayList<>();
  123. for (String brand : brands) {
  124.  
  125. for (Product product : listOfProducts) {
  126. if (brand.equalsIgnoreCase(product.getManufacturer())) {
  127. productsByBrands.add(product);
  128. }
  129. }
  130. }
  131. return productsByBrands;
  132. }
  133.  
  134. // burada jpql ile save atabiliriz ama bu örnekte basitce listeye ekleme
  135. // yapacagiz.
  136.  
  137. @Override
  138. public void addProduct(Product product) {
  139. listOfProducts.add(product);
  140. }
  141.  
  142. }
Add Comment
Please, Sign In to add comment