/**
* Orders the given list according to the ids.
*
* @param idFunction object to id
* @param objects object list
* @param ids ordered ids
* @param <T> object type
* @return ordered list of objects
*/
public static <K extends Serializable, T> List<T> fixOrder(final Function<T, K> idFunction, final List<T> objects, final List<K> ids) {
final List<T> reordered = new ArrayList<>(ids.size());
final Map<Serializable, T> map = new HashMap<>(ids.size());
objects.forEach(t -> map.put(idFunction.apply(t), t));
ids.forEach(id -> reordered.add(map.get(id)));
return reordered;
}
/**
* Orders the given list according to the ids.
*
* @param idFunction object to id
* @param objects object list
* @param ids ordered ids
* @param <T> object type
* @return ordered list of objects
*/
public static <K extends Serializable, T> List<T> fixOrder(final Function<T, K> idFunction, final List<T> objects, final K... ids) {
return fixOrder(idFunction, objects, Arrays.asList(ids));
}