Package design_patterns.strategy

Examples of design_patterns.strategy.Product


            authors_node = null;
            reservations_node = null;


            for (int i = 0; i < this.window_login.getProducts().size();i++){
                Product temp = (Product)this.window_login.getProducts().get(i);
                if(temp!=null){
                    if (this.jTextField.getText().toLowerCase().contains(temp.getName().toLowerCase())){
                        products_node = new DefaultMutableTreeNode("Products");
                        products_node.add(new javax.swing.tree.DefaultMutableTreeNode(temp.getName()));
                        break;
                    }
                }
            }

            //***************************************************************************************
            for (int i = 0; i < this.window_login.getAuthors().size();i++){
                Author temp = (Author)this.window_login.getAuthors().get(i);
                if (temp!=null){
                    if (this.jTextField.getText().toLowerCase().contains(temp.getName().toLowerCase())){
                        authors_node = new DefaultMutableTreeNode("Authors");
                        authors_node.add(new javax.swing.tree.DefaultMutableTreeNode(temp.getName()));
                        break;
                    }
                }
            }
            for (int i = 0; i< this.window_login.getReservations().size();i++){
                Reservation temp = (Reservation)this.window_login.getReservations().get(i);
                if (temp!=null){
                    if (temp.getProduct()!=null){
                        if (this.jTextField.getText().toLowerCase().contains(temp.getProduct().getName().toLowerCase())){
                            reservations_node = new DefaultMutableTreeNode("Reservations");
                            reservations_node.add(new javax.swing.tree.DefaultMutableTreeNode(temp.getProduct().getName()));
                            break;
                        }
                    }
                }
            }
