@@ -92,7 +92,7 @@ static class Builder<E> {
9292 Builder (E value , int weight ) {
9393 this .value = value ;
9494 this .weight = weight ;
95- this .userTarget = new TargetRule ("key" , "in" , new ArrayList <Object >());
95+ this .userTarget = new TargetRule ("key" , "in" , new ArrayList <JsonPrimitive >());
9696 targets = new ArrayList <TargetRule >();
9797 }
9898
@@ -115,79 +115,69 @@ Variation<E> build() {
115115 static class TargetRule {
116116 String attribute ;
117117 String operator ;
118- List <Object > values ;
118+ List <JsonPrimitive > values ;
119119
120120 private final Logger logger = LoggerFactory .getLogger (TargetRule .class );
121121
122122 public TargetRule () {
123123
124124 }
125125
126- TargetRule (String attribute , String operator , List <Object > values ) {
126+ TargetRule (String attribute , String operator , List <JsonPrimitive > values ) {
127127 this .attribute = attribute ;
128128 this .operator = operator ;
129- this .values = new ArrayList <Object >(values );
129+ this .values = new ArrayList <JsonPrimitive >(values );
130130 }
131131
132- TargetRule (String attribute , List <Object > values ) {
132+ TargetRule (String attribute , List <JsonPrimitive > values ) {
133133 this (attribute , "in" , values );
134134 }
135135
136- private boolean matchCustom (JsonPrimitive prim , List <Object > values ) {
137- if (prim .isNumber ()) {
138- return values .contains (prim .getAsDouble ());
139- } else if (prim .isBoolean ()) {
140- return values .contains (prim .getAsBoolean ());
141- } else {
142- return values .contains (prim .getAsString ());
143- }
144- }
145-
146136 public boolean matchTarget (LDUser user ) {
147137 Object uValue = null ;
148138 if (attribute .equals ("key" )) {
149139 if (user .getKey () != null ) {
150- uValue = user .getKey ();
140+ uValue = new JsonPrimitive ( user .getKey () );
151141 }
152142 }
153143 else if (attribute .equals ("ip" ) && user .getIp () != null ) {
154144 if (user .getIp () != null ) {
155- uValue = user .getIp ();
145+ uValue = new JsonPrimitive ( user .getIp () );
156146 }
157147 }
158148 else if (attribute .equals ("country" )) {
159149 if (user .getCountry () != null ) {
160- uValue = user .getCountry ().getAlpha2 ();
150+ uValue = new JsonPrimitive ( user .getCountry ().getAlpha2 () );
161151 }
162152 }
163153 else if (attribute .equals ("email" )) {
164154 if (user .getEmail () != null ) {
165- uValue = user .getEmail ();
155+ uValue = new JsonPrimitive ( user .getEmail () );
166156 }
167157 }
168158 else if (attribute .equals ("firstName" )) {
169159 if (user .getFirstName () != null ) {
170- uValue = user .getFirstName ();
160+ uValue = new JsonPrimitive ( user .getFirstName () );
171161 }
172162 }
173163 else if (attribute .equals ("lastName" )) {
174164 if (user .getLastName () != null ) {
175- uValue = user .getLastName ();
165+ uValue = new JsonPrimitive ( user .getLastName () );
176166 }
177167 }
178168 else if (attribute .equals ("avatar" )) {
179169 if (user .getAvatar () != null ) {
180- uValue = user .getAvatar ();
170+ uValue = new JsonPrimitive ( user .getAvatar () );
181171 }
182172 }
183173 else if (attribute .equals ("name" )) {
184174 if (user .getName () != null ) {
185- uValue = user .getName ();
175+ uValue = new JsonPrimitive ( user .getName () );
186176 }
187177 }
188178 else if (attribute .equals ("anonymous" )) {
189179 if (user .getAnonymous () != null ) {
190- uValue = user .getAnonymous ();
180+ uValue = new JsonPrimitive ( user .getAnonymous () );
191181 }
192182 }
193183 else { // Custom attribute
@@ -201,14 +191,14 @@ else if (attribute.equals("anonymous")) {
201191 logger .error ("Invalid custom attribute value in user object: " + elt );
202192 return false ;
203193 }
204- else if (matchCustom (elt .getAsJsonPrimitive (), values )) {
194+ else if (values . contains (elt .getAsJsonPrimitive ())) {
205195 return true ;
206196 }
207197 }
208198 return false ;
209199 }
210200 else if (custom .isJsonPrimitive ()) {
211- return matchCustom (custom .getAsJsonPrimitive (), values );
201+ return values . contains (custom .getAsJsonPrimitive ());
212202 }
213203 }
214204 return false ;
0 commit comments