Register FAQ Calendar Search Today's Posts Mark Forums Read

Go Back   Java Programming Forums > Java Programming > New to Java

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-10-2008, 10:16 PM
Junior Member
 
Join Date: Sep 2008
Posts: 3
nadman123 is on a distinguished road
Default convert arraylist to a hash map

hey guyz how do you change all of these methods when you are replacing the arraylist with a hash map
Java Code:
 public Order() {
        this.orderNumber = orderNumberCounter;
        orderNumberCounter++;
        orderLines = new ArrayList<OrderLine>();
        orderTime = Calendar.getInstance();
    }

    /**
     * Constructs a new Order object with the value of the passed in parameters
     * 
     * @param orderLines - the initial value of each order line that is in this order
     */
    public Order(ArrayList<OrderLine> orderLines) {
        this.orderNumber = orderNumberCounter;
        orderNumberCounter++;
        
        for (OrderLine orderLine : orderLines) {
            this.orderLines.add(orderLine);
        }
        
        this.orderTime = Calendar.getInstance();
    }

    /**
     * Return the food numbers of foods that are in this order
     * 
     * @return a copy of attribute foodNumbers
     */
    public ArrayList<OrderLine> getOrderLines() {
        return (ArrayList<OrderLine>)orderLines.clone();
    }

    /**
     * Add a food to the order along with the correponding quantity
     * 
     * @param food - the food to add 
     * @param quantity - the quantity of the food
     * @return true if the food item is added successfully, false otherwise
     */
    public boolean addItem(Food food, int quantity) {
        if (!orderLines.contains(searchOrderLine(food))) {
            return this.orderLines.add(new OrderLine(food, quantity));
        }
        return false;
    }
    
    /**
     * Add an order line to the order
     * 
     * @param orderLine - the new order line to add in 
     * @return true if the orderLine is added successfully, false otherwise
     */
    public boolean addItem(OrderLine orderLine) {
        if (!orderLines.contains(searchOrderLine(orderLine.getFood()))) {
            return this.orderLines.add(orderLine);
        }
        return false;
    }

     /**
     * Remove a food from the order
     * 
      * @param food - the food to remove
      * @return true if the food item is removed successfully, false otherwise
     */
    public boolean removeItem(Food food) {
        return this.orderLines.remove(searchOrderLine(food));
    }

    /**
     * Search whether a food already existed in the order
     * 
     * @param food - the food to search
     * @return the order line containing the food 
     */
    private OrderLine searchOrderLine(Food food) {
        for (OrderLine orderLine : orderLines) {
            if (orderLine.getFood().getFoodNumber() == food.getFoodNumber()) {
                return orderLine;
            }
        }
        return new OrderLine();
    }
tahnx in advance
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Custom Search
100 most searched terms
Search Cloud
"bad endpoint type" com.sun.xml.internal.messaging.saaj.soapexceptionimpl com.sun.xml.internal.messaging.saaj.soapexceptionimpl: bad endpoint type com.sun.xml.internal.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception com.sun.xml.internal.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl: message send failed com.sun.xml.internal.messaging.saaj.soapexceptionimpl: message send failed com.sun.xml.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception com.sun.xml.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception: com.sun.xml.messaging.saaj.soapexceptionimpl: message send failed convert arraylist to map date_format_now eclipse shortcut keys ejb3 quartz java convert double to binary java forum java forums java jtextarea bold java jtextarea color java jtextarea font java jtextarea font size java programmer forum java programmers forum java programming forum java programming forums java read last line java read last line of file java sendkeys java.security.privilegedactionexception java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl: bad response java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl: message send failed java.security.privilegedactionexception: com.sun.xml.messaging.saaj.soapexceptionimpl: message send failed javapf javaprogrammingforums jtextarea bold jtextarea font jtextarea font color jtextarea font size programing forums programming forums reset jcombobox saaj0008 saaj0008: bad response; bad request saaj0008: bad response; not found severe: saaj0008 severe: saaj0008: bad response; bad request severe: saaj0008: bad response; not found soap java.security.privilegedactionexception soapexceptionimpl: bad endpoint type textpad java

All times are GMT. The time now is 12:11 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.