mirror of
https://github.com/androidx/media.git
synced 2025-05-13 02:29:52 +08:00
Explicitly document empty range removal in Util.removeRange.
Also prevent an unnecessary allocation when the removed range is empty. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=212993427
This commit is contained in:
parent
1284f9ea4d
commit
caa46d49e5
@ -313,7 +313,7 @@ public class ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHo
|
|||||||
* untouched. This index must be in the range of 0 <= index <= {@link #getSize()}.
|
* untouched. This index must be in the range of 0 <= index <= {@link #getSize()}.
|
||||||
* @param actionOnCompletion A {@link Runnable} which is executed immediately after the media
|
* @param actionOnCompletion A {@link Runnable} which is executed immediately after the media
|
||||||
* source range has been removed from the playlist.
|
* source range has been removed from the playlist.
|
||||||
* @throws IndexOutOfBoundsException When the range is malformed, i.e. {@code fromIndex} < 0,
|
* @throws IllegalArgumentException When the range is malformed, i.e. {@code fromIndex} < 0,
|
||||||
* {@code toIndex} > {@link #getSize()}, {@code fromIndex} > {@code toIndex}
|
* {@code toIndex} > {@link #getSize()}, {@code fromIndex} > {@code toIndex}
|
||||||
*/
|
*/
|
||||||
public final synchronized void removeMediaSourceRange(
|
public final synchronized void removeMediaSourceRange(
|
||||||
|
@ -253,13 +253,22 @@ public final class Util {
|
|||||||
/**
|
/**
|
||||||
* Removes an indexed range from a List.
|
* Removes an indexed range from a List.
|
||||||
*
|
*
|
||||||
|
* <p>Does nothing if the provided range is valid and {@code fromIndex == toIndex}.
|
||||||
|
*
|
||||||
* @param list The List to remove the range from.
|
* @param list The List to remove the range from.
|
||||||
* @param fromIndex The first index to be removed (inclusive).
|
* @param fromIndex The first index to be removed (inclusive).
|
||||||
* @param toIndex The last index to be removed (exclusive).
|
* @param toIndex The last index to be removed (exclusive).
|
||||||
|
* @throws IllegalArgumentException If {@code fromIndex} < 0, {@code toIndex} > {@code
|
||||||
|
* list.size()}, or {@code fromIndex} > {@code toIndex}.
|
||||||
*/
|
*/
|
||||||
public static <T> void removeRange(List<T> list, int fromIndex, int toIndex) {
|
public static <T> void removeRange(List<T> list, int fromIndex, int toIndex) {
|
||||||
|
if (fromIndex < 0 || toIndex > list.size() || fromIndex > toIndex) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
} else if (fromIndex != toIndex) {
|
||||||
|
// Checking index inequality prevents an unnecessary allocation.
|
||||||
list.subList(fromIndex, toIndex).clear();
|
list.subList(fromIndex, toIndex).clear();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Casts a nullable variable to a non-null variable without runtime null check.
|
* Casts a nullable variable to a non-null variable without runtime null check.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user