I have the class below and I want to be able to determine a senior role between two dtos that is passed. The enum Role below is arranged according to seniority. Secretary is higher than cleaner and Manager is higher than secretary and cleaner.
How do I determine which Role is higher and return in the jobFunction?
@Table(name = "myusers_v")
public class UserDto {
@Column(name = "JOB_FUNCTION")
@Enumerated(EnumType.STRING)
private Role jobFunction;
public static UserDto merge(UserDto userDto1, UserDto userDto2) {
//Assuming userDto1.getJobFunction() = Cleaner
//Assuming userDto2.getJobFunction() = Manager
//? Determine which role is higher from the two above and return below
return UserDto.builder()
.jobFunction(defaultIfNull(userDto1.getJobFunction(), userDto2.getJobFunction()))
.build();
}
}
public enum Role {
Cleaner, Secretary, Manager, Director;
}