Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

The method sort(Comparator<? super Employee>) in the type List<Employee> is not applicable

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Saloon Keeper
Posts: 13394
296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
List.sort() only works with object types that are comparable to each other. How would it know how to compare two employees to each other?
 
Akash bhamri
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Stephan van Hulst so how can I call this one public List<Employee> sort(List<Employee> emps, final SortMethod method)
 
Marshal
Posts: 74371
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't have a Comparator anywhere. The enum doesn't correctly implement Comparator because it doesn't have a compare() method. Didn't you get a compiler error message about that?
 
Akash bhamri
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Campbell Ritchie
53 line to 56 I used compare so that it will compare it? but it will not compare so what I have to do? can you please code it? to compare based on their name and salary?
 
Campbell Ritchie
Marshal
Posts: 74371
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Akash bhamri wrote:. . . what I have to do?

Write two comparators called BY-NAME and BY_SALARY.

can you please code it?

Can? yes. Will? no. You have already written Comparator.comparing(...) correctly in one place, and the other only needs a tiny correction.

to compare based on their name and salary?

 
Akash bhamri
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Campbell Ritchie sorry but I didn't get your point. I am beginner in collection topic can you please code it.
 
Campbell Ritchie
Marshal
Posts: 74371
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at lines 44‑45 in the code.
 
Akash bhamri
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Campbell Ritchie I am try to do this

isCharacterPresentInAllNames(Collection<Employee> entities, String character): Method to check if Employee list contains a name starting with a specific character
Implement using Lambda expressions.

 
Campbell Ritchie
Marshal
Posts: 74371
334
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Finish one task before you start the next one. You have code which you can't run because it won't compile. If you add more code you will probably only add more compiler errors.
 
Campbell Ritchie
Marshal
Posts: 74371
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why didn't you tell us that poor design was part of the requirements? Why did you delete that part?
 
Akash bhamri
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Campbell Ritchie that one is solved bro now how can I do this one
isCharacterPresentInAllNames(Collection<Employee> entities, String character): Method to check if Employee list contains a name starting with a specific character Implement using Lambda expressions.
 
Saloon Keeper
Posts: 1642
55
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought I had seen most types of enum abuse before this, I worked with someone who loved them and did everything with them.

I didn't realize that enum types could have an implements until today, so I learned something.

This is a curious mix of rather beginning and decidedly not-beginning Java.
 
Bartender
Posts: 4682
183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Confusing topic. Op's code in his opening post is almost correct. Instead of the line (68)

it sould either be

or

and for your latest question:how about
 
Jesse Silverman
Saloon Keeper
Posts: 1642
55
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Piet, and OP:

If I read things correctly, it sounds like .anyMatch() is a better match than .allMatch()?
 
Piet Souris
Bartender
Posts: 4682
183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jesse,

The method name is 'isCharacterPresentInAllNames'
 
Jesse Silverman
Saloon Keeper
Posts: 1642
55
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, his description of what he wanted it to do didn't sound like it matched the method name.
If the name of the method was what was given then his description must have been a bad paraphrase or misreading.
(Method to check if Employee list contains a name starting with a specific character) <-- sounds like a job for .anyMatch()
(Method to check if Employee list contains only names starting with a specific character) <-- sounds like a job for .allMatch()
 
Jesse Silverman
Saloon Keeper
Posts: 1642
55
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what's more, I still don't buy it.

The name of the method doesn't imply "Starts with" at all, only "Contains"...

The OP should probably post that part of the problem description.  I suspect it is written unclearly.

Understanding how to derive the requirements from the problem description is sometimes the most important part of the problem!

I will write more about that somewhere else, not to hijack the thread.
 
Campbell Ritchie
Marshal
Posts: 74371
334
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Akash bhamri wrote:@Campbell Ritchie that one is solved bro now how can I do this one . . .

Kindly don't call me “bro”.
Please show us the working version.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic