|
33 | 33 | import com.google.protobuf.InvalidProtocolBufferException; |
34 | 34 |
|
35 | 35 | import java.util.HashMap; |
| 36 | +import java.util.LinkedList; |
36 | 37 | import java.util.List; |
37 | 38 | import java.util.Map; |
38 | 39 | import java.util.Objects; |
@@ -128,61 +129,286 @@ public B remove(String name) { |
128 | 129 | return self(); |
129 | 130 | } |
130 | 131 |
|
| 132 | + /** |
| 133 | + * Sets a property. |
| 134 | + * |
| 135 | + * @param name name of the property |
| 136 | + * @param value value associated with the property |
| 137 | + */ |
131 | 138 | public B set(String name, Value<?> value) { |
132 | 139 | properties.put(name, value); |
133 | 140 | return self(); |
134 | 141 | } |
135 | 142 |
|
| 143 | + /** |
| 144 | + * Sets a property of type {@link StringValue}. |
| 145 | + * |
| 146 | + * @param name name of the property |
| 147 | + * @param value value associated with the property |
| 148 | + */ |
136 | 149 | public B set(String name, String value) { |
137 | 150 | properties.put(name, of(value)); |
138 | 151 | return self(); |
139 | 152 | } |
140 | 153 |
|
| 154 | + /** |
| 155 | + * Sets a list property containing elements of type {@link StringValue}. |
| 156 | + * |
| 157 | + * @param name name of the property |
| 158 | + * @param first the first string in the list |
| 159 | + * @param second the second string in the list |
| 160 | + * @param others other strings in the list |
| 161 | + */ |
| 162 | + public B set(String name, String first, String second, String... others) { |
| 163 | + List<StringValue> values = new LinkedList<>(); |
| 164 | + values.add(of(first)); |
| 165 | + values.add(of(second)); |
| 166 | + for (String other : others) { |
| 167 | + values.add(of(other)); |
| 168 | + } |
| 169 | + properties.put(name, of(values)); |
| 170 | + return self(); |
| 171 | + } |
| 172 | + |
| 173 | + /** |
| 174 | + * Sets a property of type {@link LongValue}. |
| 175 | + * |
| 176 | + * @param name name of the property |
| 177 | + * @param value value associated with the property |
| 178 | + */ |
141 | 179 | public B set(String name, long value) { |
142 | 180 | properties.put(name, of(value)); |
143 | 181 | return self(); |
144 | 182 | } |
145 | 183 |
|
| 184 | + /** |
| 185 | + * Sets a list property containing elements of type {@link LongValue}. |
| 186 | + * |
| 187 | + * @param name name of the property |
| 188 | + * @param first the first long in the list |
| 189 | + * @param second the second long in the list |
| 190 | + * @param others other longs in the list |
| 191 | + */ |
| 192 | + public B set(String name, long first, long second, long... others) { |
| 193 | + List<LongValue> values = new LinkedList<>(); |
| 194 | + values.add(of(first)); |
| 195 | + values.add(of(second)); |
| 196 | + for (long other : others) { |
| 197 | + values.add(of(other)); |
| 198 | + } |
| 199 | + properties.put(name, of(values)); |
| 200 | + return self(); |
| 201 | + } |
| 202 | + |
| 203 | + /** |
| 204 | + * Sets a property of type {@link DoubleValue}. |
| 205 | + * |
| 206 | + * @param name name of the property |
| 207 | + * @param value value associated with the property |
| 208 | + */ |
146 | 209 | public B set(String name, double value) { |
147 | 210 | properties.put(name, of(value)); |
148 | 211 | return self(); |
149 | 212 | } |
150 | 213 |
|
| 214 | + /** |
| 215 | + * Sets a list property containing elements of type {@link DoubleValue}. |
| 216 | + * |
| 217 | + * @param name name of the property |
| 218 | + * @param first the first double in the list |
| 219 | + * @param second the second double in the list |
| 220 | + * @param others other doubles in the list |
| 221 | + */ |
| 222 | + public B set(String name, double first, double second, double... others) { |
| 223 | + List<DoubleValue> values = new LinkedList<>(); |
| 224 | + values.add(of(first)); |
| 225 | + values.add(of(second)); |
| 226 | + for (double other : others) { |
| 227 | + values.add(of(other)); |
| 228 | + } |
| 229 | + properties.put(name, of(values)); |
| 230 | + return self(); |
| 231 | + } |
| 232 | + |
| 233 | + /** |
| 234 | + * Sets a property of type {@link BooleanValue}. |
| 235 | + * |
| 236 | + * @param name name of the property |
| 237 | + * @param value value associated with the property |
| 238 | + */ |
151 | 239 | public B set(String name, boolean value) { |
152 | 240 | properties.put(name, of(value)); |
153 | 241 | return self(); |
154 | 242 | } |
155 | 243 |
|
| 244 | + /** |
| 245 | + * Sets a list property containing elements of type {@link BooleanValue}. |
| 246 | + * |
| 247 | + * @param name name of the property |
| 248 | + * @param first the first boolean in the list |
| 249 | + * @param second the second boolean in the list |
| 250 | + * @param others other booleans in the list |
| 251 | + */ |
| 252 | + public B set(String name, boolean first, boolean second, boolean... others) { |
| 253 | + List<BooleanValue> values = new LinkedList<>(); |
| 254 | + values.add(of(first)); |
| 255 | + values.add(of(second)); |
| 256 | + for (boolean other : others) { |
| 257 | + values.add(of(other)); |
| 258 | + } |
| 259 | + properties.put(name, of(values)); |
| 260 | + return self(); |
| 261 | + } |
| 262 | + |
| 263 | + /** |
| 264 | + * Sets a property of type {@link DateTimeValue}. |
| 265 | + * |
| 266 | + * @param name name of the property |
| 267 | + * @param value value associated with the property |
| 268 | + */ |
156 | 269 | public B set(String name, DateTime value) { |
157 | 270 | properties.put(name, of(value)); |
158 | 271 | return self(); |
159 | 272 | } |
160 | 273 |
|
| 274 | + /** |
| 275 | + * Sets a list property containing elements of type {@link DateTimeValue}. |
| 276 | + * |
| 277 | + * @param name name of the property |
| 278 | + * @param first the first {@link DateTime} in the list |
| 279 | + * @param second the second {@link DateTime} in the list |
| 280 | + * @param others other {@link DateTime}s in the list |
| 281 | + */ |
| 282 | + public B set(String name, DateTime first, DateTime second, DateTime... others) { |
| 283 | + List<DateTimeValue> values = new LinkedList<>(); |
| 284 | + values.add(of(first)); |
| 285 | + values.add(of(second)); |
| 286 | + for (DateTime other : others) { |
| 287 | + values.add(of(other)); |
| 288 | + } |
| 289 | + properties.put(name, of(values)); |
| 290 | + return self(); |
| 291 | + } |
| 292 | + |
| 293 | + /** |
| 294 | + * Sets a property of type {@link KeyValue}. |
| 295 | + * |
| 296 | + * @param name name of the property |
| 297 | + * @param value value associated with the property |
| 298 | + */ |
161 | 299 | public B set(String name, Key value) { |
162 | 300 | properties.put(name, of(value)); |
163 | 301 | return self(); |
164 | 302 | } |
165 | 303 |
|
| 304 | + /** |
| 305 | + * Sets a list property containing elements of type {@link KeyValue}. |
| 306 | + * |
| 307 | + * @param name name of the property |
| 308 | + * @param first the first {@link Key} in the list |
| 309 | + * @param second the second {@link Key} in the list |
| 310 | + * @param others other {@link Key}s in the list |
| 311 | + */ |
| 312 | + public B set(String name, Key first, Key second, Key... others) { |
| 313 | + List<KeyValue> values = new LinkedList<>(); |
| 314 | + values.add(of(first)); |
| 315 | + values.add(of(second)); |
| 316 | + for (Key other : others) { |
| 317 | + values.add(of(other)); |
| 318 | + } |
| 319 | + properties.put(name, of(values)); |
| 320 | + return self(); |
| 321 | + } |
| 322 | + |
| 323 | + /** |
| 324 | + * Sets a property of type {@link EntityValue}. |
| 325 | + * |
| 326 | + * @param name name of the property |
| 327 | + * @param value value associated with the property |
| 328 | + */ |
166 | 329 | public B set(String name, FullEntity<?> value) { |
167 | 330 | properties.put(name, of(value)); |
168 | 331 | return self(); |
169 | 332 | } |
170 | 333 |
|
| 334 | + /** |
| 335 | + * Sets a list property containing elements of type {@link EntityValue}. |
| 336 | + * |
| 337 | + * @param name name of the property |
| 338 | + * @param first the first {@link FullEntity} in the list |
| 339 | + * @param second the second {@link FullEntity} in the list |
| 340 | + * @param others other entities in the list |
| 341 | + */ |
| 342 | + public B set(String name, FullEntity<?> first, FullEntity<?> second, FullEntity<?>... others) { |
| 343 | + List<EntityValue> values = new LinkedList<>(); |
| 344 | + values.add(of(first)); |
| 345 | + values.add(of(second)); |
| 346 | + for (FullEntity<?> other : others) { |
| 347 | + values.add(of(other)); |
| 348 | + } |
| 349 | + properties.put(name, of(values)); |
| 350 | + return self(); |
| 351 | + } |
| 352 | + |
| 353 | + /** |
| 354 | + * Sets a property of type {@link ListValue}. |
| 355 | + * |
| 356 | + * @param name name of the property |
| 357 | + * @param values list of values associated with the property |
| 358 | + */ |
171 | 359 | public B set(String name, List<? extends Value<?>> values) { |
172 | 360 | properties.put(name, of(values)); |
173 | 361 | return self(); |
174 | 362 | } |
175 | 363 |
|
176 | | - public B set(String name, Value<?> value, Value<?>... other) { |
177 | | - properties.put(name, of(value, other)); |
| 364 | + /** |
| 365 | + * Sets a property of type {@link ListValue}. |
| 366 | + * |
| 367 | + * @param name name of the property |
| 368 | + * @param first the first value in the list |
| 369 | + * @param second the second value in the list |
| 370 | + * @param others other values in the list |
| 371 | + */ |
| 372 | + public B set(String name, Value<?> first, Value<?> second, Value<?>... others) { |
| 373 | + properties.put(name, ListValue.builder().addValue(first).addValue(second, others).build()); |
178 | 374 | return self(); |
179 | 375 | } |
180 | 376 |
|
| 377 | + /** |
| 378 | + * Sets a property of type {@link BlobValue}. |
| 379 | + * |
| 380 | + * @param name name of the property |
| 381 | + * @param value value associated with the property |
| 382 | + */ |
181 | 383 | public B set(String name, Blob value) { |
182 | 384 | properties.put(name, of(value)); |
183 | 385 | return self(); |
184 | 386 | } |
185 | 387 |
|
| 388 | + /** |
| 389 | + * Sets a list property containing elements of type {@link BlobValue}. |
| 390 | + * |
| 391 | + * @param name name of the property |
| 392 | + * @param first the first {@link Blob} in the list |
| 393 | + * @param second the second {@link Blob} in the list |
| 394 | + * @param others other {@link Blob}s in the list |
| 395 | + */ |
| 396 | + public B set(String name, Blob first, Blob second, Blob... others) { |
| 397 | + List<BlobValue> values = new LinkedList<>(); |
| 398 | + values.add(of(first)); |
| 399 | + values.add(of(second)); |
| 400 | + for (Blob other : others) { |
| 401 | + values.add(of(other)); |
| 402 | + } |
| 403 | + properties.put(name, of(values)); |
| 404 | + return self(); |
| 405 | + } |
| 406 | + |
| 407 | + /** |
| 408 | + * Sets a property of type {@code NullValue}. |
| 409 | + * |
| 410 | + * @param name name of the property |
| 411 | + */ |
186 | 412 | public B setNull(String name) { |
187 | 413 | properties.put(name, of()); |
188 | 414 | return self(); |
@@ -348,8 +574,8 @@ public <K extends IncompleteKey> FullEntity<K> getEntity(String name) { |
348 | 574 | * @throws ClassCastException if value is not a list of values |
349 | 575 | */ |
350 | 576 | @SuppressWarnings("unchecked") |
351 | | - public List<? extends Value<?>> getList(String name) { |
352 | | - return ((Value<List<? extends Value<?>>>) getValue(name)).get(); |
| 577 | + public <T extends Value<?>> List<T> getList(String name) { |
| 578 | + return (List<T>) getValue(name).get(); |
353 | 579 | } |
354 | 580 |
|
355 | 581 | /** |
|
0 commit comments