aspose file tools*
The moose likes Java in General and the fly likes Regarding Ordering the List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regarding Ordering the List " Watch "Regarding Ordering the List " New topic
Author

Regarding Ordering the List

surya.raaj prakash
Ranch Hand

Joined: Oct 30, 2009
Posts: 76
Hi Friends,

I have one requirement would you please help on this..


I have List object which contain three elements...from the preceding code we will get the list object..

My question is how to set the order number to each element in list so based on the order number we need to get the employee or how to write a logic to check the order and status to determine the next employee in the list?and and how to check this employee same as next employee from the employee list?


Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

For your requirement Map will be the best suited


SCJP6.0,My blog Ranchers from Delhi
Parag Shah
Greenhorn

Joined: Jan 23, 2002
Posts: 26
Java Lists allow duplicates, wheres a Set does not allow duplicates. If you want ordering, you can use a TreeSet which is an ordered set.


http://diycomputerscience.com
Do It Yourself Computer Science
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Parag Shah wrote: . . . TreeSet . . . is an ordered set.
No it isn't, it is a sorted set. If you need to retain insertion order, you want a LinkedHashSet or similar.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

Campbell Ritchie wrote:No it isn't

Technically it is, how else could be it sorted? ;)

Surya, can you be more clear in what you need?
surya.raaj prakash
Ranch Hand

Joined: Oct 30, 2009
Posts: 76
ok,stephan..

Actual requirement is..
I have been developed Three classes..
1.Approval.java it contains
"type",
"approvers",----> ( )
"dateCreated" properties
2.Approver.java it contains
"employee",
"status",
"statusDate" properties
3.Employee.java ti contains
"employeeNbr",
"firstName",
"lastName",
"emailAddress",
"managerEmployeeNbr",
"managerInfo" properties

Here from Approval object we will get list of Approver object,from Approver object we will get employee object..right?
But i would want how to write a logic to check the order and status to determine the next approver in the list?or how to check this employee same as next employee who supposed to approve from the approvers list?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Stephan van Hulst wrote: . . . Technically it is, how else could be it sorted? ;) . . .
Good grief, there's somebdoy more pedantic than me out there
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

Ok, so you have an Approval, which has a list of Approvers, and an Approver refers to an Employee and has a status.

surya.raaj prakash wrote:Here from Approval object we will get list of Approver object,from Approver object we will get employee object..right?

Yes.
surya.raaj prakash wrote:But i would want how to write a logic to check the order and status to determine the next approver in the list?or how to check this employee same as next employee who supposed to approve from the approvers list?

It's not exactly clear to me what you want to do with the approvers of an approval. You can ofcourse look at the status of each approver, and you can look at the Employee that each Approver refers to. Since the list of approvers is a list, it will be in a certain order. What exactly do you want to check there; if the order is correct? If that is what you want, then what are the rules for a correct order? I guess that you can check if two Employees are the same by comparing their employeeNbrs.

Can you explain exactly what you want to do with the Approvers of an Approval?

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

Surya, why is it important that you get them in a specific order? If you want to do this, you can create a Comparator object, and use either Collections.sort() to sort the List or use a SortedSet.

Campbell Ritchie wrote:Good grief, there's somebody more pedantic than I out there

Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
Campbell Ritchie wrote:
Stephan van Hulst wrote: . . . Technically it is, how else could be it sorted? ;) . . .
Good grief, there's somebdoy more pedantic than me out there

He's not really any more pedantic - just more correct.
 
Consider Paul's rocket mass heater.
 
subject: Regarding Ordering the List