Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zad4;
- import javax.faces.bean.ManagedBean;
- import javax.faces.bean.RequestScoped;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Locale;
- import static java.util.Objects.isNull;
- @ManagedBean(name = "Order")
- @RequestScoped
- public class Order {
- private ArrayList booksList = new ArrayList<>(Arrays.asList(
- new Book("Title1", "Author1", BookType.COMEDY, 75.23, Currency.PLN, 300),
- new Book("Title2", "Author2", BookType.THRILLER, 27.99, Currency.USD, 254),
- new Book("Title3", "Author3", BookType.DOCUMENT, 119.21, Currency.PLN, 123),
- new Book("Title4", "Author4", BookType.HORROR, 83.32, Currency.CHF, 972),
- new Book("Title5", "Author5", BookType.HORROR, 40.99, Currency.USD, 321),
- new Book("Title6", "Author6", BookType.COMEDY, 15.99, Currency.EUR, 456)
- ));
- public void setFilteredBooks(ArrayList filteredBooks) {
- this.filteredBooks = filteredBooks;
- }
- private BookType[] bookTypes = BookType.values();
- private Currency[] currencies = Currency.values();
- private ArrayList<Book> filteredBooks;
- private ArrayList<Book> selectedBooks;
- private String charge;
- public String getCharge() {
- if(isNull(selectedBooks) || selectedBooks.isEmpty()){
- return String.valueOf(0);
- }
- double priceInPLN = 0;
- for (int i = 0; i < selectedBooks.size(); i++) {
- Currency currency = selectedBooks.get(i).getCurrency();
- double price = selectedBooks.get(i).getPrice();
- switch (currency){
- case PLN: {
- priceInPLN += price;
- break;
- }
- case USD: {
- priceInPLN += price * 3;
- break;
- }
- case CHF: {
- priceInPLN += price * 6;
- break;
- }
- case EUR: {
- priceInPLN += price * 4;
- break;
- }
- }
- }
- return String.valueOf(priceInPLN);
- }
- public void setCharge(String charge) {
- this.charge = charge;
- }
- public ArrayList getSelectedBooks() {
- return selectedBooks;
- }
- public void setSelectedBooks(ArrayList selectedBooks) {
- this.selectedBooks = selectedBooks;
- }
- public boolean filterByPrice(Object value, Object filter, Locale locale) {
- String filterText = (filter == null) ? null : filter.toString().trim();
- if(filterText == null||filterText.equals("")) {
- return true;
- }
- if(value == null) {
- return false;
- }
- return ((Comparable) value).compareTo(Double.valueOf(filterText)) <= 0;
- }
- public boolean filterByPages(Object value, Object filter, Locale locale) {
- String filterText = (filter == null) ? null : filter.toString().trim();
- if(filterText == null||filterText.equals("")) {
- return true;
- }
- if(value == null) {
- return false;
- }
- return ((Comparable) value).compareTo(Integer.valueOf(filterText)) >= 0;
- }
- public Currency[] getCurrencies() {
- return currencies;
- }
- public ArrayList getBooksList(){
- return booksList;
- }
- public ArrayList getFilteredBooks() {
- return filteredBooks;
- }
- public BookType[] getBookTypes() {
- return bookTypes;
- }
- public void setBookTypes(BookType[] bookTypes) {
- this.bookTypes = bookTypes;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement