Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Ron McLeod
paul wheaton
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Himai Minh
Bartenders:
Forum:
Beginning Java
Sorting array list of classes
mike karl
Greenhorn
Posts: 13
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
this is basically the short hand version of my class, just a question, how can i use my setOrder method to set the order for customer, amount, and date instead of writing 3 different methods for each one
public class Report implements Iterable<Bill> { public static enum reportsCreated implements java.util.Comparator<Bill> { BY_CUSTOMER { @Override public int compare(Bill arg0, Bill arg1) { return (arg0.owner.name.compareTo(arg1.owner.name)); } }, BY_AMOUNT {... }, BY_DATE {... }; } List<Bill> listOfReports = new ArrayList<Bill>(); public void setOrder(List<Bill> a) { List<Bill> tempList = new ArrayList<Bill>(); int reVal = 0; for (int i = 0; i < a.size(); i++) { for (int b = i; b < a.size(); b++) { reVal = reportsCreated.BY_CUSTOMER.compare(a.get(b), a.get(i)); if (reVal > 0) tempList.add(i, a.get(b)); } } tempList.iterator(); } @Override public Iterator<Bill> iterator() { Iterator<Bill> billed = listOfReports.iterator(); return billed; } }
Campbell Ritchie
Marshal
Posts: 80769
488
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Start with
the Java Tutorials
.
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
declaring an array using an interface type
Using class Iterable and sorting ArrayList
Multiple ArrayList
Insert method....
Inheritance
More...