aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-05-05 21:19:28 +0200
committerPacien TRAN-GIRARD2016-05-05 21:19:28 +0200
commitbbd1aa31fbec7b46cb2c3a53e43101dbfa40897a (patch)
treea4a118b265bc5d5a1ae84afaea0c406dde315bca /src
parent635694370ce04f9ae6da4b137883586b70f14a7b (diff)
downloadxblast-bbd1aa31fbec7b46cb2c3a53e43101dbfa40897a.tar.gz
Enforce immutability
Diffstat (limited to 'src')
-rw-r--r--src/ch/epfl/xblast/RunLengthEncoder.java10
-rw-r--r--src/ch/epfl/xblast/server/GameStateSerializer.java8
2 files changed, 9 insertions, 9 deletions
diff --git a/src/ch/epfl/xblast/RunLengthEncoder.java b/src/ch/epfl/xblast/RunLengthEncoder.java
index d7ab106..3784e0d 100644
--- a/src/ch/epfl/xblast/RunLengthEncoder.java
+++ b/src/ch/epfl/xblast/RunLengthEncoder.java
@@ -171,10 +171,10 @@ public final class RunLengthEncoder {
171 public static List<Byte> encode(List<Byte> bl) { 171 public static List<Byte> encode(List<Byte> bl) {
172 List<RunLength> rll = bl.stream().map(RunLength::new).collect(Collectors.toList()); 172 List<RunLength> rll = bl.stream().map(RunLength::new).collect(Collectors.toList());
173 173
174 return collapseRunLengths(rll).stream() 174 return Collections.unmodifiableList(collapseRunLengths(rll).stream()
175 .flatMap(rl -> rl.split().stream()) 175 .flatMap(rl -> rl.split().stream())
176 .flatMap(rl -> rl.encode().stream()) 176 .flatMap(rl -> rl.encode().stream())
177 .collect(Collectors.toList()); 177 .collect(Collectors.toList()));
178 } 178 }
179 179
180 /** 180 /**
@@ -184,9 +184,9 @@ public final class RunLengthEncoder {
184 * @return the decoded byte sequence 184 * @return the decoded byte sequence
185 */ 185 */
186 public static List<Byte> decode(List<Byte> el) { 186 public static List<Byte> decode(List<Byte> el) {
187 return decodeRunLengths(el).stream() 187 return Collections.unmodifiableList(decodeRunLengths(el).stream()
188 .flatMap(rl -> rl.expand().stream()) 188 .flatMap(rl -> rl.expand().stream())
189 .collect(Collectors.toList()); 189 .collect(Collectors.toList()));
190 } 190 }
191 191
192} \ No newline at end of file 192}
diff --git a/src/ch/epfl/xblast/server/GameStateSerializer.java b/src/ch/epfl/xblast/server/GameStateSerializer.java
index 7747ecb..a471962 100644
--- a/src/ch/epfl/xblast/server/GameStateSerializer.java
+++ b/src/ch/epfl/xblast/server/GameStateSerializer.java
@@ -109,9 +109,9 @@ public final class GameStateSerializer {
109 * @return the serialized players 109 * @return the serialized players
110 */ 110 */
111 private static List<Byte> serializePlayers(List<Player> players, int tick) { 111 private static List<Byte> serializePlayers(List<Player> players, int tick) {
112 return players.stream() 112 return Collections.unmodifiableList(players.stream()
113 .flatMap(p -> serializePlayer(p, tick).stream()) 113 .flatMap(p -> serializePlayer(p, tick).stream())
114 .collect(Collectors.toList()); 114 .collect(Collectors.toList()));
115 } 115 }
116 116
117 /** 117 /**
@@ -142,12 +142,12 @@ public final class GameStateSerializer {
142 * @return the serialized GameState 142 * @return the serialized GameState
143 */ 143 */
144 public static List<Byte> serialize(BoardPainter bp, GameState gs) { 144 public static List<Byte> serialize(BoardPainter bp, GameState gs) {
145 return Stream.of( 145 return Collections.unmodifiableList(Stream.of(
146 prependSize(serializeBoard(bp, gs.board())), 146 prependSize(serializeBoard(bp, gs.board())),
147 prependSize(serializeExplosions(gs.bombedCells(), gs.blastedCells(), gs.board())), 147 prependSize(serializeExplosions(gs.bombedCells(), gs.blastedCells(), gs.board())),
148 serializePlayers(gs.players(), gs.ticks()), 148 serializePlayers(gs.players(), gs.ticks()),
149 serializeRemainingTime(gs.remainingTime()) 149 serializeRemainingTime(gs.remainingTime())
150 ).flatMap(List::stream).collect(Collectors.toList()); 150 ).flatMap(List::stream).collect(Collectors.toList()));
151 } 151 }
152 152
153} 153}