I am hard stuck on a problem I cannot find a good answer to. I've found this one about custom comparators, but it is incomplete:
class YourClass { static Comparator<YourClass> getAttribute1Comparator() { return new Comparator<YourClass>() { // compare using attribute 1 }; } static Comparator<YourClass> getAttribute2Comparator() { return new Comparator<YourClass>() { // compare using attribute 2 }; } }
That should work, but I don't know how the comparison part works. Here is my class:
package ZVCVolkel_Logic;
import java.util.Comparator;
public class Vliegtuig implements Comparator<Vliegtuig>{
private String naam;
private String type;
private String status;
private Hangaar hangaar;
public Vliegtuig(String naam, String type, String status, Hangaar hangaar){
this.naam = naam;
this.type = type;
this.status = status;
this.hangaar = hangaar;
}
}
Now I need a comparator for status
and for Hangaar.getName()
. Can someone help?
It is not the one, he has only 1 comparator. I can get that working too but not with 2 different ones in 1 class.