• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Regarding Ordering the List

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?


 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For your requirement Map will be the best suited
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 76888
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 14515
325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 76888
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 14515
325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Rancher
Posts: 4335
59
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Water! People swim in water! Even tiny ads swim in water:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic