24
24
import com .google .firebase .internal .Nullable ;
25
25
import com .google .firebase .remoteconfig .internal .TemplateResponse .ConditionResponse ;
26
26
27
+ import java .util .Objects ;
28
+
27
29
/**
28
30
* Represents a Remote Config condition that can be included in a {@link Template}.
29
31
* A condition targets a specific group of users. A list of these conditions make up
@@ -38,7 +40,7 @@ public final class Condition {
38
40
/**
39
41
* Creates a new {@link Condition}.
40
42
*
41
- * @param name A non-null, non-empty, and unique name of this condition.
43
+ * @param name A non-null, non-empty, and unique name of this condition.
42
44
* @param expression A non-null and non-empty expression of this condition.
43
45
*/
44
46
public Condition (@ NonNull String name , @ NonNull String expression ) {
@@ -47,7 +49,23 @@ public Condition(@NonNull String name, @NonNull String expression) {
47
49
"condition expression must not be null or empty" );
48
50
this .name = name ;
49
51
this .expression = expression ;
50
- this .tagColor = TagColor .UNSPECIFIED ;
52
+ }
53
+
54
+ /**
55
+ * Creates a new {@link Condition}.
56
+ *
57
+ * @param name A non-null, non-empty, and unique name of this condition.
58
+ * @param expression A non-null and non-empty expression of this condition.
59
+ * @param tagColor A non-null tag color of this condition.
60
+ */
61
+ public Condition (@ NonNull String name , @ NonNull String expression , @ NonNull TagColor tagColor ) {
62
+ checkArgument (!Strings .isNullOrEmpty (name ), "condition name must not be null or empty" );
63
+ checkArgument (!Strings .isNullOrEmpty (expression ),
64
+ "condition expression must not be null or empty" );
65
+ checkNotNull (tagColor , "condition tag color must not be null" );
66
+ this .name = name ;
67
+ this .expression = expression ;
68
+ this .tagColor = tagColor ;
51
69
}
52
70
53
71
Condition (@ NonNull ConditionResponse conditionResponse ) {
@@ -64,7 +82,7 @@ public Condition(@NonNull String name, @NonNull String expression) {
64
82
/**
65
83
* Gets the name of the condition.
66
84
*
67
- * @return The {@link String} name of the condition.
85
+ * @return The name of the condition.
68
86
*/
69
87
@ NonNull
70
88
public String getName () {
@@ -74,7 +92,7 @@ public String getName() {
74
92
/**
75
93
* Gets the expression of the condition.
76
94
*
77
- * @return The {@link String} expression of the condition.
95
+ * @return The expression of the condition.
78
96
*/
79
97
@ NonNull
80
98
public String getExpression () {
@@ -84,7 +102,7 @@ public String getExpression() {
84
102
/**
85
103
* Gets the tag color of the condition.
86
104
*
87
- * @return The {@link String} tag color of the condition.
105
+ * @return The tag color of the condition.
88
106
*/
89
107
@ NonNull
90
108
public TagColor getTagColor () {
@@ -127,18 +145,30 @@ public Condition setExpression(@NonNull String expression) {
127
145
* with the condition.
128
146
*
129
147
* @param tagColor The tag color of this condition.
130
- * Passing null sets to {@code TagColor.UNSPECIFIED}
131
148
* @return This {@link Condition}.
132
149
*/
133
150
public Condition setTagColor (@ Nullable TagColor tagColor ) {
134
- this .tagColor = tagColor == null ? TagColor . UNSPECIFIED : tagColor ;
151
+ this .tagColor = tagColor ;
135
152
return this ;
136
153
}
137
154
138
155
ConditionResponse toConditionResponse () {
139
156
return new ConditionResponse ()
140
157
.setName (this .name )
141
158
.setExpression (this .expression )
142
- .setTagColor (this .tagColor .getColor ());
159
+ .setTagColor (this .tagColor == null ? null : this .tagColor .getColor ());
160
+ }
161
+
162
+ @ Override
163
+ public boolean equals (Object o ) {
164
+ if (this == o ) {
165
+ return true ;
166
+ }
167
+ if (o == null || getClass () != o .getClass ()) {
168
+ return false ;
169
+ }
170
+ Condition condition = (Condition ) o ;
171
+ return Objects .equals (name , condition .name )
172
+ && Objects .equals (expression , condition .expression ) && tagColor == condition .tagColor ;
143
173
}
144
174
}
0 commit comments