diff options
author | Pacien TRAN-GIRARD | 2016-05-09 12:25:37 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2016-05-09 12:25:37 +0200 |
commit | 94f800ca9aee0ec3f0803bbf92068b5c4645a260 (patch) | |
tree | bf8f03f9004db53e87325fc8df3358a086f25591 /src/ch | |
parent | 913812c2d7a560979aaf82e0ff7ceba0390baf96 (diff) | |
download | xblast-94f800ca9aee0ec3f0803bbf92068b5c4645a260.tar.gz |
Avoid parametrized varargs
Diffstat (limited to 'src/ch')
-rw-r--r-- | src/ch/epfl/xblast/Lists.java | 16 | ||||
-rw-r--r-- | src/ch/epfl/xblast/client/painter/TimeLinePainter.java | 5 | ||||
-rw-r--r-- | src/ch/epfl/xblast/server/GameStateSerializer.java | 4 |
3 files changed, 19 insertions, 6 deletions
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 { | |||
130 | * @param lists the lists to concatenate | 130 | * @param lists the lists to concatenate |
131 | * @param <T> the type of the list's elements | 131 | * @param <T> the type of the list's elements |
132 | * @return the list result of the concatenation | 132 | * @return the list result of the concatenation |
133 | * @deprecated Use List<T> concatenated(List<List<T>> lists) instead to avoid parametrized varargs. | ||
133 | */ | 134 | */ |
134 | public static <T> List<T> concatenated(List<T>... lists) { | 135 | public static <T> List<T> concatenated(List<T>... lists) { |
136 | return concatenated(Arrays.asList(lists)); | ||
137 | } | ||
138 | |||
139 | /** | ||
140 | * Returns an immutable copy of the given lists, concatenated. | ||
141 | * | ||
142 | * @param lists the lists to concatenate | ||
143 | * @param <T> the type of the list's elements | ||
144 | * @return the list result of the concatenation | ||
145 | */ | ||
146 | public static <T> List<T> concatenated(List<List<T>> lists) { | ||
135 | return Collections.unmodifiableList( | 147 | return Collections.unmodifiableList( |
136 | Stream.of(lists) | 148 | lists.stream() |
137 | .map(List::stream) | 149 | .map(List::stream) |
138 | .reduce(Stream::concat).orElse(Stream.empty()) | 150 | .reduce(Stream::concat).orElseGet(Stream::empty) |
139 | .collect(Collectors.toList())); | 151 | .collect(Collectors.toList())); |
140 | } | 152 | } |
141 | 153 | ||
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; | |||
5 | import ch.epfl.xblast.server.Ticks; | 5 | import ch.epfl.xblast.server.Ticks; |
6 | 6 | ||
7 | import java.awt.*; | 7 | import java.awt.*; |
8 | import java.util.Arrays; | ||
8 | import java.util.Collections; | 9 | import java.util.Collections; |
9 | import java.util.List; | 10 | import java.util.List; |
10 | 11 | ||
@@ -31,9 +32,9 @@ public class TimeLinePainter { | |||
31 | * @return the list of images composing the time "line" | 32 | * @return the list of images composing the time "line" |
32 | */ | 33 | */ |
33 | public static List<Image> buildTimeLine(int t) { | 34 | public static List<Image> buildTimeLine(int t) { |
34 | return Lists.concatenated( | 35 | return Lists.concatenated(Arrays.asList( |
35 | Collections.nCopies(t, LED_ON_IMG), | 36 | Collections.nCopies(t, LED_ON_IMG), |
36 | Collections.nCopies(TIME_LINE_SIZE - t, LED_OFF_IMG)); | 37 | Collections.nCopies(TIME_LINE_SIZE - t, LED_OFF_IMG))); |
37 | } | 38 | } |
38 | 39 | ||
39 | } | 40 | } |
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 { | |||
143 | * @return the serialized GameState | 143 | * @return the serialized GameState |
144 | */ | 144 | */ |
145 | public static List<Byte> serialize(BoardPainter bp, GameState gs) { | 145 | public static List<Byte> serialize(BoardPainter bp, GameState gs) { |
146 | return Lists.concatenated( | 146 | return Lists.concatenated(Arrays.asList( |
147 | compress(serializeBoard(bp, gs.board())), | 147 | compress(serializeBoard(bp, gs.board())), |
148 | compress(serializeExplosions(gs.bombedCells(), gs.blastedCells(), gs.board())), | 148 | compress(serializeExplosions(gs.bombedCells(), gs.blastedCells(), gs.board())), |
149 | serializePlayers(gs.players(), gs.ticks()), | 149 | serializePlayers(gs.players(), gs.ticks()), |
150 | serializeRemainingTime(gs.remainingTime())); | 150 | serializeRemainingTime(gs.remainingTime()))); |
151 | } | 151 | } |
152 | 152 | ||
153 | } | 153 | } |