From 94f800ca9aee0ec3f0803bbf92068b5c4645a260 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 9 May 2016 12:25:37 +0200 Subject: Avoid parametrized varargs --- src/ch/epfl/xblast/Lists.java | 16 ++++++++++++++-- src/ch/epfl/xblast/client/painter/TimeLinePainter.java | 5 +++-- src/ch/epfl/xblast/server/GameStateSerializer.java | 4 ++-- 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'src/ch') diff --git a/src/ch/epfl/xblast/Lists.java b/src/ch/epfl/xblast/Lists.java index 3794c1e..526ebf4 100644 --- a/src/ch/epfl/xblast/Lists.java +++ b/src/ch/epfl/xblast/Lists.java @@ -130,12 +130,24 @@ public final class Lists { * @param lists the lists to concatenate * @param the type of the list's elements * @return the list result of the concatenation + * @deprecated Use List concatenated(List> lists) instead to avoid parametrized varargs. */ public static List concatenated(List... lists) { + return concatenated(Arrays.asList(lists)); + } + + /** + * Returns an immutable copy of the given lists, concatenated. + * + * @param lists the lists to concatenate + * @param the type of the list's elements + * @return the list result of the concatenation + */ + public static List concatenated(List> lists) { return Collections.unmodifiableList( - Stream.of(lists) + lists.stream() .map(List::stream) - .reduce(Stream::concat).orElse(Stream.empty()) + .reduce(Stream::concat).orElseGet(Stream::empty) .collect(Collectors.toList())); } diff --git a/src/ch/epfl/xblast/client/painter/TimeLinePainter.java b/src/ch/epfl/xblast/client/painter/TimeLinePainter.java index 7912d88..c8b0bd5 100644 --- a/src/ch/epfl/xblast/client/painter/TimeLinePainter.java +++ b/src/ch/epfl/xblast/client/painter/TimeLinePainter.java @@ -5,6 +5,7 @@ import ch.epfl.xblast.client.ImageCollection; import ch.epfl.xblast.server.Ticks; import java.awt.*; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -31,9 +32,9 @@ public class TimeLinePainter { * @return the list of images composing the time "line" */ public static List buildTimeLine(int t) { - return Lists.concatenated( + return Lists.concatenated(Arrays.asList( Collections.nCopies(t, LED_ON_IMG), - Collections.nCopies(TIME_LINE_SIZE - t, LED_OFF_IMG)); + Collections.nCopies(TIME_LINE_SIZE - t, LED_OFF_IMG))); } } diff --git a/src/ch/epfl/xblast/server/GameStateSerializer.java b/src/ch/epfl/xblast/server/GameStateSerializer.java index df448a5..b7d7758 100644 --- a/src/ch/epfl/xblast/server/GameStateSerializer.java +++ b/src/ch/epfl/xblast/server/GameStateSerializer.java @@ -143,11 +143,11 @@ public final class GameStateSerializer { * @return the serialized GameState */ public static List serialize(BoardPainter bp, GameState gs) { - return Lists.concatenated( + return Lists.concatenated(Arrays.asList( compress(serializeBoard(bp, gs.board())), compress(serializeExplosions(gs.bombedCells(), gs.blastedCells(), gs.board())), serializePlayers(gs.players(), gs.ticks()), - serializeRemainingTime(gs.remainingTime())); + serializeRemainingTime(gs.remainingTime()))); } } -- cgit v1.2.3