aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ch/epfl/xblast/Lists.java15
-rw-r--r--src/ch/epfl/xblast/server/GameStateSerializer.java6
2 files changed, 17 insertions, 4 deletions
diff --git a/src/ch/epfl/xblast/Lists.java b/src/ch/epfl/xblast/Lists.java
index b943162..073e0cc 100644
--- a/src/ch/epfl/xblast/Lists.java
+++ b/src/ch/epfl/xblast/Lists.java
@@ -152,4 +152,19 @@ public final class Lists {
152 return new ArrayList<>(l.subList(n, l.size())); 152 return new ArrayList<>(l.subList(n, l.size()));
153 } 153 }
154 154
155 /**
156 * Returns an immutable copy of the given lists, concatenated.
157 *
158 * @param lists the lists to concatenate
159 * @param <T> the type of the list's elements
160 * @return the list result of the concatenation
161 */
162 public static <T> List<T> concatenated(List<T>... lists) {
163 return Collections.unmodifiableList(
164 Stream.of(lists)
165 .map(List::stream)
166 .reduce(Stream::concat).orElse(Stream.empty())
167 .collect(Collectors.toList()));
168 }
169
155} 170}
diff --git a/src/ch/epfl/xblast/server/GameStateSerializer.java b/src/ch/epfl/xblast/server/GameStateSerializer.java
index a24ed95..df448a5 100644
--- a/src/ch/epfl/xblast/server/GameStateSerializer.java
+++ b/src/ch/epfl/xblast/server/GameStateSerializer.java
@@ -10,7 +10,6 @@ import ch.epfl.xblast.server.painter.PlayerPainter;
10 10
11import java.util.*; 11import java.util.*;
12import java.util.stream.Collectors; 12import java.util.stream.Collectors;
13import java.util.stream.Stream;
14 13
15/** 14/**
16 * The game state serializer that serializes a GameState into a byte sequence 15 * The game state serializer that serializes a GameState into a byte sequence
@@ -144,12 +143,11 @@ public final class GameStateSerializer {
144 * @return the serialized GameState 143 * @return the serialized GameState
145 */ 144 */
146 public static List<Byte> serialize(BoardPainter bp, GameState gs) { 145 public static List<Byte> serialize(BoardPainter bp, GameState gs) {
147 return Collections.unmodifiableList(Stream.of( 146 return Lists.concatenated(
148 compress(serializeBoard(bp, gs.board())), 147 compress(serializeBoard(bp, gs.board())),
149 compress(serializeExplosions(gs.bombedCells(), gs.blastedCells(), gs.board())), 148 compress(serializeExplosions(gs.bombedCells(), gs.blastedCells(), gs.board())),
150 serializePlayers(gs.players(), gs.ticks()), 149 serializePlayers(gs.players(), gs.ticks()),
151 serializeRemainingTime(gs.remainingTime()) 150 serializeRemainingTime(gs.remainingTime()));
152 ).flatMap(List::stream).collect(Collectors.toList()));
153 } 151 }
154 152
155} 153}