View Full Code Here


              }
              else if (qName.equalsIgnoreCase("Product")) {         
                    Matcher makeMatch = Pattern.compile("\\d+").matcher((String)temp);
                    makeMatch.find();
                    String inputInt = makeMatch.group();
                    Product product = (Product) this.login.getProducts_map().get(Integer.parseInt(inputInt));
                    Author author = (Author) login.getAuthors_map().get(product.getAuthor().getId());
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
                    Date reserv_date_start=null;
                    Date reserv_finish =null;
                    try {
                        if (reserv_date_start!=null && reserv_finish!=null){
View Full Code Here

                        try {
                            date = sdf.parse((String) jsonObject.get("pub_date"));
                        } catch (java.text.ParseException ex) {
                            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        Product product = new Product(Integer.parseInt((String)jsonObject.get("id")),author,(String) jsonObject.get("name"),(String) jsonObject.get("genre"),date);
                        product.setCount((long) jsonObject.get("count"));
                        if (product!=null){
                            login.getProducts().add(product);                   
                            login.getProducts_map().put(product.getId(), product);
                        }
                    }
                } catch (ParseException ex) {
                    Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                }
                flag = true;
            }
            else {
                flag = false;
            }

            data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/video/?format=json", username.getText(), password.getPassword());
            if( data!=null) {
                try {
                    login.setVideos(new ArrayList ());
                    login.setVideos_map(new HashMap());
                    JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
                    for (Object c : (JSONArray) jsonObject.get("objects")){
                        jsonObject = (JSONObject) c;
                        Author author = (Author) login.getAuthors_map().get(Integer.parseInt((String)jsonObject.get("id")));
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
                        Date date=null;
                        try {
                            date = sdf.parse((String) jsonObject.get("pub_date"));
                        } catch (java.text.ParseException ex) {
                            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        Video video = new Video (Integer.parseInt((String)jsonObject.get("id")),author,(String) jsonObject.get("name"),(String) jsonObject.get("genre"),date);
                        video.setCount((long) jsonObject.get("count"));
                        login.getVideos().add(video);              
                        login.getVideos_map().put(video.getId(), video);
                    }
                } catch (ParseException ex) {
                    Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                }
                flag = true;
            }
            else {
                flag = false;
            }

            data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/book/?format=json", username.getText(), password.getPassword());
            if( data!=null) {
                try {
                    login.setBooks(new ArrayList ());
                    login.setBooks_map(new HashMap());
                    JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
                    for (Object c : (JSONArray) jsonObject.get("objects")){
                        jsonObject = (JSONObject) c;
                        Author author = (Author) login.getAuthors_map().get(Integer.parseInt((String)jsonObject.get("id")));
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
                        Date date=null;
                        try {
                            date = sdf.parse((String) jsonObject.get("pub_date"));
                        } catch (java.text.ParseException ex) {
                            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        Book book = new Book (Integer.parseInt((String)jsonObject.get("id")),author,(String) jsonObject.get("name"),(String) jsonObject.get("genre"),date);
                        book.setCount((long) jsonObject.get("count"));
                        login.getBooks().add(book);                 
                        login.getBooks_map().put(book.getId(), book);
                    }
                } catch (ParseException ex) {
                    Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                }
                flag = true;
            }
            else {
                flag = false;
            }

            data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/reservation/?format=json", username.getText(), password.getPassword());
            if( data!=null) {
                try {
                    login.setReservations(new ArrayList ());
                    login.setReservations_map(new HashMap());
                    JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
                    for (Object c : (JSONArray) jsonObject.get("objects")){
                        jsonObject = (JSONObject) c;
                        System.out.println((String)jsonObject.get("user"));
                        Matcher makeMatch = Pattern.compile("\\d+").matcher((String)jsonObject.get("product"));
                        makeMatch.find();
                        String inputInt = makeMatch.group();
                        Product product = (Product) login.getProducts_map().get(Integer.parseInt(inputInt));
                        Author author = (Author) login.getAuthors_map().get(product.getAuthor().getId());
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
                        Date reserv_date_start=null;
                        Date reserv_finish =null;
                        try {
                            reserv_date_start = sdf.parse((String) jsonObject.get("reserv_date_start"));
View Full Code Here

                    try {
                        date = sdf.parse((String) jsonObject.get("pub_date"));
                    } catch (java.text.ParseException ex) {
                        Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                    }
                   Product product = new Product(Integer.parseInt((String)jsonObject.get("id")),author,(String) jsonObject.get("name"),(String) jsonObject.get("genre"),date);
                   this.newproducts.add(product);
                }
            } catch (ParseException ex) {
                Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
            }
View Full Code Here

                        if(temp.equals("/api/reservation/auth/user/"+this.menu_window.getUser().getId()+"/")){
                            System.out.println("coiso: "+(String)jsonObject.get("user"));
                            Matcher makeMatch = Pattern.compile("\\d+").matcher((String)jsonObject.get("product"));
                            makeMatch.find();
                            String inputInt = makeMatch.group();
                            Product aux = (Product)this.menu_window.getLogin_window().getProducts_map().get(Integer.parseInt(inputInt));
                            Reservation r = new Reservation();
                            r.setId(Integer.parseInt((String)jsonObject.get("id")));
                            r.setProduct(aux);
                            this.reservation.add(r);
                            this.jComboBox1.addItem(aux.getName());
                        }

                       
                    }
                } catch (ParseException ex) {
View Full Code Here

    @Override
    public DefaultMutableTreeNode search(ArrayList products) {
        DefaultMutableTreeNode products_node = new DefaultMutableTreeNode("Products");
        for (int i = 0; i < products.size();i++){
            Product temp = (Product)products.get(i);
            if (temp!=null){
                products_node.add(new javax.swing.tree.DefaultMutableTreeNode(temp.getName()));
            }
        }
        return products_node;
    }
View Full Code Here

                        Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                    }
                
                    productcreator.setProduct(videobuilder);
                    productcreator.constructProduct(Integer.parseInt((String)jsonObject.get("id")),author,(String) jsonObject.get("name"),(String) jsonObject.get("genre"),date);
                    Product product = productcreator.getProduct();
                    this.newvideos.add(product);
                }
            } catch (ParseException ex) {
                Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
       
       
        data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/book/?format=json", this.user.getUsername(), this.user.getPassword());
        if( data!=null) {
            try {
                this.newbooks = new ArrayList();
                JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
                for (Object c : (JSONArray) jsonObject.get("objects")){
                    jsonObject = (JSONObject) c;
                    Matcher makeMatch = Pattern.compile("\\d+").matcher((String)jsonObject.get("author"));
                    makeMatch.find();
                    String inputInt = makeMatch.group();
                    Author author = (Author) this.login_window.getAuthors_map().get(Integer.parseInt(inputInt));
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
                    Date date=null;
                    try {
                        date = sdf.parse((String) jsonObject.get("pub_date"));
                    } catch (java.text.ParseException ex) {
                        Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                    }
                
                    productcreator.setProduct(bookbuilder);
                    productcreator.constructProduct(Integer.parseInt((String)jsonObject.get("id")),author,(String) jsonObject.get("name"),(String) jsonObject.get("genre"),date);
                    Product product = productcreator.getProduct();
                    this.newbooks.add(product);
                }
            } catch (ParseException ex) {
                Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        Iterator it = this.login_window.getReservations_map().entrySet().iterator();
        Map reservationProducts = new HashMap();
        while (it.hasNext()) {
            Map.Entry pairs = (Map.Entry)it.next();
            Reservation r = (Reservation) pairs.getValue();
            reservationProducts.put(r.getProduct().getId(), r.getProduct());
            //it.remove(); // avoids a ConcurrentModificationException
        }
       
        this.jTextArea1.setForeground(Color.blue);
       
        for (int i=0; i<this.newvideos.size();i++){
            Product video = (Product) this.newvideos.get(i);        
            if(reservationProducts.get(video.getId())!=null){
                this.jTextArea1.setText(this.jTextArea1.getText()+video.getName()+"****** RESERVED"+"\n");
            }
            else{
                this.jTextArea1.setText(this.jTextArea1.getText()+video.getName()+"****** AVAILABLE"+"\n");
            }
        }
       
        for (int i=0; i<newbooks.size();i++){
            Product book = (Product) newbooks.get(i);
            if(reservationProducts.get(book.getId())!=null){
                this.jTextArea1.setText(this.jTextArea1.getText()+book.getName()+"****** RESERVED"+"\n");
            }
            else{
                this.jTextArea1.setText(this.jTextArea1.getText()+book.getName()+"****** AVAILABLE"+"\n");
            }
        }
    }
View Full Code Here

     */
    public void setProduct(Product product) {
        this.product = product;
    }
   
    public void createNewProduct() { product = new Product(); }
View Full Code Here

        * it calls this method, which resets the string buffer
        */
       public void startElement(String uri, String localName,String qName, Attributes attributes) throws SAXException {
              temp = "";
              if (qName.equalsIgnoreCase("Object")) {
                     this.product = new Product();
              }
       }
View Full Code Here

    }
       private void readList() {
              System.out.println("Names of  the products '" + this.login.getProducts().size()  + "'.");
              Iterator<Product> it = this.login.getProducts().iterator();
              while (it.hasNext()) {
                  Product aux = it.next();
                  System.out.println(aux.getName());
              }
       }
View Full Code Here

TOP

Related Classes of design_patterns.strategy.Product

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.