From 76eb06d6f2e6cd3fe605878bb3880b87ec1c9c7e Mon Sep 17 00:00:00 2001 From: aquilescanta Date: Wed, 14 Nov 2018 06:58:42 -0800 Subject: [PATCH] Add Timeline to nullness check This allows client code to run nullability checks. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=221437215 --- .../google/android/exoplayer2/Timeline.java | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/Timeline.java b/library/core/src/main/java/com/google/android/exoplayer2/Timeline.java index 61a31f7db5c..14769a17e51 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/Timeline.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/Timeline.java @@ -120,7 +120,7 @@ public abstract class Timeline { public static final class Window { /** A tag for the window. Not necessarily unique. */ - public @Nullable Object tag; + @Nullable public Object tag; /** * The start time of the presentation to which this window belongs in milliseconds since the @@ -264,14 +264,15 @@ public long getPositionInFirstPeriodUs() { public static final class Period { /** - * An identifier for the period. Not necessarily unique. + * An identifier for the period. Not necessarily unique. May be null if the ids of the period + * are not required. */ - public Object id; + @Nullable public Object id; /** - * A unique identifier for the period. + * A unique identifier for the period. May be null if the ids of the period are not required. */ - public Object uid; + @Nullable public Object uid; /** * The index of the window to which this period belongs. @@ -286,11 +287,18 @@ public static final class Period { private long positionInWindowUs; private AdPlaybackState adPlaybackState; + /** Creates a new instance with no ad playback state. */ + public Period() { + adPlaybackState = AdPlaybackState.NONE; + } + /** * Sets the data held by this period. * - * @param id An identifier for the period. Not necessarily unique. - * @param uid A unique identifier for the period. + * @param id An identifier for the period. Not necessarily unique. May be null if the ids of the + * period are not required. + * @param uid A unique identifier for the period. May be null if the ids of the period are not + * required. * @param windowIndex The index of the window to which this period belongs. * @param durationUs The duration of this period in microseconds, or {@link C#TIME_UNSET} if * unknown. @@ -299,7 +307,11 @@ public static final class Period { * period is not within the window. * @return This period, for convenience. */ - public Period set(Object id, Object uid, int windowIndex, long durationUs, + public Period set( + @Nullable Object id, + @Nullable Object uid, + int windowIndex, + long durationUs, long positionInWindowUs) { return set(id, uid, windowIndex, durationUs, positionInWindowUs, AdPlaybackState.NONE); } @@ -307,8 +319,10 @@ public Period set(Object id, Object uid, int windowIndex, long durationUs, /** * Sets the data held by this period. * - * @param id An identifier for the period. Not necessarily unique. - * @param uid A unique identifier for the period. + * @param id An identifier for the period. Not necessarily unique. May be null if the ids of the + * period are not required. + * @param uid A unique identifier for the period. May be null if the ids of the period are not + * required. * @param windowIndex The index of the window to which this period belongs. * @param durationUs The duration of this period in microseconds, or {@link C#TIME_UNSET} if * unknown. @@ -320,8 +334,8 @@ public Period set(Object id, Object uid, int windowIndex, long durationUs, * @return This period, for convenience. */ public Period set( - Object id, - Object uid, + @Nullable Object id, + @Nullable Object uid, int windowIndex, long durationUs, long positionInWindowUs, @@ -704,7 +718,9 @@ public final boolean isLastPeriod(int periodIndex, Period period, Window window, */ public final Pair getPeriodPosition( Window window, Period period, int windowIndex, long windowPositionUs) { - return getPeriodPosition(window, period, windowIndex, windowPositionUs, 0); + return Assertions.checkNotNull( + getPeriodPosition( + window, period, windowIndex, windowPositionUs, /* defaultPositionProjectionUs= */ 0)); } /** @@ -721,6 +737,7 @@ public final Pair getPeriodPosition( * is {@link C#TIME_UNSET}, {@code defaultPositionProjectionUs} is non-zero, and the window's * position could not be projected by {@code defaultPositionProjectionUs}. */ + @Nullable public final Pair getPeriodPosition( Window window, Period period, @@ -743,7 +760,7 @@ public final Pair getPeriodPosition( periodPositionUs -= periodDurationUs; periodDurationUs = getPeriod(++periodIndex, period, /* setIds= */ true).getDurationUs(); } - return Pair.create(period.uid, periodPositionUs); + return Pair.create(Assertions.checkNotNull(period.uid), periodPositionUs); } /** @@ -758,8 +775,8 @@ public Period getPeriodByUid(Object periodUid, Period period) { } /** - * Populates a {@link Period} with data for the period at the specified index. Does not populate - * {@link Period#id} and {@link Period#uid}. + * Populates a {@link Period} with data for the period at the specified index. {@link Period#id} + * and {@link Period#uid} will be set to null. * * @param periodIndex The index of the period. * @param period The {@link Period} to populate. Must not be null.