Coverage Summary for Class: Swap (it.polimi.ingsw.view.model)
Class | Class, % | Method, % | Line, % |
---|---|---|---|
Swap | 100% (1/ 1) | 100% (6/ 6) | 100% (18/ 18) |
1 package it.polimi.ingsw.view.model;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.List;
6 import java.util.stream.Collectors;
7
8 /**
9 * Worker Swap Data Structure
10 */
11 public class Swap implements RawObj {
12 /**
13 * First Element start position to move
14 */
15 private final List<Integer> x1;
16 /**
17 * First Element end position to move
18 */
19 private final List<Integer> x2;
20 /**
21 * Second Element start position to move
22 */
23 private final List<Integer> y1;
24 /**
25 * Second Element end position to move
26 */
27 private final List<Integer> y2;
28
29 /**
30 * Swap Constructor
31 *
32 * @param x1 First Element start position to move
33 * @param x2 First Element end position to move
34 * @param y1 Second Element start position to move
35 * @param y2 Second Element end position to move
36 */
37 public Swap(List<Integer> x1, List<Integer> x2, List<Integer> y1, List<Integer> y2) {
38 this.x1 = x1;
39 this.x2 = x2;
40 this.y1 = y1;
41 this.y2 = y2;
42 }
43
44 @Override
45 public ArrayList<String> getRawData() {
46 String from = "[";
47 String to = "] => [";
48 if (Arrays.equals(y1.toArray(), y2.toArray()))
49 return new ArrayList<>(
50 Arrays.asList("Move", from + (x1.get(0) * 5 + x1.get(1)) + to + (x2.get(0) * 5 + x2.get(1)) + "]"));
51 return new ArrayList<>(
52 Arrays.asList("Swap", from + (x1.get(0) * 5 + x1.get(1)) + to + (x2.get(0) * 5 + x2.get(1)) + "]",
53 from + (y1.get(0) * 5 + y1.get(1)) + to + (y2.get(0) * 5 + y2.get(1)) + "]"));
54 }
55
56 /**
57 * Get First Element start position to move
58 *
59 * @return First Element start position to move
60 */
61 public List<Integer> getX1() {
62 return x1.stream().map(e -> e).collect(Collectors.toList());
63 }
64
65 /**
66 * Get First Element end position to move
67 *
68 * @return First Element end position to move
69 */
70 public List<Integer> getX2() {
71 return x2.stream().map(e -> e).collect(Collectors.toList());
72 }
73
74 /**
75 * Get Second Element start position to move
76 *
77 * @return Second Element start position to move
78 */
79 public List<Integer> getY1() {
80 return y1.stream().map(e -> e).collect(Collectors.toList());
81 }
82
83 /**
84 * Get Second Element end position to move
85 *
86 * @return Second Element end position to move
87 */
88 public List<Integer> getY2() {
89 return y2.stream().map(e -> e).collect(Collectors.toList());
90 }
91 }