I'm trying to build a select menu object. I'm using hibernate criteria to build my object list. I'm trying to take my joined table object and add it to a set to eliminate duplicates. I then want to order the set by a property within the object, once ordered I need to add it to an arraylist and finally add one additional entry to the end of the list.
Here's what I have thus far.
public class Computer {
private String name;
//other properties getter/setter
}
Select menu query
public List<Computer> getComputerList() {
//Hibernate critera query
List<ComputerConfiguration> results = session.criteraQuery(ComputerConfiguration.class).add(Restrictions.eq("processor", "amd")).list();
Set<Computer> computerSet = HashSet();
//Get joined object and add to set to remove duplicates
for(ComputerConfiguration computerConfiguration : results) {
computerSet.add(computerConfiguration.getComputer());
}
List<Computer> computers = new ArrayList<>(computerSet);
//Need to somehow order by computer.getName();
//Lastly add the following
computers.add("Other");
//Return computers to select model
return computers;
}
What is the most efficient way to remove duplicate objects and then order them by the property name? I tried just initially ordering the critera query, however the set didn't appear to hold its position.
Thanks.