mirror of
https://github.com/androidx/media.git
synced 2025-05-12 10:09:55 +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()}.
|
||||
* @param actionOnCompletion A {@link Runnable} which is executed immediately after the media
|
||||
* 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}
|
||||
*/
|
||||
public final synchronized void removeMediaSourceRange(
|
||||
|
@ -253,12 +253,21 @@ public final class Util {
|
||||
/**
|
||||
* 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 fromIndex The first index to be removed (inclusive).
|
||||
* @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) {
|
||||
list.subList(fromIndex, toIndex).clear();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user