blob: f541b37cdbeb529084c8f64383d87398850f2062 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package ch.epfl.xblast;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Lists utility class providing common operations on lists.
*
* @author Pacien TRAN-GIRARD (261948)
* @author Timothée FLOURE (257420)
*/
public final class Lists {
/**
* Returns a reversed copy of the given list, leaving the original one unmodified.
*
* @param l the list to reverse
* @param <T> the type of the list's elements
* @return a reversed copy of the list.
*/
public static <T> List<T> reversed(List<T> l) {
List<T> r = new ArrayList<>(l);
Collections.reverse(r);
return r;
}
/**
* Returns a symmetric version of the list, without repeating the last element of the input list.
* For instance, mirrored([kay]) will return [kayak].
*
* @param l the input list
* @param <T> the type of the list's elements
* @return the mirrored list
* @throws IllegalArgumentException if the given list is empty
*/
public static <T> List<T> mirrored(List<T> l) {
if (l == null || l.size() == 0) throw new IllegalArgumentException();
return Stream
.concat(l.stream(), Lists.reversed(l).stream().skip(1))
.collect(Collectors.toList());
}
/**
* Returns all the permutations of the elements of the given list
*
* @param l given list
* @return a list of all the permutations of the list
*/
public static <T> List<List<T>> permutations(List<T> l) {
return null;
}
}
|