-
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.
We seem to keep adding more and more experiments. Hopefully this makes them a bit easier to keep track of and reduces the pass through work required each time one is added or removed. PiperOrigin-RevId: 337556489
- Loading branch information
1 parent
9c6eae7
commit 6d7c484
Showing
8 changed files
with
105 additions
and
32 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
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
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
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
66 changes: 66 additions & 0 deletions
66
library/src/main/java/com/bumptech/glide/GlideExperiments.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,66 @@ | ||
package com.bumptech.glide; | ||
|
||
import androidx.annotation.Nullable; | ||
import com.bumptech.glide.util.Synthetic; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Keeps track of a set of Experimental features that may be enabled in Glide, simplifying the | ||
* process of adding and removing them. | ||
* | ||
* <p>This is an experimental API, it may be removed at any point without deprecation or other | ||
* notice. | ||
*/ | ||
// non-final for mocking | ||
public class GlideExperiments { | ||
|
||
private final Map<Class<?>, Experiment> experiments; | ||
|
||
@Synthetic | ||
GlideExperiments(Builder builder) { | ||
this.experiments = | ||
Collections.unmodifiableMap(new HashMap<Class<?>, Experiment>(builder.experiments)); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Nullable | ||
<T extends Experiment> T get(Class<T> clazz) { | ||
return (T) experiments.get(clazz); | ||
} | ||
|
||
/** | ||
* Returns {@code true} if the given experiment is enabled. | ||
* | ||
* <p>This is an experimental API, it may be removed at any point without deprecation or other | ||
* notice. | ||
*/ | ||
public boolean isEnabled(Class<? extends Experiment> clazz) { | ||
return experiments.containsKey(clazz); | ||
} | ||
|
||
interface Experiment {} | ||
|
||
static final class Builder { | ||
private final Map<Class<?>, Experiment> experiments = new HashMap<>(); | ||
|
||
Builder update(Experiment experiment, boolean isEnabled) { | ||
if (isEnabled) { | ||
add(experiment); | ||
} else { | ||
experiments.remove(experiment.getClass()); | ||
} | ||
return this; | ||
} | ||
|
||
Builder add(Experiment experiment) { | ||
experiments.put(experiment.getClass(), experiment); | ||
return this; | ||
} | ||
|
||
GlideExperiments build() { | ||
return new GlideExperiments(this); | ||
} | ||
} | ||
} |
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
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
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