Skip to content

Commit

Permalink
Add Timeline to nullness check
Browse files Browse the repository at this point in the history
This allows client code to run nullability checks.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=221437215
  • Loading branch information
AquilesCanta authored and ojw28 committed Nov 14, 2018
1 parent 866b088 commit 76eb06d
Showing 1 changed file with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -299,16 +307,22 @@ 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);
}

/**
* 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.
Expand All @@ -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,
Expand Down Expand Up @@ -704,7 +718,9 @@ public final boolean isLastPeriod(int periodIndex, Period period, Window window,
*/
public final Pair<Object, Long> 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));
}

/**
Expand All @@ -721,6 +737,7 @@ public final Pair<Object, Long> 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<Object, Long> getPeriodPosition(
Window window,
Period period,
Expand All @@ -743,7 +760,7 @@ public final Pair<Object, Long> getPeriodPosition(
periodPositionUs -= periodDurationUs;
periodDurationUs = getPeriod(++periodIndex, period, /* setIds= */ true).getDurationUs();
}
return Pair.create(period.uid, periodPositionUs);
return Pair.create(Assertions.checkNotNull(period.uid), periodPositionUs);
}

/**
Expand All @@ -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.
Expand Down

0 comments on commit 76eb06d

Please sign in to comment.