-
Notifications
You must be signed in to change notification settings - Fork 306
Support Remote Config managed value types #1164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c557114
4087dea
dad48bf
baf8e01
c59db87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,15 @@ | |
| import static com.google.common.base.Preconditions.checkNotNull; | ||
|
|
||
| import com.google.firebase.internal.NonNull; | ||
| import com.google.firebase.internal.Nullable; | ||
| import com.google.firebase.remoteconfig.internal.TemplateResponse.ExperimentValueResponse; | ||
| import com.google.firebase.remoteconfig.internal.TemplateResponse.ExperimentVariantValueResponse; | ||
| import com.google.firebase.remoteconfig.internal.TemplateResponse.ParameterValueResponse; | ||
| import com.google.firebase.remoteconfig.internal.TemplateResponse.PersonalizationValueResponse; | ||
| import com.google.firebase.remoteconfig.internal.TemplateResponse.RolloutValueResponse; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
|
|
@@ -47,6 +54,40 @@ public static InAppDefault inAppDefault() { | |
| return new InAppDefault(); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new {@link ParameterValue.RolloutValue} instance. | ||
| * | ||
| * @param rolloutId The rollout ID. | ||
| * @param value The value of the rollout. | ||
| * @param percent The percentage of the rollout. | ||
| * @return A {@link ParameterValue.RolloutValue} instance. | ||
| */ | ||
| public static RolloutValue rollout(String rolloutId, String value, double percent) { | ||
| return new RolloutValue(rolloutId, value, percent); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new {@link ParameterValue.PersonalizationValue} instance. | ||
| * | ||
| * @param personalizationId The personalization ID. | ||
| * @return A {@link ParameterValue.PersonalizationValue} instance. | ||
| */ | ||
| public static PersonalizationValue personalization(String personalizationId) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename this to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Renamed |
||
| return new PersonalizationValue(personalizationId); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new {@link ParameterValue.ExperimentValue} instance. | ||
| * | ||
| * @param experimentId The experiment ID. | ||
| * @param variantValues The list of experiment variant values. | ||
| * @return A {@link ParameterValue.ExperimentValue} instance. | ||
| */ | ||
| public static ExperimentValue experiment(String experimentId, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename this to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Renamed |
||
| List<ExperimentVariantValue> variantValues) { | ||
| return new ExperimentValue(experimentId, variantValues); | ||
| } | ||
|
|
||
| abstract ParameterValueResponse toParameterValueResponse(); | ||
|
|
||
| static ParameterValue fromParameterValueResponse( | ||
|
|
@@ -55,6 +96,24 @@ static ParameterValue fromParameterValueResponse( | |
| if (parameterValueResponse.isUseInAppDefault()) { | ||
| return ParameterValue.inAppDefault(); | ||
| } | ||
| if (parameterValueResponse.getRolloutValue() != null) { | ||
| RolloutValueResponse rv = parameterValueResponse.getRolloutValue(); | ||
| return ParameterValue.rollout(rv.getRolloutId(), rv.getValue(), rv.getPercent()); | ||
| } | ||
| if (parameterValueResponse.getPersonalizationValue() != null) { | ||
| PersonalizationValueResponse pv = parameterValueResponse.getPersonalizationValue(); | ||
| return ParameterValue.personalization(pv.getPersonalizationId()); | ||
| } | ||
| if (parameterValueResponse.getExperimentValue() != null) { | ||
| ExperimentValueResponse ev = parameterValueResponse.getExperimentValue(); | ||
| List<ExperimentVariantValue> variantValues = new ArrayList<>(); | ||
| for (ExperimentVariantValueResponse evv : ev.getExperimentVariantValues()) { | ||
| variantValues.add( | ||
| new ExperimentVariantValue(evv.getVariantId(), evv.getValue(), | ||
| evv.getNoChange())); | ||
| } | ||
| return ParameterValue.experiment(ev.getExperimentId(), variantValues); | ||
| } | ||
| return ParameterValue.of(parameterValueResponse.getValue()); | ||
| } | ||
|
|
||
|
|
@@ -124,4 +183,220 @@ public boolean equals(Object o) { | |
| return true; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Represents a Rollout value. | ||
| */ | ||
| public static final class RolloutValue extends ParameterValue { | ||
| private final String rolloutId; | ||
| private final String value; | ||
| private final double percent; | ||
|
|
||
| private RolloutValue(String rolloutId, String value, double percent) { | ||
| this.rolloutId = rolloutId; | ||
| this.value = value; | ||
| this.percent = percent; | ||
| } | ||
|
|
||
| public String getRolloutId() { | ||
| return rolloutId; | ||
| } | ||
|
|
||
| public String getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| public double getPercent() { | ||
| return percent; | ||
| } | ||
|
|
||
| @Override | ||
| ParameterValueResponse toParameterValueResponse() { | ||
| return new ParameterValueResponse().setRolloutValue( | ||
| new RolloutValueResponse() | ||
| .setRolloutId(this.rolloutId) | ||
| .setValue(this.value) | ||
| .setPercent(this.percent)); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| RolloutValue that = (RolloutValue) o; | ||
| return Double.compare(that.percent, percent) == 0 | ||
| && Objects.equals(rolloutId, that.rolloutId) | ||
| && Objects.equals(value, that.value); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(rolloutId, value, percent); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Represents a Personalization value. | ||
| */ | ||
| public static final class PersonalizationValue extends ParameterValue { | ||
| private final String personalizationId; | ||
|
|
||
| private PersonalizationValue(String personalizationId) { | ||
| this.personalizationId = personalizationId; | ||
| } | ||
|
|
||
| public String getPersonalizationId() { | ||
| return personalizationId; | ||
| } | ||
|
|
||
| @Override | ||
| ParameterValueResponse toParameterValueResponse() { | ||
| return new ParameterValueResponse().setPersonalizationValue( | ||
| new PersonalizationValueResponse() | ||
| .setPersonalizationId(this.personalizationId)); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| PersonalizationValue that = (PersonalizationValue) o; | ||
| return Objects.equals(personalizationId, that.personalizationId); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(personalizationId); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Represents a specific variant within an Experiment. | ||
| */ | ||
| public static final class ExperimentVariantValue { | ||
| private final String variantId; | ||
| private final String value; | ||
| private final boolean noChange; | ||
|
|
||
| ExperimentVariantValue(String variantId, String value, Boolean noChange) { | ||
| this.variantId = variantId; | ||
| this.value = value; | ||
| this.noChange = Boolean.TRUE.equals(noChange); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new {@link ExperimentVariantValue} instance. | ||
| * | ||
| * @param variantId The variant ID. | ||
| * @param value The value of the variant. | ||
| * @return A {@link ExperimentVariantValue} instance. | ||
| */ | ||
| public static ExperimentVariantValue of(String variantId, String value) { | ||
| return new ExperimentVariantValue(variantId, value, false); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new {@link ExperimentVariantValue} instance. | ||
| * | ||
| * @param variantId The variant ID. | ||
| * @return A {@link ExperimentVariantValue} instance. | ||
| */ | ||
| public static ExperimentVariantValue ofNoChange(String variantId) { | ||
| return new ExperimentVariantValue(variantId, null, true); | ||
| } | ||
|
|
||
| public String getVariantId() { | ||
| return variantId; | ||
| } | ||
|
|
||
| @Nullable | ||
| public String getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| public boolean isNoChange() { | ||
| return noChange; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| ExperimentVariantValue that = (ExperimentVariantValue) o; | ||
| return noChange == that.noChange | ||
| && Objects.equals(variantId, that.variantId) | ||
| && Objects.equals(value, that.value); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(variantId, value, noChange); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Represents an Experiment value. | ||
| */ | ||
| public static final class ExperimentValue extends ParameterValue { | ||
| private final String experimentId; | ||
| private final List<ExperimentVariantValue> variantValues; | ||
|
|
||
| private ExperimentValue(String experimentId, List<ExperimentVariantValue> variantValues) { | ||
| this.experimentId = experimentId; | ||
| this.variantValues = variantValues; | ||
| } | ||
|
|
||
| public String getExperimentId() { | ||
| return experimentId; | ||
| } | ||
|
|
||
| public List<ExperimentVariantValue> getExperimentVariantValues() { | ||
| return variantValues; | ||
| } | ||
|
|
||
| @Override | ||
| ParameterValueResponse toParameterValueResponse() { | ||
| List<ExperimentVariantValueResponse> variantValueResponses = new ArrayList<>(); | ||
| for (ExperimentVariantValue variantValue : variantValues) { | ||
| variantValueResponses.add(new ExperimentVariantValueResponse() | ||
| .setVariantId(variantValue.getVariantId()) | ||
| .setValue(variantValue.getValue()) | ||
| .setNoChange(variantValue.isNoChange())); | ||
| } | ||
| return new ParameterValueResponse().setExperimentValue( | ||
| new ExperimentValueResponse() | ||
| .setExperimentId(this.experimentId) | ||
| .setExperimentVariantValues(variantValueResponses)); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| ExperimentValue that = (ExperimentValue) o; | ||
| return Objects.equals(experimentId, that.experimentId) | ||
| && Objects.equals(variantValues, that.variantValues); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(experimentId, variantValues); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this to
ofRollout(...).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Renamed
rollouttoofRollout.