mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-07-07 12:32:59 +00:00
getAudioIndexByHighestRank: simplify & make list NonNull
This commit is contained in:
parent
64c68cf2f1
commit
e0cbddfe54
@ -98,7 +98,7 @@ public final class ListHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getDefaultAudioFormat(final Context context,
|
public static int getDefaultAudioFormat(final Context context,
|
||||||
final List<AudioStream> audioStreams) {
|
@NonNull final List<AudioStream> audioStreams) {
|
||||||
return getAudioIndexByHighestRank(audioStreams,
|
return getAudioIndexByHighestRank(audioStreams,
|
||||||
getAudioTrackComparator(context).thenComparing(getAudioFormatComparator(context)));
|
getAudioTrackComparator(context).thenComparing(getAudioFormatComparator(context)));
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ public final class ListHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getAudioFormatIndex(final Context context,
|
public static int getAudioFormatIndex(final Context context,
|
||||||
final List<AudioStream> audioStreams,
|
@NonNull final List<AudioStream> audioStreams,
|
||||||
@Nullable final String trackId) {
|
@Nullable final String trackId) {
|
||||||
if (trackId != null) {
|
if (trackId != null) {
|
||||||
for (int i = 0; i < audioStreams.size(); i++) {
|
for (int i = 0; i < audioStreams.size(); i++) {
|
||||||
@ -263,6 +263,7 @@ public final class ListHelper {
|
|||||||
* @param audioStreams the list of audio streams
|
* @param audioStreams the list of audio streams
|
||||||
* @return the sorted, filtered list
|
* @return the sorted, filtered list
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
public static List<AudioStream> getFilteredAudioStreams(
|
public static List<AudioStream> getFilteredAudioStreams(
|
||||||
@NonNull final Context context,
|
@NonNull final Context context,
|
||||||
@Nullable final List<AudioStream> audioStreams) {
|
@Nullable final List<AudioStream> audioStreams) {
|
||||||
@ -535,16 +536,12 @@ public final class ListHelper {
|
|||||||
* @param comparator The comparator used for determining the max/best/highest ranked value
|
* @param comparator The comparator used for determining the max/best/highest ranked value
|
||||||
* @return Index of audio stream that produces the highest ranked result or -1 if not found
|
* @return Index of audio stream that produces the highest ranked result or -1 if not found
|
||||||
*/
|
*/
|
||||||
static int getAudioIndexByHighestRank(@Nullable final List<AudioStream> audioStreams,
|
static int getAudioIndexByHighestRank(@NonNull final List<AudioStream> audioStreams,
|
||||||
final Comparator<AudioStream> comparator) {
|
final Comparator<AudioStream> comparator) {
|
||||||
if (audioStreams == null || audioStreams.isEmpty()) {
|
return audioStreams.stream()
|
||||||
return -1;
|
.max(comparator)
|
||||||
}
|
.map(audioStreams::indexOf)
|
||||||
|
.orElse(-1);
|
||||||
final AudioStream highestRankedAudioStream = audioStreams.stream()
|
|
||||||
.max(comparator).orElse(null);
|
|
||||||
|
|
||||||
return audioStreams.indexOf(highestRankedAudioStream);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -230,7 +230,7 @@ public class StreamItemAdapter<T extends Stream, U extends Stream> extends BaseA
|
|||||||
new StreamInfoWrapper<>(Collections.emptyList(), null);
|
new StreamInfoWrapper<>(Collections.emptyList(), null);
|
||||||
private static final int SIZE_UNSET = -2;
|
private static final int SIZE_UNSET = -2;
|
||||||
|
|
||||||
private final List<T> streamsList;
|
@NonNull private final List<T> streamsList;
|
||||||
private final long[] streamSizes;
|
private final long[] streamSizes;
|
||||||
private final MediaFormat[] streamFormats;
|
private final MediaFormat[] streamFormats;
|
||||||
private final String unknownSize;
|
private final String unknownSize;
|
||||||
@ -432,6 +432,7 @@ public class StreamItemAdapter<T extends Stream, U extends Stream> extends BaseA
|
|||||||
return (StreamInfoWrapper<X>) EMPTY;
|
return (StreamInfoWrapper<X>) EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public List<T> getStreamsList() {
|
public List<T> getStreamsList() {
|
||||||
return streamsList;
|
return streamsList;
|
||||||
}
|
}
|
||||||
|
@ -279,7 +279,6 @@ public class ListHelperTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getHighestQualityAudioNull() {
|
public void getHighestQualityAudioNull() {
|
||||||
final Comparator<AudioStream> cmp = ListHelper.getAudioFormatComparator(null, false);
|
final Comparator<AudioStream> cmp = ListHelper.getAudioFormatComparator(null, false);
|
||||||
assertEquals(-1, ListHelper.getAudioIndexByHighestRank(null, cmp));
|
|
||||||
assertEquals(-1, ListHelper.getAudioIndexByHighestRank(new ArrayList<>(), cmp));
|
assertEquals(-1, ListHelper.getAudioIndexByHighestRank(new ArrayList<>(), cmp));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,7 +355,6 @@ public class ListHelperTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getLowestQualityAudioNull() {
|
public void getLowestQualityAudioNull() {
|
||||||
final Comparator<AudioStream> cmp = ListHelper.getAudioFormatComparator(null, false);
|
final Comparator<AudioStream> cmp = ListHelper.getAudioFormatComparator(null, false);
|
||||||
assertEquals(-1, ListHelper.getAudioIndexByHighestRank(null, cmp));
|
|
||||||
assertEquals(-1, ListHelper.getAudioIndexByHighestRank(new ArrayList<>(), cmp));
|
assertEquals(-1, ListHelper.getAudioIndexByHighestRank(new ArrayList<>(), cmp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user