Make SegmentDownloadAction constructor keys parameter simpler
Removed option to pass null keys parameter. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=185134822
This commit is contained in:
parent
4916baabf0
commit
2c2aaf0a4b
@ -40,16 +40,11 @@ public abstract class SegmentDownloadAction<K> extends DownloadAction {
|
|||||||
public DownloadAction readFromStream(int version, DataInputStream input) throws IOException {
|
public DownloadAction readFromStream(int version, DataInputStream input) throws IOException {
|
||||||
Uri manifestUri = Uri.parse(input.readUTF());
|
Uri manifestUri = Uri.parse(input.readUTF());
|
||||||
String data = input.readUTF();
|
String data = input.readUTF();
|
||||||
|
boolean removeAction = input.readBoolean();
|
||||||
int keyCount = input.readInt();
|
int keyCount = input.readInt();
|
||||||
boolean removeAction = keyCount == -1;
|
K[] keys = createKeyArray(keyCount);
|
||||||
K[] keys;
|
for (int i = 0; i < keyCount; i++) {
|
||||||
if (removeAction) {
|
keys[i] = readKey(input);
|
||||||
keys = null;
|
|
||||||
} else {
|
|
||||||
keys = createKeyArray(keyCount);
|
|
||||||
for (int i = 0; i < keyCount; i++) {
|
|
||||||
keys[i] = readKey(input);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return createDownloadAction(manifestUri, removeAction, data, keys);
|
return createDownloadAction(manifestUri, removeAction, data, keys);
|
||||||
}
|
}
|
||||||
@ -74,12 +69,15 @@ public abstract class SegmentDownloadAction<K> extends DownloadAction {
|
|||||||
* @param manifestUri The {@link Uri} of the manifest to be downloaded.
|
* @param manifestUri The {@link Uri} of the manifest to be downloaded.
|
||||||
* @param removeAction Whether the data will be removed. If {@code false} it will be downloaded.
|
* @param removeAction Whether the data will be removed. If {@code false} it will be downloaded.
|
||||||
* @param data Optional custom data for this action. If null, an empty string is used.
|
* @param data Optional custom data for this action. If null, an empty string is used.
|
||||||
* @param keys Keys of representations to be downloaded. If empty or null, all representations are
|
* @param keys Keys of representations to be downloaded. If empty, all representations are
|
||||||
* downloaded. If {@code removeAction} is true, this is ignored.
|
* downloaded. If {@code removeAction} is true, {@code keys} should be an empty array.
|
||||||
*/
|
*/
|
||||||
protected SegmentDownloadAction(Uri manifestUri, boolean removeAction, String data, K[] keys) {
|
protected SegmentDownloadAction(Uri manifestUri, boolean removeAction, String data, K[] keys) {
|
||||||
super(data);
|
super(data);
|
||||||
Assertions.checkArgument(!removeAction || keys == null || keys.length == 0);
|
Assertions.checkNotNull(keys);
|
||||||
|
if (removeAction) {
|
||||||
|
Assertions.checkArgument(keys.length == 0);
|
||||||
|
}
|
||||||
this.manifestUri = manifestUri;
|
this.manifestUri = manifestUri;
|
||||||
this.keys = keys;
|
this.keys = keys;
|
||||||
this.removeAction = removeAction;
|
this.removeAction = removeAction;
|
||||||
@ -94,13 +92,10 @@ public abstract class SegmentDownloadAction<K> extends DownloadAction {
|
|||||||
public final void writeToStream(DataOutputStream output) throws IOException {
|
public final void writeToStream(DataOutputStream output) throws IOException {
|
||||||
output.writeUTF(manifestUri.toString());
|
output.writeUTF(manifestUri.toString());
|
||||||
output.writeUTF(getData());
|
output.writeUTF(getData());
|
||||||
if (isRemoveAction()) {
|
output.writeBoolean(removeAction);
|
||||||
output.writeInt(-1);
|
output.writeInt(keys.length);
|
||||||
} else {
|
for (K key : keys) {
|
||||||
output.writeInt(keys.length);
|
writeKey(output, key);
|
||||||
for (K key : keys) {
|
|
||||||
writeKey(output, key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,11 +119,9 @@ public abstract class SegmentDownloadAction<K> extends DownloadAction {
|
|||||||
}
|
}
|
||||||
SegmentDownloadAction<?> that = (SegmentDownloadAction<?>) o;
|
SegmentDownloadAction<?> that = (SegmentDownloadAction<?>) o;
|
||||||
return manifestUri.equals(that.manifestUri)
|
return manifestUri.equals(that.manifestUri)
|
||||||
&& (keys == null || keys.length == 0
|
&& removeAction == that.removeAction
|
||||||
? (that.keys == null || that.keys.length == 0)
|
&& keys.length == that.keys.length
|
||||||
: (that.keys != null
|
&& Arrays.asList(keys).containsAll(Arrays.asList(that.keys));
|
||||||
&& that.keys.length == keys.length
|
|
||||||
&& Arrays.asList(keys).containsAll(Arrays.asList(that.keys))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -101,10 +101,10 @@ public abstract class SegmentDownloader<M, K> implements Downloader {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Selects multiple representations pointed to by the keys for downloading, checking status. Any
|
* Selects multiple representations pointed to by the keys for downloading, checking status. Any
|
||||||
* previous selection is cleared. If keys are null or empty, all representations are downloaded.
|
* previous selection is cleared. If keys array is empty, all representations are downloaded.
|
||||||
*/
|
*/
|
||||||
public final void selectRepresentations(K[] keys) {
|
public final void selectRepresentations(K[] keys) {
|
||||||
this.keys = (keys != null && keys.length > 0) ? keys.clone() : null;
|
this.keys = keys.length > 0 ? keys.clone() : null;
|
||||||
resetCounters();
|
resetCounters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,11 +184,6 @@ public class DashDownloaderTest extends InstrumentationTestCase {
|
|||||||
// select something random
|
// select something random
|
||||||
dashDownloader.selectRepresentations(new RepresentationKey[] {new RepresentationKey(0, 0, 0)});
|
dashDownloader.selectRepresentations(new RepresentationKey[] {new RepresentationKey(0, 0, 0)});
|
||||||
// clear selection
|
// clear selection
|
||||||
dashDownloader.selectRepresentations(null);
|
|
||||||
dashDownloader.download(null);
|
|
||||||
assertCachedData(cache, fakeDataSet);
|
|
||||||
dashDownloader.remove();
|
|
||||||
|
|
||||||
dashDownloader.selectRepresentations(new RepresentationKey[0]);
|
dashDownloader.selectRepresentations(new RepresentationKey[0]);
|
||||||
dashDownloader.download(null);
|
dashDownloader.download(null);
|
||||||
assertCachedData(cache, fakeDataSet);
|
assertCachedData(cache, fakeDataSet);
|
||||||
|
@ -156,11 +156,6 @@ public class HlsDownloaderTest extends InstrumentationTestCase {
|
|||||||
// select something random
|
// select something random
|
||||||
hlsDownloader.selectRepresentations(new String[] {MEDIA_PLAYLIST_1_URI});
|
hlsDownloader.selectRepresentations(new String[] {MEDIA_PLAYLIST_1_URI});
|
||||||
// clear selection
|
// clear selection
|
||||||
hlsDownloader.selectRepresentations(null);
|
|
||||||
hlsDownloader.download(null);
|
|
||||||
assertCachedData(cache, fakeDataSet);
|
|
||||||
hlsDownloader.remove();
|
|
||||||
|
|
||||||
hlsDownloader.selectRepresentations(new String[0]);
|
hlsDownloader.selectRepresentations(new String[0]);
|
||||||
hlsDownloader.download(null);
|
hlsDownloader.download(null);
|
||||||
assertCachedData(cache, fakeDataSet);
|
assertCachedData(cache, fakeDataSet);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user