-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollforward using a non-deprecated API for connectivity monitoring
PiperOrigin-RevId: 406191957
- Loading branch information
1 parent
b43ea98
commit 833ef21
Showing
3 changed files
with
354 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
library/src/main/java/com/bumptech/glide/util/GlideSuppliers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.bumptech.glide.util; | ||
|
||
/** Similar to {@link com.google.common.base.Suppliers}, but named to reduce import confusion. */ | ||
public final class GlideSuppliers { | ||
/** | ||
* Produces a non-null instance of {@code T}. | ||
* | ||
* @param <T> The data type | ||
*/ | ||
public interface GlideSupplier<T> { | ||
T get(); | ||
} | ||
|
||
private GlideSuppliers() {} | ||
|
||
public static <T> GlideSupplier<T> memorize(final GlideSupplier<T> supplier) { | ||
return new GlideSupplier<T>() { | ||
private volatile T instance; | ||
|
||
@Override | ||
public T get() { | ||
if (instance == null) { | ||
synchronized (this) { | ||
if (instance == null) { | ||
instance = Preconditions.checkNotNull(supplier.get()); | ||
} | ||
} | ||
} | ||
return instance; | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.