Merge pull request #8631 from Isira-Seneviratne/Use_collection_factories

Use Java 9 collection factories.
This commit is contained in:
Stypox 2022-07-20 14:52:18 +02:00 committed by GitHub
commit 344c33d9a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 113 additions and 165 deletions

View File

@ -14,7 +14,6 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
import org.schabi.newpipe.R;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
// See https://stackoverflow.com/questions/56849221#57997489
@ -27,7 +26,7 @@ public final class FlingBehavior extends AppBarLayout.Behavior {
private boolean allowScroll = true;
private final Rect globalRect = new Rect();
private final List<Integer> skipInterceptionOfElements = Arrays.asList(
private final List<Integer> skipInterceptionOfElements = List.of(
R.id.itemsListPanel, R.id.playbackSeekBar,
R.id.playPauseButton, R.id.playPreviousButton, R.id.playNextButton);
@ -67,7 +66,7 @@ public final class FlingBehavior extends AppBarLayout.Behavior {
public boolean onInterceptTouchEvent(@NonNull final CoordinatorLayout parent,
@NonNull final AppBarLayout child,
@NonNull final MotionEvent ev) {
for (final Integer element : skipInterceptionOfElements) {
for (final int element : skipInterceptionOfElements) {
final View view = child.findViewById(element);
if (view != null) {
final boolean visible = view.getGlobalVisibleRect(globalRect);

View File

@ -27,9 +27,8 @@ import org.schabi.newpipe.util.StateSaver;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import io.reactivex.rxjava3.exceptions.CompositeException;
import io.reactivex.rxjava3.exceptions.MissingBackpressureException;
@ -140,7 +139,7 @@ public class App extends Application {
if (throwable instanceof UndeliverableException) {
// As UndeliverableException is a wrapper,
// get the cause of it to get the "real" exception
actualThrowable = throwable.getCause();
actualThrowable = Objects.requireNonNull(throwable.getCause());
} else {
actualThrowable = throwable;
}
@ -149,7 +148,7 @@ public class App extends Application {
if (actualThrowable instanceof CompositeException) {
errors = ((CompositeException) actualThrowable).getExceptions();
} else {
errors = Collections.singletonList(actualThrowable);
errors = List.of(actualThrowable);
}
for (final Throwable error : errors) {
@ -213,41 +212,37 @@ public class App extends Application {
private void initNotificationChannels() {
// Keep the importance below DEFAULT to avoid making noise on every notification update for
// the main and update channels
final List<NotificationChannelCompat> notificationChannelCompats = new ArrayList<>();
notificationChannelCompats.add(new NotificationChannelCompat
.Builder(getString(R.string.notification_channel_id),
final List<NotificationChannelCompat> notificationChannelCompats = List.of(
new NotificationChannelCompat.Builder(getString(R.string.notification_channel_id),
NotificationManagerCompat.IMPORTANCE_LOW)
.setName(getString(R.string.notification_channel_name))
.setDescription(getString(R.string.notification_channel_description))
.build());
notificationChannelCompats.add(new NotificationChannelCompat
.Builder(getString(R.string.app_update_notification_channel_id),
.setName(getString(R.string.notification_channel_name))
.setDescription(getString(R.string.notification_channel_description))
.build(),
new NotificationChannelCompat
.Builder(getString(R.string.app_update_notification_channel_id),
NotificationManagerCompat.IMPORTANCE_LOW)
.setName(getString(R.string.app_update_notification_channel_name))
.setDescription(getString(R.string.app_update_notification_channel_description))
.build());
notificationChannelCompats.add(new NotificationChannelCompat
.Builder(getString(R.string.hash_channel_id),
.setName(getString(R.string.app_update_notification_channel_name))
.setDescription(
getString(R.string.app_update_notification_channel_description))
.build(),
new NotificationChannelCompat.Builder(getString(R.string.hash_channel_id),
NotificationManagerCompat.IMPORTANCE_HIGH)
.setName(getString(R.string.hash_channel_name))
.setDescription(getString(R.string.hash_channel_description))
.build());
notificationChannelCompats.add(new NotificationChannelCompat
.Builder(getString(R.string.error_report_channel_id),
.setName(getString(R.string.hash_channel_name))
.setDescription(getString(R.string.hash_channel_description))
.build(),
new NotificationChannelCompat.Builder(getString(R.string.error_report_channel_id),
NotificationManagerCompat.IMPORTANCE_LOW)
.setName(getString(R.string.error_report_channel_name))
.setDescription(getString(R.string.error_report_channel_description))
.build());
notificationChannelCompats.add(new NotificationChannelCompat
.Builder(getString(R.string.streams_notification_channel_id),
NotificationManagerCompat.IMPORTANCE_DEFAULT)
.setName(getString(R.string.streams_notification_channel_name))
.setDescription(getString(R.string.streams_notification_channel_description))
.build());
.setName(getString(R.string.error_report_channel_name))
.setDescription(getString(R.string.error_report_channel_description))
.build(),
new NotificationChannelCompat
.Builder(getString(R.string.streams_notification_channel_id),
NotificationManagerCompat.IMPORTANCE_DEFAULT)
.setName(getString(R.string.streams_notification_channel_name))
.setDescription(
getString(R.string.streams_notification_channel_description))
.build()
);
final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.createNotificationChannelsCompat(notificationChannelCompats);

View File

@ -16,7 +16,7 @@ import org.schabi.newpipe.player.playqueue.PlayQueueItem;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.SparseItemUtil;
import java.util.Collections;
import java.util.List;
public final class QueueItemMenuUtil {
private QueueItemMenuUtil() {
@ -53,7 +53,7 @@ public final class QueueItemMenuUtil {
case R.id.menu_item_append_playlist:
PlaylistDialog.createCorrespondingDialog(
context,
Collections.singletonList(new StreamEntity(item)),
List.of(new StreamEntity(item)),
dialog -> dialog.show(
fragmentManager,
"QueueItemMenuUtil@append_playlist"

View File

@ -81,7 +81,6 @@ import org.schabi.newpipe.views.FocusOverlayView;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import icepick.Icepick;
@ -649,7 +648,7 @@ public class RouterActivity extends AppCompatActivity {
.subscribe(
info -> PlaylistDialog.createCorrespondingDialog(
getThemeWrapperContext(),
Collections.singletonList(new StreamEntity(info)),
List.of(new StreamEntity(info)),
playlistDialog -> {
playlistDialog.setOnDismissListener(dialog -> finish());

View File

@ -114,7 +114,6 @@ import org.schabi.newpipe.util.external_communication.KoreUtils;
import org.schabi.newpipe.util.external_communication.ShareUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@ -453,7 +452,7 @@ public final class VideoDetailFragment
disposables.add(
PlaylistDialog.createCorrespondingDialog(
getContext(),
Collections.singletonList(new StreamEntity(currentInfo)),
List.of(new StreamEntity(currentInfo)),
dialog -> dialog.show(getFM(), TAG)
)
);

View File

@ -6,6 +6,7 @@ import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_UNSPECI
import android.content.Context;
import android.util.Log;
import android.util.Pair;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.ViewGroup;
@ -28,9 +29,7 @@ import org.schabi.newpipe.player.Player;
import org.schabi.newpipe.util.ThemeHelper;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.List;
import java.util.function.Supplier;
/**
@ -43,50 +42,34 @@ public final class VideoDetailPlayerCrasher {
// https://stackoverflow.com/a/54744028
private static final String TAG = "VideoDetPlayerCrasher";
private static final Map<String, Supplier<ExoPlaybackException>> AVAILABLE_EXCEPTION_TYPES =
getExceptionTypes();
private static final String DEFAULT_MSG = "Dummy";
private static final List<Pair<String, Supplier<ExoPlaybackException>>>
AVAILABLE_EXCEPTION_TYPES = List.of(
new Pair<>("Source", () -> ExoPlaybackException.createForSource(
new IOException(DEFAULT_MSG),
ERROR_CODE_BEHIND_LIVE_WINDOW
)),
new Pair<>("Renderer", () -> ExoPlaybackException.createForRenderer(
new Exception(DEFAULT_MSG),
"Dummy renderer",
0,
null,
C.FORMAT_HANDLED,
/*isRecoverable=*/false,
ERROR_CODE_DECODING_FAILED
)),
new Pair<>("Unexpected", () -> ExoPlaybackException.createForUnexpected(
new RuntimeException(DEFAULT_MSG),
ERROR_CODE_UNSPECIFIED
)),
new Pair<>("Remote", () -> ExoPlaybackException.createForRemote(DEFAULT_MSG))
);
private VideoDetailPlayerCrasher() {
// No impls
}
private static Map<String, Supplier<ExoPlaybackException>> getExceptionTypes() {
final String defaultMsg = "Dummy";
final Map<String, Supplier<ExoPlaybackException>> exceptionTypes = new LinkedHashMap<>();
exceptionTypes.put(
"Source",
() -> ExoPlaybackException.createForSource(
new IOException(defaultMsg),
ERROR_CODE_BEHIND_LIVE_WINDOW
)
);
exceptionTypes.put(
"Renderer",
() -> ExoPlaybackException.createForRenderer(
new Exception(defaultMsg),
"Dummy renderer",
0,
null,
C.FORMAT_HANDLED,
/*isRecoverable=*/false,
ERROR_CODE_DECODING_FAILED
)
);
exceptionTypes.put(
"Unexpected",
() -> ExoPlaybackException.createForUnexpected(
new RuntimeException(defaultMsg),
ERROR_CODE_UNSPECIFIED
)
);
exceptionTypes.put(
"Remote",
() -> ExoPlaybackException.createForRemote(defaultMsg)
);
return Collections.unmodifiableMap(exceptionTypes);
}
private static Context getThemeWrapperContext(final Context context) {
return new ContextThemeWrapper(
context,
@ -121,10 +104,9 @@ public final class VideoDetailPlayerCrasher {
.setNegativeButton(R.string.cancel, null)
.create();
for (final Map.Entry<String, Supplier<ExoPlaybackException>> entry
: AVAILABLE_EXCEPTION_TYPES.entrySet()) {
for (final Pair<String, Supplier<ExoPlaybackException>> entry : AVAILABLE_EXCEPTION_TYPES) {
final RadioButton radioButton = ListRadioIconItemBinding.inflate(inflater).getRoot();
radioButton.setText(entry.getKey());
radioButton.setText(entry.first);
radioButton.setChecked(false);
radioButton.setLayoutParams(
new RadioGroup.LayoutParams(
@ -133,7 +115,7 @@ public final class VideoDetailPlayerCrasher {
)
);
radioButton.setOnClickListener(v -> {
tryCrashPlayerWith(player, entry.getValue().get());
tryCrashPlayerWith(player, entry.second.get());
alertDialog.cancel();
});
binding.list.addView(radioButton);

View File

@ -20,7 +20,7 @@ import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.external_communication.KoreUtils;
import org.schabi.newpipe.util.external_communication.ShareUtils;
import java.util.Collections;
import java.util.List;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
@ -89,7 +89,7 @@ public enum StreamDialogDefaultEntry {
APPEND_PLAYLIST(R.string.add_to_playlist, (fragment, item) ->
PlaylistDialog.createCorrespondingDialog(
fragment.getContext(),
Collections.singletonList(new StreamEntity(item)),
List.of(new StreamEntity(item)),
dialog -> dialog.show(
fragment.getParentFragmentManager(),
"StreamDialogEntry@"

View File

@ -14,7 +14,6 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior;
import org.schabi.newpipe.R;
import java.util.Arrays;
import java.util.List;
public class CustomBottomSheetBehavior extends BottomSheetBehavior<FrameLayout> {
@ -25,7 +24,7 @@ public class CustomBottomSheetBehavior extends BottomSheetBehavior<FrameLayout>
Rect globalRect = new Rect();
private boolean skippingInterception = false;
private final List<Integer> skipInterceptionOfElements = Arrays.asList(
private final List<Integer> skipInterceptionOfElements = List.of(
R.id.detail_content_root_layout, R.id.relatedItemsLayout,
R.id.itemsListPanel, R.id.view_pager, R.id.tab_layout, R.id.bottomControls,
R.id.playPauseButton, R.id.playPreviousButton, R.id.playNextButton);
@ -57,7 +56,7 @@ public class CustomBottomSheetBehavior extends BottomSheetBehavior<FrameLayout>
if (getState() == BottomSheetBehavior.STATE_EXPANDED
&& event.getAction() == MotionEvent.ACTION_DOWN) {
// Without overriding scrolling will not work when user touches these elements
for (final Integer element : skipInterceptionOfElements) {
for (final int element : skipInterceptionOfElements) {
final View view = child.findViewById(element);
if (view != null) {
final boolean visible = view.getGlobalVisibleRect(globalRect);

View File

@ -30,7 +30,6 @@ import org.schabi.newpipe.player.ui.VideoPlayerUi;
import org.schabi.newpipe.util.SimpleOnSeekBarChangeListener;
import org.schabi.newpipe.util.SliderStrategy;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
@ -334,10 +333,8 @@ public class PlaybackParameterDialog extends DialogFragment {
}
private Map<Boolean, TextView> getPitchControlModeComponentMappings() {
final Map<Boolean, TextView> mappings = new HashMap<>();
mappings.put(PITCH_CTRL_MODE_PERCENT, binding.pitchControlModePercent);
mappings.put(PITCH_CTRL_MODE_SEMITONE, binding.pitchControlModeSemitone);
return mappings;
return Map.of(PITCH_CTRL_MODE_PERCENT, binding.pitchControlModePercent,
PITCH_CTRL_MODE_SEMITONE, binding.pitchControlModeSemitone);
}
private void changePitchControlMode(final boolean semitones) {
@ -407,13 +404,11 @@ public class PlaybackParameterDialog extends DialogFragment {
}
private Map<Double, TextView> getStepSizeComponentMappings() {
final Map<Double, TextView> mappings = new HashMap<>();
mappings.put(STEP_1_PERCENT_VALUE, binding.stepSizeOnePercent);
mappings.put(STEP_5_PERCENT_VALUE, binding.stepSizeFivePercent);
mappings.put(STEP_10_PERCENT_VALUE, binding.stepSizeTenPercent);
mappings.put(STEP_25_PERCENT_VALUE, binding.stepSizeTwentyFivePercent);
mappings.put(STEP_100_PERCENT_VALUE, binding.stepSizeOneHundredPercent);
return mappings;
return Map.of(STEP_1_PERCENT_VALUE, binding.stepSizeOnePercent,
STEP_5_PERCENT_VALUE, binding.stepSizeFivePercent,
STEP_10_PERCENT_VALUE, binding.stepSizeTenPercent,
STEP_25_PERCENT_VALUE, binding.stepSizeTwentyFivePercent,
STEP_100_PERCENT_VALUE, binding.stepSizeOneHundredPercent);
}
private void setStepSizeToUI(final double newStepSize) {

View File

@ -16,7 +16,7 @@ import org.schabi.newpipe.player.mediaitem.ExceptionTag;
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import androidx.annotation.NonNull;
@ -56,9 +56,7 @@ public class FailedMediaSource extends BaseMediaSource implements ManagedMediaSo
this.playQueueItem = playQueueItem;
this.error = error;
this.retryTimestamp = retryTimestamp;
this.mediaItem = ExceptionTag
.of(playQueueItem, Collections.singletonList(error))
.withExtras(this)
this.mediaItem = ExceptionTag.of(playQueueItem, List.of(error)).withExtras(this)
.asMediaItem();
}

View File

@ -16,7 +16,6 @@ import org.schabi.newpipe.player.playqueue.events.SelectEvent;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@ -264,7 +263,7 @@ public abstract class PlayQueue implements Serializable {
* @param items {@link PlayQueueItem}s to append
*/
public synchronized void append(@NonNull final PlayQueueItem... items) {
append(Arrays.asList(items));
append(List.of(items));
}
/**

View File

@ -4,20 +4,19 @@ import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public final class SinglePlayQueue extends PlayQueue {
public SinglePlayQueue(final StreamInfoItem item) {
super(0, Collections.singletonList(new PlayQueueItem(item)));
super(0, List.of(new PlayQueueItem(item)));
}
public SinglePlayQueue(final StreamInfo info) {
super(0, Collections.singletonList(new PlayQueueItem(info)));
super(0, List.of(new PlayQueueItem(info)));
}
public SinglePlayQueue(final StreamInfo info, final long startPosition) {
super(0, Collections.singletonList(new PlayQueueItem(info)));
super(0, List.of(new PlayQueueItem(info)));
getItem().setRecoveryPosition(startPosition);
}

View File

@ -3,8 +3,6 @@ package org.schabi.newpipe.settings.preferencesearch;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
@ -12,9 +10,9 @@ import java.util.stream.Stream;
public class PreferenceSearchConfiguration {
private PreferenceSearchFunction searcher = new PreferenceFuzzySearchFunction();
private final List<String> parserIgnoreElements = Collections.singletonList(
private final List<String> parserIgnoreElements = List.of(
PreferenceCategory.class.getSimpleName());
private final List<String> parserContainerElements = Arrays.asList(
private final List<String> parserContainerElements = List.of(
PreferenceCategory.class.getSimpleName(),
PreferenceScreen.class.getSimpleName());

View File

@ -3,7 +3,6 @@ package org.schabi.newpipe.settings.preferencesearch;
import androidx.annotation.NonNull;
import androidx.annotation.XmlRes;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
@ -92,11 +91,7 @@ public class PreferenceSearchItem {
}
public List<String> getAllRelevantSearchFields() {
return Arrays.asList(
getTitle(),
getSummary(),
getEntries(),
getBreadcrumbs());
return List.of(getTitle(), getSummary(), getEntries(), getBreadcrumbs());
}
@NonNull

View File

@ -10,8 +10,6 @@ import com.grack.nanojson.JsonStringWriter;
import com.grack.nanojson.JsonWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
@ -20,11 +18,10 @@ import java.util.List;
public final class TabsJsonHelper {
private static final String JSON_TABS_ARRAY_KEY = "tabs";
private static final List<Tab> FALLBACK_INITIAL_TABS_LIST = Collections.unmodifiableList(
Arrays.asList(
Tab.Type.DEFAULT_KIOSK.getTab(),
Tab.Type.SUBSCRIPTIONS.getTab(),
Tab.Type.BOOKMARKS.getTab()));
private static final List<Tab> FALLBACK_INITIAL_TABS_LIST = List.of(
Tab.Type.DEFAULT_KIOSK.getTab(),
Tab.Type.SUBSCRIPTIONS.getTab(),
Tab.Type.BOOKMARKS.getTab());
private TabsJsonHelper() { }

View File

@ -2,7 +2,6 @@ package org.schabi.newpipe.util;
import android.text.TextUtils;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@ -20,6 +19,6 @@ public final class CookieUtils {
}
public static Set<String> splitCookies(final String cookies) {
return new HashSet<>(Arrays.asList(cookies.split("; *")));
return Set.of(cookies.split("; *"));
}
}

View File

@ -22,7 +22,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@ -32,17 +31,16 @@ import java.util.stream.Collectors;
public final class ListHelper {
// Video format in order of quality. 0=lowest quality, n=highest quality
private static final List<MediaFormat> VIDEO_FORMAT_QUALITY_RANKING =
Arrays.asList(MediaFormat.v3GPP, MediaFormat.WEBM, MediaFormat.MPEG_4);
List.of(MediaFormat.v3GPP, MediaFormat.WEBM, MediaFormat.MPEG_4);
// Audio format in order of quality. 0=lowest quality, n=highest quality
private static final List<MediaFormat> AUDIO_FORMAT_QUALITY_RANKING =
Arrays.asList(MediaFormat.MP3, MediaFormat.WEBMA, MediaFormat.M4A);
List.of(MediaFormat.MP3, MediaFormat.WEBMA, MediaFormat.M4A);
// Audio format in order of efficiency. 0=most efficient, n=least efficient
private static final List<MediaFormat> AUDIO_FORMAT_EFFICIENCY_RANKING =
Arrays.asList(MediaFormat.WEBMA, MediaFormat.M4A, MediaFormat.MP3);
// Use a HashSet for better performance
private static final Set<String> HIGH_RESOLUTION_LIST = new HashSet<>(
Arrays.asList("1440p", "2160p"));
List.of(MediaFormat.WEBMA, MediaFormat.M4A, MediaFormat.MP3);
// Use a Set for better performance
private static final Set<String> HIGH_RESOLUTION_LIST = Set.of("1440p", "2160p");
private ListHelper() { }

View File

@ -17,7 +17,6 @@ import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public final class PeertubeHelper {
@ -29,7 +28,7 @@ public final class PeertubeHelper {
final String savedInstanceListKey = context.getString(R.string.peertube_instance_list_key);
final String savedJson = sharedPreferences.getString(savedInstanceListKey, null);
if (null == savedJson) {
return Collections.singletonList(getCurrentInstance());
return List.of(getCurrentInstance());
}
try {
@ -45,9 +44,8 @@ public final class PeertubeHelper {
}
return result;
} catch (final JsonParserException e) {
return Collections.singletonList(getCurrentInstance());
return List.of(getCurrentInstance());
}
}
public static PeertubeInstance selectInstance(final PeertubeInstance instance,

View File

@ -153,7 +153,7 @@ public class PlayQueueTest {
@Test
public void itemsAreNotCloned() {
final PlayQueueItem item = makeItemWithUrl("A url");
final PlayQueue playQueue = makePlayQueue(0, Collections.singletonList(item));
final PlayQueue playQueue = makePlayQueue(0, List.of(item));
// make sure that items are not cloned when added to the queue
assertSame(playQueue.getItem(), item);

View File

@ -6,7 +6,6 @@ import org.schabi.newpipe.extractor.stream.AudioStream;
import org.schabi.newpipe.extractor.stream.VideoStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
@ -18,7 +17,7 @@ import androidx.annotation.Nullable;
public class ListHelperTest {
private static final String BEST_RESOLUTION_KEY = "best_resolution";
private static final List<AudioStream> AUDIO_STREAMS_TEST_LIST = Arrays.asList(
private static final List<AudioStream> AUDIO_STREAMS_TEST_LIST = List.of(
generateAudioStream("m4a-128-1", MediaFormat.M4A, 128),
generateAudioStream("webma-192", MediaFormat.WEBMA, 192),
generateAudioStream("mp3-64", MediaFormat.MP3, 64),
@ -30,7 +29,7 @@ public class ListHelperTest {
generateAudioStream("mp3-192", MediaFormat.MP3, 192),
generateAudioStream("webma-320", MediaFormat.WEBMA, 320));
private static final List<VideoStream> VIDEO_STREAMS_TEST_LIST = Arrays.asList(
private static final List<VideoStream> VIDEO_STREAMS_TEST_LIST = List.of(
generateVideoStream("mpeg_4-720", MediaFormat.MPEG_4, "720p", false),
generateVideoStream("v3gpp-240", MediaFormat.v3GPP, "240p", false),
generateVideoStream("webm-480", MediaFormat.WEBM, "480p", false),
@ -38,7 +37,7 @@ public class ListHelperTest {
generateVideoStream("mpeg_4-360", MediaFormat.MPEG_4, "360p", false),
generateVideoStream("webm-360", MediaFormat.WEBM, "360p", false));
private static final List<VideoStream> VIDEO_ONLY_STREAMS_TEST_LIST = Arrays.asList(
private static final List<VideoStream> VIDEO_ONLY_STREAMS_TEST_LIST = List.of(
generateVideoStream("mpeg_4-720-1", MediaFormat.MPEG_4, "720p", true),
generateVideoStream("mpeg_4-720-2", MediaFormat.MPEG_4, "720p", true),
generateVideoStream("mpeg_4-2160", MediaFormat.MPEG_4, "2160p", true),
@ -54,7 +53,7 @@ public class ListHelperTest {
List<VideoStream> result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, true,
VIDEO_STREAMS_TEST_LIST, VIDEO_ONLY_STREAMS_TEST_LIST, true, false);
List<String> expected = Arrays.asList("144p", "240p", "360p", "480p", "720p", "720p60",
List<String> expected = List.of("144p", "240p", "360p", "480p", "720p", "720p60",
"1080p", "1080p60", "1440p60", "2160p", "2160p60");
assertEquals(expected.size(), result.size());
@ -69,7 +68,7 @@ public class ListHelperTest {
result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, true,
VIDEO_STREAMS_TEST_LIST, VIDEO_ONLY_STREAMS_TEST_LIST, false, false);
expected = Arrays.asList("2160p60", "2160p", "1440p60", "1080p60", "1080p", "720p60",
expected = List.of("2160p60", "2160p", "1440p60", "1080p60", "1080p", "720p60",
"720p", "480p", "360p", "240p", "144p");
assertEquals(expected.size(), result.size());
for (int i = 0; i < result.size(); i++) {
@ -83,7 +82,7 @@ public class ListHelperTest {
null, VIDEO_ONLY_STREAMS_TEST_LIST, true, true);
List<String> expected =
Arrays.asList("720p", "720p60", "1080p", "1080p60", "1440p60", "2160p", "2160p60");
List.of("720p", "720p60", "1080p", "1080p60", "1440p60", "2160p", "2160p60");
assertEquals(expected.size(), result.size());
for (int i = 0; i < result.size(); i++) {
@ -97,7 +96,7 @@ public class ListHelperTest {
result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, true,
VIDEO_STREAMS_TEST_LIST, null, false, true);
expected = Arrays.asList("720p", "480p", "360p", "240p", "144p");
expected = List.of("720p", "480p", "360p", "240p", "144p");
assertEquals(expected.size(), result.size());
for (int i = 0; i < result.size(); i++) {
assertEquals(expected.get(i), result.get(i).getResolution());
@ -110,10 +109,10 @@ public class ListHelperTest {
result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, true,
VIDEO_STREAMS_TEST_LIST, VIDEO_ONLY_STREAMS_TEST_LIST, true, true);
expected = Arrays.asList("144p", "240p", "360p", "480p", "720p", "720p60",
expected = List.of("144p", "240p", "360p", "480p", "720p", "720p60",
"1080p", "1080p60", "1440p60", "2160p", "2160p60");
final List<String> expectedVideoOnly =
Arrays.asList("720p", "720p60", "1080p", "1080p60", "1440p60", "2160p", "2160p60");
List.of("720p", "720p60", "1080p", "1080p60", "1440p60", "2160p", "2160p60");
assertEquals(expected.size(), result.size());
for (int i = 0; i < result.size(); i++) {
@ -131,7 +130,7 @@ public class ListHelperTest {
final List<VideoStream> result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4,
false, VIDEO_STREAMS_TEST_LIST, VIDEO_ONLY_STREAMS_TEST_LIST, false, false);
final List<String> expected = Arrays.asList(
final List<String> expected = List.of(
"1080p60", "1080p", "720p60", "720p", "480p", "360p", "240p", "144p");
assertEquals(expected.size(), result.size());
for (int i = 0; i < result.size(); i++) {
@ -141,7 +140,7 @@ public class ListHelperTest {
@Test
public void getDefaultResolutionTest() {
final List<VideoStream> testList = Arrays.asList(
final List<VideoStream> testList = List.of(
generateVideoStream("mpeg_4-720", MediaFormat.MPEG_4, "720p", false),
generateVideoStream("v3gpp-240", MediaFormat.v3GPP, "240p", false),
generateVideoStream("webm-480", MediaFormat.WEBM, "480p", false),
@ -223,7 +222,7 @@ public class ListHelperTest {
// Doesn't contain the preferred format //
////////////////////////////////////////
List<AudioStream> testList = Arrays.asList(
List<AudioStream> testList = List.of(
generateAudioStream("m4a-128", MediaFormat.M4A, 128),
generateAudioStream("webma-192", MediaFormat.WEBMA, 192));
// List doesn't contains this format
@ -237,7 +236,7 @@ public class ListHelperTest {
// Multiple not-preferred-formats and equal bitrates //
//////////////////////////////////////////////////////
testList = new ArrayList<>(Arrays.asList(
testList = new ArrayList<>(List.of(
generateAudioStream("webma-192-1", MediaFormat.WEBMA, 192),
generateAudioStream("m4a-192-1", MediaFormat.M4A, 192),
generateAudioStream("webma-192-2", MediaFormat.WEBMA, 192),
@ -290,7 +289,7 @@ public class ListHelperTest {
// Doesn't contain the preferred format //
////////////////////////////////////////
List<AudioStream> testList = new ArrayList<>(Arrays.asList(
List<AudioStream> testList = new ArrayList<>(List.of(
generateAudioStream("m4a-128", MediaFormat.M4A, 128),
generateAudioStream("webma-192-1", MediaFormat.WEBMA, 192)));
// List doesn't contains this format
@ -310,7 +309,7 @@ public class ListHelperTest {
// Multiple not-preferred-formats and equal bitrates //
//////////////////////////////////////////////////////
testList = new ArrayList<>(Arrays.asList(
testList = new ArrayList<>(List.of(
generateAudioStream("webma-192-1", MediaFormat.WEBMA, 192),
generateAudioStream("m4a-192-1", MediaFormat.M4A, 192),
generateAudioStream("webma-256", MediaFormat.WEBMA, 256),
@ -337,7 +336,7 @@ public class ListHelperTest {
@Test
public void getVideoDefaultStreamIndexCombinations() {
final List<VideoStream> testList = Arrays.asList(
final List<VideoStream> testList = List.of(
generateVideoStream("mpeg_4-1080", MediaFormat.MPEG_4, "1080p", false),
generateVideoStream("mpeg_4-720_60", MediaFormat.MPEG_4, "720p60", false),
generateVideoStream("mpeg_4-720", MediaFormat.MPEG_4, "720p", false),