Revert^2 "Allow flags to add metadata directly in code."

d7d04dccb9

Bug: 279054964
Change-Id: I8cf53ca92628366332c767a9b1709ba989c7b972
This commit is contained in:
Dave Mankoff
2023-07-12 19:32:11 +00:00
parent fdc60c8749
commit 9cf5bb454e
6 changed files with 89 additions and 0 deletions

View File

@@ -43,4 +43,10 @@ public class BooleanFlag extends BooleanFlagBase {
public Boolean getDefault() {
return mDefault;
}
@Override
public BooleanFlag defineMetaData(String label, String description, String categoryName) {
super.defineMetaData(label, description, categoryName);
return this;
}
}

View File

@@ -22,6 +22,9 @@ abstract class BooleanFlagBase implements Flag<Boolean> {
private final String mNamespace;
private final String mName;
private String mLabel;
private String mDescription;
private String mCategoryName;
/**
* @param namespace A namespace for this flag. See {@link android.provider.DeviceConfig}.
@@ -30,6 +33,7 @@ abstract class BooleanFlagBase implements Flag<Boolean> {
BooleanFlagBase(String namespace, String name) {
mNamespace = namespace;
mName = name;
mLabel = name;
}
public abstract Boolean getDefault();
@@ -46,6 +50,30 @@ abstract class BooleanFlagBase implements Flag<Boolean> {
return mName;
}
@Override
public BooleanFlagBase defineMetaData(String label, String description, String categoryName) {
mLabel = label;
mDescription = description;
mCategoryName = categoryName;
return this;
}
@Override
@NonNull
public String getLabel() {
return mLabel;
}
@Override
public String getDescription() {
return mDescription;
}
@Override
public String getCategoryName() {
return mCategoryName;
}
@Override
@NonNull
public String toString() {

View File

@@ -41,4 +41,10 @@ public class DynamicBooleanFlag extends BooleanFlagBase implements DynamicFlag<B
public Boolean getDefault() {
return mDefault;
}
@Override
public DynamicBooleanFlag defineMetaData(String label, String description, String categoryName) {
super.defineMetaData(label, description, categoryName);
return this;
}
}

View File

@@ -42,4 +42,41 @@ public interface Flag<T> {
default boolean isDynamic() {
return false;
}
/**
* Add human-readable details to the flag. Flag client's are not required to set this.
*
* See {@link #getLabel()}, {@link #getDescription()}, and {@link #getCategoryName()}.
*
* @return Returns `this`, to make a fluent api.
*/
Flag<T> defineMetaData(String label, String description, String categoryName);
/**
* A human-readable name for the flag. Defaults to {@link #getName()}
*
* See {@link #defineMetaData(String, String, String)}
*/
@NonNull
default String getLabel() {
return getName();
}
/**
* A human-readable description for the flag. Defaults to null if unset.
*
* See {@link #defineMetaData(String, String, String)}
*/
default String getDescription() {
return null;
}
/**
* A human-readable category name for the flag. Defaults to null if unset.
*
* See {@link #defineMetaData(String, String, String)}
*/
default String getCategoryName() {
return null;
}
}

View File

@@ -40,4 +40,10 @@ public final class FusedOffFlag extends BooleanFlagBase {
public Boolean getDefault() {
return false;
}
@Override
public FusedOffFlag defineMetaData(String label, String description, String categoryName) {
super.defineMetaData(label, description, categoryName);
return this;
}
}

View File

@@ -40,4 +40,10 @@ public final class FusedOnFlag extends BooleanFlagBase {
public Boolean getDefault() {
return true;
}
@Override
public FusedOnFlag defineMetaData(String label, String description, String categoryName) {
super.defineMetaData(label, description, categoryName);
return this;
}
}