• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding Ordering the List

 
surya.raaj prakash
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For your requirement Map will be the best suited
 
Parag Shah
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 5347
50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Stephan van Hulst
Bartender
Pie
Posts: 5347
50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3028
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic