com.google.firebase.remoteconfig.ParameterValue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of firebase-admin Show documentation
Show all versions of firebase-admin Show documentation
This is the official Firebase Admin Java SDK. Build extraordinary native JVM apps in
minutes with Firebase. The Firebase platform can power your app’s backend, user
authentication, static hosting, and more.
/*
* Copyright 2020 Google LLC
*
* 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.firebase.remoteconfig;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.firebase.internal.NonNull;
import com.google.firebase.remoteconfig.internal.TemplateResponse.ParameterValueResponse;
import java.util.Objects;
/**
* Represents a Remote Config parameter value that can be used in a {@link Template}.
*/
public abstract class ParameterValue {
/**
* Creates a new {@link ParameterValue.Explicit} instance with the given value.
*
* @param value The value of the {@link ParameterValue.Explicit}.
* @return A {@link ParameterValue.Explicit} instance.
*/
public static Explicit of(String value) {
return new Explicit(value);
}
/**
* Creates a new {@link ParameterValue.InAppDefault} instance.
*
* @return A {@link ParameterValue.InAppDefault} instance.
*/
public static InAppDefault inAppDefault() {
return new InAppDefault();
}
abstract ParameterValueResponse toParameterValueResponse();
static ParameterValue fromParameterValueResponse(
@NonNull ParameterValueResponse parameterValueResponse) {
checkNotNull(parameterValueResponse);
if (parameterValueResponse.isUseInAppDefault()) {
return ParameterValue.inAppDefault();
}
return ParameterValue.of(parameterValueResponse.getValue());
}
/**
* Represents an explicit Remote Config parameter value with a value that the
* parameter is set to.
*/
public static final class Explicit extends ParameterValue {
private final String value;
private Explicit(String value) {
this.value = value;
}
/**
* Gets the value of {@link ParameterValue.Explicit}.
*
* @return The value.
*/
public String getValue() {
return this.value;
}
@Override
ParameterValueResponse toParameterValueResponse() {
return new ParameterValueResponse()
.setValue(this.value);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Explicit explicit = (Explicit) o;
return Objects.equals(value, explicit.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
}
/**
* Represents an in app default parameter value.
*/
public static final class InAppDefault extends ParameterValue {
@Override
ParameterValueResponse toParameterValueResponse() {
return new ParameterValueResponse().setUseInAppDefault(true);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
return true;
}
}
}