From bbd1aa31fbec7b46cb2c3a53e43101dbfa40897a Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Thu, 5 May 2016 21:19:28 +0200 Subject: Enforce immutability --- src/ch/epfl/xblast/RunLengthEncoder.java | 10 +++++----- src/ch/epfl/xblast/server/GameStateSerializer.java | 8 ++++---- 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 { public static List encode(List bl) { List rll = bl.stream().map(RunLength::new).collect(Collectors.toList()); - return collapseRunLengths(rll).stream() + return Collections.unmodifiableList(collapseRunLengths(rll).stream() .flatMap(rl -> rl.split().stream()) .flatMap(rl -> rl.encode().stream()) - .collect(Collectors.toList()); + .collect(Collectors.toList())); } /** @@ -184,9 +184,9 @@ public final class RunLengthEncoder { * @return the decoded byte sequence */ public static List decode(List el) { - return decodeRunLengths(el).stream() + return Collections.unmodifiableList(decodeRunLengths(el).stream() .flatMap(rl -> rl.expand().stream()) - .collect(Collectors.toList()); + .collect(Collectors.toList())); } -} \ No newline at end of file +} 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 { * @return the serialized players */ private static List serializePlayers(List players, int tick) { - return players.stream() + return Collections.unmodifiableList(players.stream() .flatMap(p -> serializePlayer(p, tick).stream()) - .collect(Collectors.toList()); + .collect(Collectors.toList())); } /** @@ -142,12 +142,12 @@ public final class GameStateSerializer { * @return the serialized GameState */ public static List serialize(BoardPainter bp, GameState gs) { - return Stream.of( + return Collections.unmodifiableList(Stream.of( prependSize(serializeBoard(bp, gs.board())), prependSize(serializeExplosions(gs.bombedCells(), gs.blastedCells(), gs.board())), serializePlayers(gs.players(), gs.ticks()), serializeRemainingTime(gs.remainingTime()) - ).flatMap(List::stream).collect(Collectors.toList()); + ).flatMap(List::stream).collect(Collectors.toList())); } } -- cgit v1.2.3