diff options
Diffstat (limited to 'src/ch/epfl/xblast/Lists.java')
-rw-r--r-- | src/ch/epfl/xblast/Lists.java | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/ch/epfl/xblast/Lists.java b/src/ch/epfl/xblast/Lists.java index 073e0cc..da3f919 100644 --- a/src/ch/epfl/xblast/Lists.java +++ b/src/ch/epfl/xblast/Lists.java | |||
@@ -167,4 +167,18 @@ public final class Lists { | |||
167 | .collect(Collectors.toList())); | 167 | .collect(Collectors.toList())); |
168 | } | 168 | } |
169 | 169 | ||
170 | /** | ||
171 | * Returns an immutable copy of the given list, sorted using the supplied comparator. | ||
172 | * | ||
173 | * @param l the list to sort | ||
174 | * @param cmp the Comparator to use | ||
175 | * @param <T> the type of the list's elements | ||
176 | * @return the sorted list | ||
177 | */ | ||
178 | public static <T> List<T> sorted(List<T> l, Comparator<T> cmp) { | ||
179 | List<T> r = new ArrayList<>(l); | ||
180 | Collections.sort(r, cmp); | ||
181 | return Collections.unmodifiableList(r); | ||
182 | } | ||
183 | |||
170 | } | 184 | } |