Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 1st, 2006, 11:41 AM
moon moon is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 1 moon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 10 sec
Reputation Power: 0
Sorting by many kind by using combo box

Hi to all, this is my first participate in this website.I face some problems in implementing the method of the sort. I should implement the (compareTo method) to identify the criterion of sorting. But i doubt with my implementation:I don't know if it's correct or not:

moon Code:
Original - moon Code
    public int compareTo(Object o) {         Book other = (Book) o;         if (this.serialNumber > other.serialNumber                 || (this.title).compareToIgnoreCase(other.title) > 0                 || (this.author).compareToIgnoreCase(other.author) > 0                 || (this.publisher).compareToIgnoreCase(other.publish  er) > 0                 || this.publishingDate > other.publishingDate                 || this.price > other.price)             return 1;         if (this.serialNumber < other.serialNumber                 || (this.title).compareToIgnoreCase(other.title) < 0                 || (this.author).compareToIgnoreCase(other.author) < 0                 || (this.publisher).compareToIgnoreCase(other.publish  er) < 0                 || this.publishingDate > other.publishingDate                 || this.price > other.price)             return -1;         return 0;     }
on the other hand, I have to implement in the Graphical User Interface application the list of the ceteria by using combo box. I found it difficult for me to write the sort method using compareTo method and how to activate the selection part in the combo box.for example, Choose a criterion for sort and sort accordingly. For example, the user may choose to sort according to serial number, title, publisher, publishing year, or price by the combo box.
the note, all this methods done by the Linked Class
import java.util.Iterator;

Linked Class Code:
Original - Linked Class Code
    public class Linked<E> {         boolean empty(){         return true;     }     E head(){         throw new RuntimeException();     }         Linked<E> tail(){         throw new RuntimeException();     }     Linked<E> add(E head){         return new LinkedNode<E>(head, this);//l=l.add("Alia");{Alia{Aisha{}}}     }         int size(){         return 0;     }         public void print(String s){         System.out.print(s);         System.out.println("Empty List");     } // the method in the LinkedNode can work here        public Linked<E> reverse(){         return this;     }         /*public Linked<E> add(E t){         Linked<E> m = new BookList<E>(head, this);         return m;     }*/     public Linked<E> addTail(E t){         return add(t);     }         public Linked<E> rev(){         return this;     }         public Linked<E> removeTail(){         throw new RuntimeException();     }         public Linked<E> join(Linked<E> list){         return list;     }         public Linked<E> sort(){//less(recursion)+head+tail(recursion)         return this;     }         public Iterator<E> iterator(){         Iterator<E> it = new LinkedIterator<E>(this);         return it;     }         public Linked<E> remove(E item){         throw new RuntimeException();     }         public Linked<E> clear (){         return new Linked<E>();     }         public E getLast(){         throw new RuntimeException();     } }


other is LinkedNode Class which contain the sort method which I want to modefy it to fit the all creiteria
Sort method Code:
Original - Sort method Code
        public Linked<E> sort() {// less(recursion)+head+tail(recursion)         Comparable h = (Comparable) head;         Linked<E> less = new Linked<E>();         Linked<E> more = new Linked<E>();         for (Linked<E> l = tail; !l.empty(); l = l.tail()) {             if (h.compareTo(l.head()) > 0) {                 less = less.add(l.head());             } else {                 more = more.add(l.head());             }         }         less = less.sort();         more = more.sort();         return less.join(more.add(head));             }


Could any one help me very soon because this is a part of the project.

I appreciate your helps.

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > Sorting by many kind by using combo box


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT