Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. package zad4;
  2.  
  3. import javax.faces.bean.ManagedBean;
  4. import javax.faces.bean.RequestScoped;
  5. import java.util.ArrayList;
  6. import java.util.Arrays;
  7. import java.util.Locale;
  8.  
  9. import static java.util.Objects.isNull;
  10.  
  11. @ManagedBean(name = "Order")
  12. @RequestScoped
  13. public class Order {
  14.  
  15. private ArrayList booksList = new ArrayList<>(Arrays.asList(
  16. new Book("Title1", "Author1", BookType.COMEDY, 75.23, Currency.PLN, 300),
  17. new Book("Title2", "Author2", BookType.THRILLER, 27.99, Currency.USD, 254),
  18. new Book("Title3", "Author3", BookType.DOCUMENT, 119.21, Currency.PLN, 123),
  19. new Book("Title4", "Author4", BookType.HORROR, 83.32, Currency.CHF, 972),
  20. new Book("Title5", "Author5", BookType.HORROR, 40.99, Currency.USD, 321),
  21. new Book("Title6", "Author6", BookType.COMEDY, 15.99, Currency.EUR, 456)
  22. ));
  23.  
  24. public void setFilteredBooks(ArrayList filteredBooks) {
  25. this.filteredBooks = filteredBooks;
  26. }
  27.  
  28. private BookType[] bookTypes = BookType.values();
  29. private Currency[] currencies = Currency.values();
  30. private ArrayList<Book> filteredBooks;
  31. private ArrayList<Book> selectedBooks;
  32. private String charge;
  33.  
  34. public String getCharge() {
  35. if(isNull(selectedBooks) || selectedBooks.isEmpty()){
  36. return String.valueOf(0);
  37. }
  38. double priceInPLN = 0;
  39. for (int i = 0; i < selectedBooks.size(); i++) {
  40. Currency currency = selectedBooks.get(i).getCurrency();
  41. double price = selectedBooks.get(i).getPrice();
  42. switch (currency){
  43. case PLN: {
  44. priceInPLN += price;
  45. break;
  46. }
  47. case USD: {
  48. priceInPLN += price * 3;
  49. break;
  50. }
  51. case CHF: {
  52. priceInPLN += price * 6;
  53. break;
  54. }
  55. case EUR: {
  56. priceInPLN += price * 4;
  57. break;
  58. }
  59. }
  60. }
  61. return String.valueOf(priceInPLN);
  62. }
  63.  
  64. public void setCharge(String charge) {
  65. this.charge = charge;
  66. }
  67.  
  68. public ArrayList getSelectedBooks() {
  69. return selectedBooks;
  70. }
  71.  
  72. public void setSelectedBooks(ArrayList selectedBooks) {
  73. this.selectedBooks = selectedBooks;
  74. }
  75.  
  76. public boolean filterByPrice(Object value, Object filter, Locale locale) {
  77. String filterText = (filter == null) ? null : filter.toString().trim();
  78. if(filterText == null||filterText.equals("")) {
  79. return true;
  80. }
  81. if(value == null) {
  82. return false;
  83. }
  84. return ((Comparable) value).compareTo(Double.valueOf(filterText)) <= 0;
  85. }
  86. public boolean filterByPages(Object value, Object filter, Locale locale) {
  87. String filterText = (filter == null) ? null : filter.toString().trim();
  88. if(filterText == null||filterText.equals("")) {
  89. return true;
  90. }
  91. if(value == null) {
  92. return false;
  93. }
  94. return ((Comparable) value).compareTo(Integer.valueOf(filterText)) >= 0;
  95. }
  96.  
  97. public Currency[] getCurrencies() {
  98. return currencies;
  99. }
  100.  
  101. public ArrayList getBooksList(){
  102. return booksList;
  103. }
  104.  
  105. public ArrayList getFilteredBooks() {
  106. return filteredBooks;
  107. }
  108.  
  109. public BookType[] getBookTypes() {
  110. return bookTypes;
  111. }
  112.  
  113. public void setBookTypes(BookType[] bookTypes) {
  114. this.bookTypes = bookTypes;
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement