Results 1 to 4 of 4
  1. #1
    ajbj is offline Member
    Join Date
    Aug 2009
    Rep Power

    Default please review the following code

    please give me feedback on the following code
    public LinkedList findOrdersForProduct(Product p, boolean debug) {
    ArrayList l = new ArrayList();
    ArrayList list = getAllOrders();
    for (int i=0; i<list.size(); i++) {
    Order order = (Order) list.get(0);
    boolean found = false;
    if (order.getProducts().size() > 0) {
    for (int j=0; j<=order.getProducts().size(); j++) {
    Product p2 = order.getProducts().get(j);
    found = (p2 == p);
    if (found && order != null)
    return new LinkedList(l);

    please tell me that is this code is complicated and what are the other problems in this code
    Last edited by ajbj; 08-25-2009 at 06:03 AM.

  2. #2
    sysout is offline Member
    Join Date
    Aug 2009
    Rep Power


    where's the code?

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Rep Power


    Several sins have been committed here:
    1.) You posted code without wrapping it in code tags. Looks like the site police doesn't like that (understandably so).
    2.) The method takes a boolean parameter called debug that it never uses.
    3.) The method uses meaningless variable names like l,list,p2.
    4.) The code does not use generics to aid in type safety and avoid the ugly casts all over the place.
    5.) The code uses == to compare equality of two Products. == will check equality of the references not of the objects. Better use the .equals methods for such purposes.
    6.) The logic of the method itself is cumbersome and probably incorrect. It could all be collapsed into
    Java Code:
    for(Order oder: getAllOrders()) {
        if(oder.getProducts().contains(p)) {

Similar Threads

  1. Please Review My Code (Long Integer Addition)
    By Saradus in forum New To Java
    Replies: 12
    Last Post: 07-05-2009, 02:01 PM
  2. Web Page Review
    By MuslimCoder in forum Reviews / Advertising
    Replies: 0
    Last Post: 03-18-2009, 09:38 AM
  3. [SOLVED] Code review
    By saeedsubedar in forum Advanced Java
    Replies: 14
    Last Post: 06-25-2008, 06:25 AM
  4. Java Review
    By toad in forum New To Java
    Replies: 5
    Last Post: 12-08-2007, 02:28 AM
  5. Java Review Question
    By toad in forum New To Java
    Replies: 1
    Last Post: 10-29-2007, 07:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts