Skip to content

Commit

Permalink
Suppress rawtypes warning when instantiating generic array
Browse files Browse the repository at this point in the history
Change FakeAdaptiveMediaPeriod back to this style for consistency.

PiperOrigin-RevId: 284967667
  • Loading branch information
ojw28 committed Dec 11, 2019
1 parent 6ebc9f9 commit a4a9cc9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@ private static Format buildCea608TrackFormat(
/* initializationData= */ null);
}

@SuppressWarnings("unchecked")
// We won't assign the array to a variable that erases the generic type, and then write into it.
@SuppressWarnings({"unchecked", "rawtypes"})
private static ChunkSampleStream<DashChunkSource>[] newSampleStreamArray(int length) {
return new ChunkSampleStream[length];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ private static TrackGroupArray buildTrackGroups(
return new TrackGroupArray(trackGroups);
}

@SuppressWarnings("unchecked")
// We won't assign the array to a variable that erases the generic type, and then write into it.
@SuppressWarnings({"unchecked", "rawtypes"})
private static ChunkSampleStream<SsChunkSource>[] newSampleStreamArray(int length) {
return new ChunkSampleStream[length];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
private final long durationUs;

private Callback callback;
private List<ChunkSampleStream<FakeChunkSource>> sampleStreams;
private ChunkSampleStream<FakeChunkSource>[] sampleStreams;
private SequenceableLoader sequenceableLoader;

public FakeAdaptiveMediaPeriod(
Expand All @@ -60,7 +60,7 @@ public FakeAdaptiveMediaPeriod(
this.chunkSourceFactory = chunkSourceFactory;
this.transferListener = transferListener;
this.durationUs = durationUs;
this.sampleStreams = new ArrayList<>();
this.sampleStreams = newSampleStreamArray(0);
this.sequenceableLoader = new CompositeSequenceableLoader(new SequenceableLoader[0]);
}

Expand Down Expand Up @@ -94,9 +94,8 @@ public long selectTracks(
validStreams.add((ChunkSampleStream<FakeChunkSource>) stream);
}
}
this.sampleStreams = validStreams;
this.sequenceableLoader =
new CompositeSequenceableLoader(sampleStreams.toArray(new SequenceableLoader[0]));
this.sampleStreams = validStreams.toArray(newSampleStreamArray(validStreams.size()));
this.sequenceableLoader = new CompositeSequenceableLoader(sampleStreams);
return returnPositionUs;
}

Expand Down Expand Up @@ -166,4 +165,10 @@ protected SampleStream createSampleStream(TrackSelection trackSelection) {
public void onContinueLoadingRequested(ChunkSampleStream<FakeChunkSource> source) {
callback.onContinueLoadingRequested(this);
}

// We won't assign the array to a variable that erases the generic type, and then write into it.
@SuppressWarnings({"unchecked", "rawtypes"})
private static ChunkSampleStream<FakeChunkSource>[] newSampleStreamArray(int length) {
return new ChunkSampleStream[length];
}
}

0 comments on commit a4a9cc9

Please sign in to comment.