diff --git a/extensions/cronet/build.gradle b/extensions/cronet/build.gradle index c0f443d5df..ed8f4f5926 100644 --- a/extensions/cronet/build.gradle +++ b/extensions/cronet/build.gradle @@ -17,6 +17,7 @@ dependencies { api "com.google.android.gms:play-services-cronet:17.0.0" implementation project(modulePrefix + 'library-core') implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion + implementation 'com.google.guava:guava:' + guavaVersion compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion compileOnly 'org.jetbrains.kotlin:kotlin-annotations-jvm:' + kotlinAnnotationsVersion testImplementation project(modulePrefix + 'library') diff --git a/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetDataSource.java b/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetDataSource.java index 4d0333bb8c..3712ee7334 100644 --- a/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetDataSource.java +++ b/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetDataSource.java @@ -30,8 +30,8 @@ import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.ConditionVariable; import com.google.android.exoplayer2.util.Log; -import com.google.android.exoplayer2.util.Predicate; import com.google.android.exoplayer2.util.Util; +import com.google.common.base.Predicate; import java.io.IOException; import java.io.InterruptedIOException; import java.net.SocketTimeoutException; @@ -477,7 +477,7 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource { if (contentTypePredicate != null) { List contentTypeHeaders = responseInfo.getAllHeaders().get(CONTENT_TYPE); String contentType = isEmpty(contentTypeHeaders) ? null : contentTypeHeaders.get(0); - if (contentType != null && !contentTypePredicate.evaluate(contentType)) { + if (contentType != null && !contentTypePredicate.apply(contentType)) { throw new InvalidContentTypeException(contentType, dataSpec); } } diff --git a/extensions/okhttp/build.gradle b/extensions/okhttp/build.gradle index 032fb0fded..217bfa76cd 100644 --- a/extensions/okhttp/build.gradle +++ b/extensions/okhttp/build.gradle @@ -16,6 +16,7 @@ apply from: "$gradle.ext.exoplayerSettingsDir/common_library_config.gradle" dependencies { implementation project(modulePrefix + 'library-core') implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion + implementation 'com.google.guava:guava:' + guavaVersion compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion compileOnly 'org.jetbrains.kotlin:kotlin-annotations-jvm:' + kotlinAnnotationsVersion testImplementation project(modulePrefix + 'testutils') diff --git a/extensions/okhttp/src/main/java/com/google/android/exoplayer2/ext/okhttp/OkHttpDataSource.java b/extensions/okhttp/src/main/java/com/google/android/exoplayer2/ext/okhttp/OkHttpDataSource.java index 6a7e48f7e2..54d3c1a5b4 100644 --- a/extensions/okhttp/src/main/java/com/google/android/exoplayer2/ext/okhttp/OkHttpDataSource.java +++ b/extensions/okhttp/src/main/java/com/google/android/exoplayer2/ext/okhttp/OkHttpDataSource.java @@ -26,8 +26,8 @@ import com.google.android.exoplayer2.upstream.DataSourceException; import com.google.android.exoplayer2.upstream.DataSpec; import com.google.android.exoplayer2.upstream.HttpDataSource; import com.google.android.exoplayer2.util.Assertions; -import com.google.android.exoplayer2.util.Predicate; import com.google.android.exoplayer2.util.Util; +import com.google.common.base.Predicate; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; @@ -252,7 +252,7 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource { // Check for a valid content type. MediaType mediaType = responseBody.contentType(); String contentType = mediaType != null ? mediaType.toString() : ""; - if (contentTypePredicate != null && !contentTypePredicate.evaluate(contentType)) { + if (contentTypePredicate != null && !contentTypePredicate.apply(contentType)) { closeConnectionQuietly(); throw new InvalidContentTypeException(contentType, dataSpec); } diff --git a/library/common/src/main/java/com/google/android/exoplayer2/upstream/HttpDataSource.java b/library/common/src/main/java/com/google/android/exoplayer2/upstream/HttpDataSource.java index 3a25efc18a..d2170b9eab 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/upstream/HttpDataSource.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/upstream/HttpDataSource.java @@ -18,8 +18,8 @@ package com.google.android.exoplayer2.upstream; import android.text.TextUtils; import androidx.annotation.IntDef; import androidx.annotation.Nullable; -import com.google.android.exoplayer2.util.Predicate; import com.google.android.exoplayer2.util.Util; +import com.google.common.base.Predicate; import java.io.IOException; import java.lang.annotation.Documented; import java.lang.annotation.Retention; diff --git a/library/common/src/main/java/com/google/android/exoplayer2/util/Function.java b/library/common/src/main/java/com/google/android/exoplayer2/util/Function.java deleted file mode 100644 index 900f32db45..0000000000 --- a/library/common/src/main/java/com/google/android/exoplayer2/util/Function.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.android.exoplayer2.util; - -/** - * A functional interface representing a function taking one argument and returning a result. - * - * @param The input type of the function. - * @param The output type of the function. - */ -public interface Function { - - /** - * Applies this function to the given argument. - * - * @param t The function argument. - * @return The function result, which may be {@code null}. - */ - R apply(T t); -} diff --git a/library/common/src/main/java/com/google/android/exoplayer2/util/Predicate.java b/library/common/src/main/java/com/google/android/exoplayer2/util/Predicate.java deleted file mode 100644 index b582cf3f7c..0000000000 --- a/library/common/src/main/java/com/google/android/exoplayer2/util/Predicate.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.android.exoplayer2.util; - -/** - * Determines a true or false value for a given input. - * - * @param The input type of the predicate. - */ -public interface Predicate { - - /** - * Evaluates an input. - * - * @param input The input to evaluate. - * @return The evaluated result. - */ - boolean evaluate(T input); - -} diff --git a/library/common/src/main/java/com/google/android/exoplayer2/util/Supplier.java b/library/common/src/main/java/com/google/android/exoplayer2/util/Supplier.java deleted file mode 100644 index 723047b1ed..0000000000 --- a/library/common/src/main/java/com/google/android/exoplayer2/util/Supplier.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.android.exoplayer2.util; - -/** - * A functional interface representing a supplier of results. - * - * @param The type of results supplied by this supplier. - */ -public interface Supplier { - - /** Gets a result. */ - T get(); -} diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java index f2570aa552..8b50e5a292 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java @@ -43,9 +43,9 @@ import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.HandlerWrapper; import com.google.android.exoplayer2.util.Log; -import com.google.android.exoplayer2.util.Supplier; import com.google.android.exoplayer2.util.TraceUtil; import com.google.android.exoplayer2.util.Util; +import com.google.common.base.Supplier; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; diff --git a/library/core/src/main/java/com/google/android/exoplayer2/analytics/DefaultPlaybackSessionManager.java b/library/core/src/main/java/com/google/android/exoplayer2/analytics/DefaultPlaybackSessionManager.java index b1ef52839b..9746829107 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/analytics/DefaultPlaybackSessionManager.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/analytics/DefaultPlaybackSessionManager.java @@ -27,8 +27,8 @@ import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime; import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId; import com.google.android.exoplayer2.util.Assertions; -import com.google.android.exoplayer2.util.Supplier; import com.google.android.exoplayer2.util.Util; +import com.google.common.base.Supplier; import java.util.HashMap; import java.util.Iterator; import java.util.Random; diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.java index 7f01d2182e..4e773b0bbf 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.java @@ -23,8 +23,8 @@ import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.upstream.DataSpec.HttpMethod; import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Log; -import com.google.android.exoplayer2.util.Predicate; import com.google.android.exoplayer2.util.Util; +import com.google.common.base.Predicate; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; @@ -319,7 +319,7 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou // Check for a valid content type. String contentType = connection.getContentType(); - if (contentTypePredicate != null && !contentTypePredicate.evaluate(contentType)) { + if (contentTypePredicate != null && !contentTypePredicate.apply(contentType)) { closeConnectionQuietly(); throw new InvalidContentTypeException(contentType, dataSpec); } diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeTrackOutput.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeTrackOutput.java index 236eef0b60..4e636d993c 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeTrackOutput.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeTrackOutput.java @@ -24,9 +24,9 @@ import com.google.android.exoplayer2.extractor.TrackOutput; import com.google.android.exoplayer2.testutil.Dumper.Dumpable; import com.google.android.exoplayer2.upstream.DataReader; import com.google.android.exoplayer2.util.Assertions; -import com.google.android.exoplayer2.util.Function; import com.google.android.exoplayer2.util.ParsableByteArray; import com.google.android.exoplayer2.util.Util; +import com.google.common.base.Function; import com.google.common.primitives.Bytes; import java.io.EOFException; import java.io.IOException; diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/TestUtil.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/TestUtil.java index 71156b711e..ea423660f4 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/TestUtil.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/TestUtil.java @@ -41,9 +41,9 @@ import com.google.android.exoplayer2.upstream.DataSpec; import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.ConditionVariable; -import com.google.android.exoplayer2.util.Supplier; import com.google.android.exoplayer2.util.SystemClock; import com.google.android.exoplayer2.util.Util; +import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; import com.google.common.primitives.Bytes; import java.io.File; diff --git a/testutils/src/test/java/com/google/android/exoplayer2/testutil/TestUtilTest.java b/testutils/src/test/java/com/google/android/exoplayer2/testutil/TestUtilTest.java index 01a119b694..cc7df84375 100644 --- a/testutils/src/test/java/com/google/android/exoplayer2/testutil/TestUtilTest.java +++ b/testutils/src/test/java/com/google/android/exoplayer2/testutil/TestUtilTest.java @@ -26,7 +26,7 @@ import static org.mockito.Mockito.when; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.ConditionVariable; -import com.google.android.exoplayer2.util.Supplier; +import com.google.common.base.Supplier; import java.util.concurrent.TimeoutException; import org.junit.Test; import org.junit.runner.RunWith;