001/* 002 * ModeShape (http://www.modeshape.org) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.modeshape.schematic.document; 017 018import java.text.ParseException; 019import java.util.Date; 020import java.util.UUID; 021import java.util.regex.Pattern; 022 023public interface EditableArray extends EditableDocument, Array { 024 025 /** 026 * Set the value for the field with the given name to the supplied value. 027 * 028 * @param name The name of the field 029 * @param value the new value for the field 030 * @return This document, to allow for chaining methods 031 */ 032 @Override 033 EditableArray set( String name, 034 Object value ); 035 036 /** 037 * Set the value for the field with the given name to the supplied value. 038 * 039 * @param index The index in the array 040 * @param value the new value 041 * @return This array, to allow for chaining methods 042 */ 043 EditableArray setValue( int index, 044 Object value ); 045 046 /** 047 * Insert the value for the field with the given name to the supplied value. 048 * 049 * @param index The index in the array 050 * @param value the new value 051 * @return This array, to allow for chaining methods 052 */ 053 EditableArray addValue( int index, 054 Object value ); 055 056 /** 057 * Add the supplied value to this array. 058 * 059 * @param value the new value 060 * @return This array, to allow for chaining methods 061 */ 062 EditableArray addValue( Object value ); 063 064 /** 065 * Add the supplied value to this array if and only if there is not already an equivalent value in the array. 066 * 067 * @param value the value 068 * @return This array, to allow for chaining methods 069 */ 070 EditableDocument addValueIfAbsent( Object value ); 071 072 /** 073 * Set the value for the field at the given index to the supplied boolean value. 074 * 075 * @param name The name of the field, which is the string representation of the index in the array 076 * @param value the new value for the field 077 * @return This array, to allow for chaining methods 078 */ 079 @Override 080 EditableArray setBoolean( String name, 081 boolean value ); 082 083 /** 084 * Set the value for the field at the given index to the supplied integer value. 085 * 086 * @param name The name of the field, which is the string representation of the index in the array 087 * @param value the new value for the field 088 * @return This document, to allow for chaining methods 089 */ 090 @Override 091 EditableArray setNumber( String name, 092 int value ); 093 094 /** 095 * Set the value for the field at the given index to the supplied long value. 096 * 097 * @param name The name of the field, which is the string representation of the index in the array 098 * @param value the new value for the field 099 * @return This document, to allow for chaining methods 100 */ 101 @Override 102 EditableArray setNumber( String name, 103 long value ); 104 105 /** 106 * Set the value for the field at the given index to the supplied float value. 107 * 108 * @param name The name of the field, which is the string representation of the index in the array 109 * @param value the new value for the field 110 * @return This document, to allow for chaining methods 111 */ 112 @Override 113 EditableArray setNumber( String name, 114 float value ); 115 116 /** 117 * Set the value for the field at the given index to the supplied double value. 118 * 119 * @param name The name of the field, which is the string representation of the index in the array 120 * @param value the new value for the field 121 * @return This document, to allow for chaining methods 122 */ 123 @Override 124 EditableArray setNumber( String name, 125 double value ); 126 127 /** 128 * Set the value for the field at the given index to the supplied string value. 129 * 130 * @param name The name of the field, which is the string representation of the index in the array 131 * @param value the new value for the field 132 * @return This document, to allow for chaining methods 133 */ 134 @Override 135 EditableArray setString( String name, 136 String value ); 137 138 /** 139 * Set the value for the field at the given index to a {@link Symbol} created from the supplied string value. Symbols are 140 * defined in the BSON specification as being similar to a string but which exists for those languages that have a specific 141 * symbol type. Symbols are serialized to JSON as a normal string. 142 * 143 * @param name The name of the field, which is the string representation of the index in the array 144 * @param value the new value for the field 145 * @return This document, to allow for chaining methods 146 * @see #setString(String, String) 147 */ 148 @Override 149 EditableArray setSymbol( String name, 150 String value ); 151 152 /** 153 * Set the value for the field at the given index to be a new, empty Document. 154 * 155 * @param name The name of the field, which is the string representation of the index in the array 156 * @return The editable document that was just created; never null 157 */ 158 @Override 159 EditableDocument setDocument( String name ); 160 161 /** 162 * Set the value for the field at the given index to be the supplied Document. 163 * 164 * @param name The name of the field, which is the string representation of the index in the array 165 * @param document the document 166 * @return The editable document that was just set as the value for the named field; never null and may or may not be the same 167 * instance as the supplied <code>document</code>. 168 */ 169 @Override 170 EditableDocument setDocument( String name, 171 Document document ); 172 173 /** 174 * Get the existing document value in this array for the given index. 175 * 176 * @param name The name of the field, which is the string representation of the index in the array 177 * @return The editable document field value, if found, or null if there is no such pair or if the value is not a document 178 */ 179 @Override 180 EditableDocument getDocument( String name ); 181 182 /** 183 * Set the value for the field at the given index to be a new, empty array. 184 * 185 * @param name The name of the field, which is the string representation of the index in the array 186 * @return The editable array that was just created; never null 187 */ 188 @Override 189 EditableArray setArray( String name ); 190 191 /** 192 * Set the value for the field at the given index to be the supplied array. 193 * 194 * @param name The name of the field, which is the string representation of the index in the array 195 * @param array the array 196 * @return The editable array that was just set as the value for the named field; never null and may or may not be the same 197 * instance as the supplied <code>array</code>. 198 */ 199 @Override 200 EditableArray setArray( String name, 201 Array array ); 202 203 /** 204 * Get the existing array value in this array for the given index. 205 * 206 * @param name The name of the field, which is the string representation of the index in the array 207 * @return The editable array field value, if found, or null if there is no such pair or if the value is not an array 208 */ 209 @Override 210 EditableArray getArray( String name ); 211 212 /** 213 * Set the value for the field at the given index to the supplied date value. 214 * 215 * @param name The name of the field, which is the string representation of the index in the array 216 * @param value the new value for the field 217 * @return This document, to allow for chaining methods 218 */ 219 @Override 220 EditableArray setDate( String name, 221 Date value ); 222 223 /** 224 * Set the value for the field at the given index to the date value parsed from the ISO-8601 date representation. 225 * Specifically, the date string must match one of these patterns: 226 * <ul> 227 * <li>"<code><i>yyyy</i>-<i>MM</i>-<i>dd</i>T<i>HH</i>:<i>mm</i>:<i>ss</i></code>" where "<code>T</code>" is a literal 228 * character</li> 229 * <li>"<code><i>yyyy</i>-<i>MM</i>-<i>dd</i>T<i>HH</i>:<i>mm</i>:<i>ss</i>Z</code>" where "<code>T</code>" and " 230 * <code>Z</code>" are literal characters</li> 231 * <li>"<code><i>yyyy</i>-<i>MM</i>-<i>dd</i>T<i>HH</i>:<i>mm</i>:<i>ss</i>GMT+<i>00</i>:<i>00</i></code>" where " 232 * <code>T</code>", and "<code>GMT</code>" are literal characters</li> 233 * </ul> 234 * 235 * @param name The name of the field, which is the string representation of the index in the array 236 * @param isoDate the new value for the field 237 * @return This document, to allow for chaining methods 238 * @throws ParseException if the supplied value could not be parsed into a valid date 239 */ 240 @Override 241 EditableArray setDate( String name, 242 String isoDate ) throws ParseException; 243 244 /** 245 * Set the value for the field at the given index to a {@link Timestamp} with the supplied time in seconds and increment. Note 246 * that {@link Date} values are recommended for most purposes, as they are better suited to most applications' representations 247 * of time instants. 248 * 249 * @param name The name of the field, which is the string representation of the index in the array 250 * @param timeInSeconds the time in seconds for the new Timestamp 251 * @param increment the time increment for the new Timestamp 252 * @return This document, to allow for chaining methods 253 * @see #setDate(String, Date) 254 */ 255 @Override 256 EditableArray setTimestamp( String name, 257 int timeInSeconds, 258 int increment ); 259 260 /** 261 * Set the value for the field at the given index to an {@link ObjectId} created from the supplied hexadecimal binary value. 262 * Object IDs are defined by the BSON specification as 12-byte binary values designed to have a reasonably high probability of 263 * being unique when allocated. Since there is no explicit way to represent these in a JSON document, each ObjectId value is 264 * serialized in a JSON document as a nested document of the form: 265 * 266 * <pre> 267 * { "$oid" : "<i>12bytesOfIdInBase16</i>" } 268 * </pre> 269 * 270 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 271 * be converted to an ObjectId value. 272 * <p> 273 * For example, an ObjectId with time value of "1310745823", machine value of "1", process value of "2", and increment value 274 * of "3" would be written as 275 * 276 * <pre> 277 * { "$oid" : "4e2064df0000010002000003" } 278 * </pre> 279 * 280 * </p> 281 * 282 * @param name The name of the field, which is the string representation of the index in the array 283 * @param hex the hexadecimal binary value for the ObjectId 284 * @return This document, to allow for chaining methods 285 * @see #setObjectId(String, byte[]) 286 * @see #setObjectId(String, int, int, int, int) 287 */ 288 @Override 289 EditableArray setObjectId( String name, 290 String hex ); 291 292 /** 293 * Set the value for the field at the given index to an {@link ObjectId} created from the supplied 12-byte binary value. 294 * Object IDs are defined by the BSON specification as 12-byte binary values designed to have a reasonably high probability of 295 * being unique when allocated. Since there is no explicit way to represent these in a JSON document, each ObjectId value is 296 * serialized in a JSON document as a nested document of the form: 297 * 298 * <pre> 299 * { "$oid" : "<i>12bytesOfIdInBase16</i>" } 300 * </pre> 301 * 302 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 303 * be converted to an ObjectId value. 304 * <p> 305 * For example, an ObjectId with time value of "1310745823", machine value of "1", process value of "2", and increment value 306 * of "3" would be written as 307 * 308 * <pre> 309 * { "$oid" : "4e2064df0000010002000003" } 310 * </pre> 311 * 312 * </p> 313 * 314 * @param name The name of the field, which is the string representation of the index in the array 315 * @param bytes the 12-byte value for the ObjectId 316 * @return This document, to allow for chaining methods 317 * @see #setObjectId(String, String) 318 * @see #setObjectId(String, int, int, int, int) 319 */ 320 @Override 321 EditableArray setObjectId( String name, 322 byte[] bytes ); 323 324 /** 325 * Set the value for the field at the given index to an {@link ObjectId} created from the supplied hexadecimal binary value. 326 * Object IDs are defined by the BSON specification as 12-byte binary values designed to have a reasonably high probability of 327 * being unique when allocated. Since there is no explicit way to represent these in a JSON document, each ObjectId value is 328 * serialized in a JSON document as a nested document of the form: 329 * 330 * <pre> 331 * { "$oid" : "<i>12bytesOfIdInBase16</i>" } 332 * </pre> 333 * 334 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 335 * be converted to an ObjectId value. 336 * <p> 337 * For example, an ObjectId with time value of "1310745823", machine value of "1", process value of "2", and increment value 338 * of "3" would be written as 339 * 340 * <pre> 341 * { "$oid" : "4e2064df0000010002000003" } 342 * </pre> 343 * 344 * </p> 345 * 346 * @param name The name of the field, which is the string representation of the index in the array 347 * @param time the Unix-style timestamp, which is a signed integer representing the number of seconds before or after January 348 * 1st 1970 (UTC) 349 * @param machine the first three bytes of the (md5) hash of the machine host name, or of the mac/network address, or the 350 * virtual machine id 351 * @param process the 2 bytes of the process id (or thread id) of the process generating the object id 352 * @param inc an ever incrementing value, or a random number if a counter can't be used in the language/runtime 353 * @return This document, to allow for chaining methods 354 * @see #setObjectId(String, String) 355 * @see #setObjectId(String, byte[]) 356 */ 357 @Override 358 EditableArray setObjectId( String name, 359 int time, 360 int machine, 361 int process, 362 int inc ); 363 364 /** 365 * Set the value for the field at the given index to the supplied regular expression. Regular expression values are 366 * represented in memory using {@link Pattern} instances, and are stored natively in BSON as regular expressions. However, 367 * when serialized to JSON, regular expressions are written as nested documents of the form: 368 * 369 * <pre> 370 * { "$regex" : "<i>pattern</i>" } 371 * </pre> 372 * 373 * where "<i>pattern</i>" is the regular expression pattern. 374 * <p> 375 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 376 * be converted to a regular expression value. 377 * </p> 378 * 379 * @param name The name of the field, which is the string representation of the index in the array 380 * @param pattern the regular expression pattern string 381 * @return This document, to allow for chaining methods 382 * @see #setRegularExpression(String, String, int) 383 */ 384 @Override 385 EditableArray setRegularExpression( String name, 386 String pattern ); 387 388 /** 389 * Set the value for the field at the given index to the supplied regular expression. Regular expression values are 390 * represented in memory using {@link Pattern} instances, and are stored natively in BSON as regular expressions. However, 391 * when serialized to JSON, regular expressions are written as nested documents of the form: 392 * 393 * <pre> 394 * { "$regex" : "<i>pattern</i>", "$options" : "<i>flags</i>" } 395 * </pre> 396 * 397 * where "<i>pattern</i>" is the regular expression pattern, and "<i>flags</i>" is a string representation of the regular 398 * expression options. 399 * <p> 400 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 401 * be converted to a regular expression value. 402 * </p> 403 * 404 * @param name The name of the field, which is the string representation of the index in the array 405 * @param pattern the regular expression pattern string 406 * @param flags the bitwise-anded {@link Pattern} options: {@link Pattern#CANON_EQ}, {@link Pattern#CASE_INSENSITIVE}, 407 * {@link Pattern#CASE_INSENSITIVE}, {@link Pattern#COMMENTS}, {@link Pattern#DOTALL}, {@link Pattern#LITERAL}, 408 * {@link Pattern#MULTILINE}, {@link Pattern#UNICODE_CASE}, and {@link Pattern#UNIX_LINES} 409 * @return This document, to allow for chaining methods 410 * @see #setRegularExpression(String, String) 411 */ 412 @Override 413 EditableArray setRegularExpression( String name, 414 String pattern, 415 int flags ); 416 417 /** 418 * Set the value for the field at the given index to be a null value. Both JSON and BSON formats support null values, and 419 * {@link Null} is used for the value in the in-memory representation. The {@link #isNull(String)} methods can be used to 420 * determine if a field has been set to null, or {@link #isNullOrMissing(String)} if the field has not be set or if it has 421 * been set to null. 422 * 423 * @param name The name of the field, which is the string representation of the index in the array 424 * @return This document, to allow for chaining methods 425 * @see #isNull(String) 426 * @see #isNullOrMissing(String) 427 */ 428 @Override 429 EditableArray setNull( String name ); 430 431 /** 432 * Set the value for the field at the given index to be a binary value. JSON does not formally support binary values, and so 433 * such values will be encoded using a nested document of the form: 434 * 435 * <pre> 436 * { "$type" : <i>typeAsInt</i>, "$base64" : "<i>bytesInBase64</i>" } 437 * </pre> 438 * 439 * where "<i>typeAsInt</i>" is the integer representation of the {@link Bson.BinaryType BSON type}, and "<i>bytesInBase64</i>" is 440 * the Base64 encoding of the actual Binary {@link Binary#getBytes() bytes}. 441 * <p> 442 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 443 * be converted to Binary value. 444 * </p> 445 * 446 * @param name The name of the field, which is the string representation of the index in the array 447 * @param type one of the {@link Bson.BinaryType BSON type} constants denoting the type of the {@link Binary} value 448 * @param data the bytes for the {@link Binary} value 449 * @return This document, to allow for chaining methods 450 */ 451 @Override 452 EditableArray setBinary( String name, 453 byte type, 454 byte[] data ); 455 456 /** 457 * Set the value for the field at the given index to be a {@link UUID}. JSON does not formally support binary values, and so 458 * such values will be encoded using a nested document of the form: 459 * 460 * <pre> 461 * { "$uuid" : "<i>string-form-of-uuid</i>" } 462 * </pre> 463 * 464 * where "<i>string-form-of-uuid</i>" is the UUID's {@link UUID#toString() string representation} 465 * <p> 466 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 467 * be converted to UUID value. 468 * </p> 469 * 470 * @param name The name of the field, which is the string representation of the index in the array 471 * @param uuid the UUID value 472 * @return This document, to allow for chaining methods 473 */ 474 @Override 475 EditableArray setUuid( String name, 476 UUID uuid ); 477 478 /** 479 * Set the value for the field at the given index to be a {@link Code} or {@link CodeWithScope}. JSON does not formally 480 * support such values, and so when written to JSON they will be encoded using a nested document of the form: 481 * 482 * <pre> 483 * { "$code" : "<i>code</i>" } 484 * </pre> 485 * 486 * or, if there is a scope document 487 * 488 * <pre> 489 * { "$code" : "<i>code</i>", "$scope" : <i>scope document</i> } 490 * </pre> 491 * 492 * where "<i>code</i>" is the {@link Code}'s {@link Code#getCode() JavaScript code} and <i>scopeDocument</i> is the nested 493 * document representing the {@link CodeWithScope#getScope() scope} in which the JavaScript code should be evaluated. 494 * <p> 495 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 496 * be converted to {@link Code} or {@link CodeWithScope} value. 497 * </p> 498 * <p> 499 * Note that when <code>includeScope</code> is <code>true</code>, the returned {@link EditableArray} can be used to populate 500 * the scope document. 501 * 502 * @param name The name of the field, which is the string representation of the index in the array 503 * @param code the code 504 * @param includeScope true if the code should include a scope (and if this method should return an {@link EditableArray} for 505 * this scope document), or false otherwise 506 * @return if <code>includeScope</code> is <code>true</code>, then the {@link EditableDocument} for the scope; otherwise, this 507 * array to allow for chaining methods 508 * @see #setCode(String, String, Document) 509 */ 510 @Override 511 EditableDocument setCode( String name, 512 String code, 513 boolean includeScope ); 514 515 /** 516 * Set the value for the field at the given index to be a {@link Code} or {@link CodeWithScope}. JSON does not formally 517 * support such values, and so when written to JSON they will be encoded using a nested document of the form: 518 * 519 * <pre> 520 * { "$code" : "<i>code</i>" } 521 * </pre> 522 * 523 * or, if there is a scope document 524 * 525 * <pre> 526 * { "$code" : "<i>code</i>", "$scope" : <i>scope document</i> } 527 * </pre> 528 * 529 * where "<i>code</i>" is the {@link Code}'s {@link Code#getCode() JavaScript code} and <i>scopeDocument</i> is the nested 530 * document representing the {@link CodeWithScope#getScope() scope} in which the JavaScript code should be evaluated. 531 * <p> 532 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 533 * be converted to {@link Code} or {@link CodeWithScope} value. 534 * </p> 535 * 536 * @param name The name of the field, which is the string representation of the index in the array 537 * @param code the code 538 * @param scope the scope in which the JavaScript code should be evaulated, or null if there is no scope 539 * @return the {@link EditableDocument} for the scope 540 * @see #setCode(String, String, boolean) 541 */ 542 @Override 543 EditableDocument setCode( String name, 544 String code, 545 Document scope ); 546 547 /** 548 * Set the value for the field at the given index to the supplied boolean value. 549 * 550 * @param index The index in the array at which the value is to be set 551 * @param value the new value for the field 552 * @return This document, to allow for chaining methods 553 */ 554 EditableArray setBoolean( int index, 555 boolean value ); 556 557 /** 558 * Set the value for the field at the given index to the supplied integer value. 559 * 560 * @param index The index in the array at which the value is to be set 561 * @param value the new value for the field 562 * @return This document, to allow for chaining methods 563 */ 564 EditableArray setNumber( int index, 565 int value ); 566 567 /** 568 * Set the value for the field at the given index to the supplied long value. 569 * 570 * @param index The index in the array at which the value is to be set 571 * @param value the new value for the field 572 * @return This document, to allow for chaining methods 573 */ 574 EditableArray setNumber( int index, 575 long value ); 576 577 /** 578 * Set the value for the field at the given index to the supplied float value. 579 * 580 * @param index The index in the array at which the value is to be set 581 * @param value the new value for the field 582 * @return This document, to allow for chaining methods 583 */ 584 EditableArray setNumber( int index, 585 float value ); 586 587 /** 588 * Set the value for the field at the given index to the supplied double value. 589 * 590 * @param index The index in the array at which the value is to be set 591 * @param value the new value for the field 592 * @return This document, to allow for chaining methods 593 */ 594 EditableArray setNumber( int index, 595 double value ); 596 597 /** 598 * Set the value for the field at the given index to the supplied string value. 599 * 600 * @param index The index in the array at which the value is to be set 601 * @param value the new value for the field 602 * @return This document, to allow for chaining methods 603 */ 604 EditableArray setString( int index, 605 String value ); 606 607 /** 608 * Set the value for the field at the given index to a {@link Symbol} created from the supplied string value. Symbols are 609 * defined in the BSON specification as being similar to a string but which exists for those languages that have a specific 610 * symbol type. Symbols are serialized to JSON as a normal string. 611 * 612 * @param index The index in the array at which the value is to be set 613 * @param value the new value for the field 614 * @return This document, to allow for chaining methods 615 * @see #setString(int, String) 616 */ 617 EditableArray setSymbol( int index, 618 String value ); 619 620 /** 621 * Set the value for the field at the given index to be a new, empty Document. 622 * 623 * @param index The index in the array at which the value is to be set 624 * @return The editable document that was just created; never null 625 */ 626 EditableDocument setDocument( int index ); 627 628 /** 629 * Set the value for the field at the given index to be the supplied Document. 630 * 631 * @param index The index in the array at which the value is to be set 632 * @param document the document 633 * @return The editable document that was just set as the value at the supplied index in this array; never null and may or may 634 * not be the same instance as the supplied <code>document</code>. 635 */ 636 EditableDocument setDocument( int index, 637 Document document ); 638 639 /** 640 * Set the value for the field at the given index to be a new, empty array. 641 * 642 * @param index The index in the array at which the value is to be set 643 * @return The editable array that was just created; never null 644 */ 645 EditableArray setArray( int index ); 646 647 /** 648 * Set the value for the field at the given index to be the supplied array. 649 * 650 * @param index The index in the array at which the value is to be set 651 * @param array the array 652 * @return The editable array that was just set as the value at the supplied index in this array; never null and may or may 653 * not be the same instance as the supplied <code>array</code>. 654 */ 655 EditableArray setArray( int index, 656 Array array ); 657 658 /** 659 * Set the value for the field at the given index to the supplied date value. 660 * 661 * @param index The index in the array at which the value is to be set 662 * @param value the new value for the field 663 * @return This document, to allow for chaining methods 664 */ 665 EditableArray setDate( int index, 666 Date value ); 667 668 /** 669 * Set the value for the field at the given index to the date value parsed from the ISO-8601 date representation. 670 * Specifically, the date string must match one of these patterns: 671 * <ul> 672 * <li>"<code><i>yyyy</i>-<i>MM</i>-<i>dd</i>T<i>HH</i>:<i>mm</i>:<i>ss</i></code>" where "<code>T</code>" is a literal 673 * character</li> 674 * <li>"<code><i>yyyy</i>-<i>MM</i>-<i>dd</i>T<i>HH</i>:<i>mm</i>:<i>ss</i>Z</code>" where "<code>T</code>" and " 675 * <code>Z</code>" are literal characters</li> 676 * <li>"<code><i>yyyy</i>-<i>MM</i>-<i>dd</i>T<i>HH</i>:<i>mm</i>:<i>ss</i>GMT+<i>00</i>:<i>00</i></code>" where " 677 * <code>T</code>", and "<code>GMT</code>" are literal characters</li> 678 * </ul> 679 * 680 * @param index The index in the array at which the value is to be set 681 * @param isoDate the new value for the field 682 * @return This document, to allow for chaining methods 683 * @throws ParseException if the supplied value could not be parsed into a valid date 684 */ 685 EditableArray setDate( int index, 686 String isoDate ) throws ParseException; 687 688 /** 689 * Set the value for the field at the given index to a {@link Timestamp} with the supplied time in seconds and increment. Note 690 * that {@link Date} values are recommended for most purposes, as they are better suited to most applications' representations 691 * of time instants. 692 * 693 * @param index The index in the array at which the value is to be set 694 * @param timeInSeconds the time in seconds for the new Timestamp 695 * @param increment the time increment for the new Timestamp 696 * @return This document, to allow for chaining methods 697 * @see #setDate(int, Date) 698 */ 699 EditableArray setTimestamp( int index, 700 int timeInSeconds, 701 int increment ); 702 703 /** 704 * Set the value for the field at the given index to an {@link ObjectId} created from the supplied hexadecimal binary value. 705 * Object IDs are defined by the BSON specification as 12-byte binary values designed to have a reasonably high probability of 706 * being unique when allocated. Since there is no explicit way to represent these in a JSON document, each ObjectId value is 707 * serialized in a JSON document as a nested document of the form: 708 * 709 * <pre> 710 * { "$oid" : "<i>12bytesOfIdInBase16</i>" } 711 * </pre> 712 * 713 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 714 * be converted to an ObjectId value. 715 * <p> 716 * For example, an ObjectId with time value of "1310745823", machine value of "1", process value of "2", and increment value 717 * of "3" would be written as 718 * 719 * <pre> 720 * { "$oid" : "4e2064df0000010002000003" } 721 * </pre> 722 * 723 * </p> 724 * 725 * @param index The index in the array at which the value is to be set 726 * @param hex the hexadecimal binary value for the ObjectId 727 * @return This document, to allow for chaining methods 728 * @see #setObjectId(int, byte[]) 729 * @see #setObjectId(int, int, int, int, int) 730 */ 731 EditableArray setObjectId( int index, 732 String hex ); 733 734 /** 735 * Set the value for the field at the given index to an {@link ObjectId} created from the supplied 12-byte binary value. 736 * Object IDs are defined by the BSON specification as 12-byte binary values designed to have a reasonably high probability of 737 * being unique when allocated. Since there is no explicit way to represent these in a JSON document, each ObjectId value is 738 * serialized in a JSON document as a nested document of the form: 739 * 740 * <pre> 741 * { "$oid" : "<i>12bytesOfIdInBase16</i>" } 742 * </pre> 743 * 744 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 745 * be converted to an ObjectId value. 746 * <p> 747 * For example, an ObjectId with time value of "1310745823", machine value of "1", process value of "2", and increment value 748 * of "3" would be written as 749 * 750 * <pre> 751 * { "$oid" : "4e2064df0000010002000003" } 752 * </pre> 753 * 754 * </p> 755 * 756 * @param index The index in the array at which the value is to be set 757 * @param bytes the 12-byte value for the ObjectId 758 * @return This document, to allow for chaining methods 759 * @see #setObjectId(int, String) 760 * @see #setObjectId(int, int, int, int, int) 761 */ 762 EditableArray setObjectId( int index, 763 byte[] bytes ); 764 765 /** 766 * Set the value for the field at the given index to an {@link ObjectId} created from the supplied hexadecimal binary value. 767 * Object IDs are defined by the BSON specification as 12-byte binary values designed to have a reasonably high probability of 768 * being unique when allocated. Since there is no explicit way to represent these in a JSON document, each ObjectId value is 769 * serialized in a JSON document as a nested document of the form: 770 * 771 * <pre> 772 * { "$oid" : "<i>12bytesOfIdInBase16</i>" } 773 * </pre> 774 * 775 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 776 * be converted to an ObjectId value. 777 * <p> 778 * For example, an ObjectId with time value of "1310745823", machine value of "1", process value of "2", and increment value 779 * of "3" would be written as 780 * 781 * <pre> 782 * { "$oid" : "4e2064df0000010002000003" } 783 * </pre> 784 * 785 * </p> 786 * 787 * @param index The index in the array at which the value is to be set 788 * @param time the Unix-style timestamp, which is a signed integer representing the number of seconds before or after January 789 * 1st 1970 (UTC) 790 * @param machine the first three bytes of the (md5) hash of the machine host name, or of the mac/network address, or the 791 * virtual machine id 792 * @param process the 2 bytes of the process id (or thread id) of the process generating the object id 793 * @param inc an ever incrementing value, or a random number if a counter can't be used in the language/runtime 794 * @return This document, to allow for chaining methods 795 * @see #setObjectId(int, String) 796 * @see #setObjectId(int, byte[]) 797 */ 798 EditableArray setObjectId( int index, 799 int time, 800 int machine, 801 int process, 802 int inc ); 803 804 /** 805 * Set the value for the field at the given index to the supplied regular expression. Regular expression values are 806 * represented in memory using {@link Pattern} instances, and are stored natively in BSON as regular expressions. However, 807 * when serialized to JSON, regular expressions are written as nested documents of the form: 808 * 809 * <pre> 810 * { "$regex" : "<i>pattern</i>" } 811 * </pre> 812 * 813 * where "<i>pattern</i>" is the regular expression pattern. 814 * <p> 815 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 816 * be converted to a regular expression value. 817 * </p> 818 * 819 * @param index The index in the array at which the value is to be set 820 * @param pattern the regular expression pattern string 821 * @return This document, to allow for chaining methods 822 * @see #setRegularExpression(int, String, int) 823 */ 824 EditableArray setRegularExpression( int index, 825 String pattern ); 826 827 /** 828 * Set the value for the field at the given index to the supplied regular expression. Regular expression values are 829 * represented in memory using {@link Pattern} instances, and are stored natively in BSON as regular expressions. However, 830 * when serialized to JSON, regular expressions are written as nested documents of the form: 831 * 832 * <pre> 833 * { "$regex" : "<i>pattern</i>", "$options" : "<i>flags</i>" } 834 * </pre> 835 * 836 * where "<i>pattern</i>" is the regular expression pattern, and "<i>flags</i>" is a string representation of the regular 837 * expression options. 838 * <p> 839 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 840 * be converted to a regular expression value. 841 * </p> 842 * 843 * @param index The index in the array at which the value is to be set 844 * @param pattern the regular expression pattern string 845 * @param flags the bitwise-anded {@link Pattern} options: {@link Pattern#CANON_EQ}, {@link Pattern#CASE_INSENSITIVE}, 846 * {@link Pattern#CASE_INSENSITIVE}, {@link Pattern#COMMENTS}, {@link Pattern#DOTALL}, {@link Pattern#LITERAL}, 847 * {@link Pattern#MULTILINE}, {@link Pattern#UNICODE_CASE}, and {@link Pattern#UNIX_LINES} 848 * @return This document, to allow for chaining methods 849 * @see #setRegularExpression(int, String) 850 */ 851 EditableArray setRegularExpression( int index, 852 String pattern, 853 int flags ); 854 855 /** 856 * Set the value for the field at the given index to be a null value. Both JSON and BSON formats support null values, and 857 * {@link Null} is used for the value in the in-memory representation. The {@link #isNull(String)} methods can be used to 858 * determine if a field has been set to null, or {@link #isNullOrMissing(String)} if the field has not be set or if it has 859 * been set to null. 860 * 861 * @param index The index in the array at which the value is to be set 862 * @return This document, to allow for chaining methods 863 * @see #isNull(String) 864 * @see #isNullOrMissing(String) 865 */ 866 EditableArray setNull( int index ); 867 868 /** 869 * Set the value for the field at the given index to be a binary value. JSON does not formally support binary values, and so 870 * such values will be encoded using a nested document of the form: 871 * 872 * <pre> 873 * { "$type" : <i>typeAsInt</i>, "$base64" : "<i>bytesInBase64</i>" } 874 * </pre> 875 * 876 * where "<i>typeAsInt</i>" is the integer representation of the {@link Bson.BinaryType BSON type}, and "<i>bytesInBase64</i>" is 877 * the Base64 encoding of the actual Binary {@link Binary#getBytes() bytes}. 878 * <p> 879 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 880 * be converted to Binary value. 881 * </p> 882 * 883 * @param index The index in the array at which the value is to be set 884 * @param type one of the {@link Bson.BinaryType BSON type} constants denoting the type of the {@link Binary} value 885 * @param data the bytes for the {@link Binary} value 886 * @return This document, to allow for chaining methods 887 */ 888 EditableArray setBinary( int index, 889 byte type, 890 byte[] data ); 891 892 /** 893 * Set the value for the field at the given index to be a {@link UUID}. JSON does not formally support binary values, and so 894 * such values will be encoded using a nested document of the form: 895 * 896 * <pre> 897 * { "$uuid" : "<i>string-form-of-uuid</i>" } 898 * </pre> 899 * 900 * where "<i>string-form-of-uuid</i>" is the UUID's {@link UUID#toString() string representation} 901 * <p> 902 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 903 * be converted to UUID value. 904 * </p> 905 * 906 * @param index The index in the array at which the value is to be set 907 * @param uuid the UUID value 908 * @return This document, to allow for chaining methods 909 */ 910 EditableArray setUuid( int index, 911 UUID uuid ); 912 913 /** 914 * Set the value for the field at the given index to be a {@link Code} or {@link CodeWithScope}. JSON does not formally 915 * support such values, and so when written to JSON they will be encoded using a nested document of the form: 916 * 917 * <pre> 918 * { "$code" : "<i>code</i>" } 919 * </pre> 920 * 921 * or, if there is a scope document 922 * 923 * <pre> 924 * { "$code" : "<i>code</i>", "$scope" : <i>scope document</i> } 925 * </pre> 926 * 927 * where "<i>code</i>" is the {@link Code}'s {@link Code#getCode() JavaScript code} and <i>scopeDocument</i> is the nested 928 * document representing the {@link CodeWithScope#getScope() scope} in which the JavaScript code should be evaluated. 929 * <p> 930 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 931 * be converted to {@link Code} or {@link CodeWithScope} value. 932 * </p> 933 * <p> 934 * Note that when <code>includeScope</code> is <code>true</code>, the returned {@link EditableArray} can be used to populate 935 * the scope document. 936 * 937 * @param index The index in the array at which the value is to be set 938 * @param code the code 939 * @param includeScope true if the code should include a scope (and if this method should return an {@link EditableArray} for 940 * this scope document), or false otherwise 941 * @return if <code>includeScope</code> is <code>true</code>, then the {@link EditableDocument} for the scope; otherwise, this 942 * array to allow for chaining methods 943 * @see #setCode(int, String, Document) 944 */ 945 EditableDocument setCode( int index, 946 String code, 947 boolean includeScope ); 948 949 /** 950 * Set the value for the field at the given index to be a {@link Code} or {@link CodeWithScope}. JSON does not formally 951 * support such values, and so when written to JSON they will be encoded using a nested document of the form: 952 * 953 * <pre> 954 * { "$code" : "<i>code</i>" } 955 * </pre> 956 * 957 * or, if there is a scope document 958 * 959 * <pre> 960 * { "$code" : "<i>code</i>", "$scope" : <i>scope document</i> } 961 * </pre> 962 * 963 * where "<i>code</i>" is the {@link Code}'s {@link Code#getCode() JavaScript code} and <i>scopeDocument</i> is the nested 964 * document representing the {@link CodeWithScope#getScope() scope} in which the JavaScript code should be evaluated. 965 * <p> 966 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 967 * be converted to {@link Code} or {@link CodeWithScope} value. 968 * </p> 969 * 970 * @param index The index in the array at which the value is to be set 971 * @param code the code 972 * @param scope the scope in which the JavaScript code should be evaulated, or null if there is no scope 973 * @return the {@link EditableDocument} for the scope; or this array if the scope is null 974 * @see #setCode(int, String, boolean) 975 */ 976 EditableDocument setCode( int index, 977 String code, 978 Document scope ); 979 980 /** 981 * Insert the value for the field at the given index to the supplied boolean value. 982 * 983 * @param index The index in the array at which the value is to be set 984 * @param value the new value for the field 985 * @return This document, to allow for chaining methods 986 */ 987 EditableArray addBoolean( int index, 988 boolean value ); 989 990 /** 991 * Insert the value for the field at the given index to the supplied integer value. 992 * 993 * @param index The index in the array at which the value is to be set 994 * @param value the new value for the field 995 * @return This document, to allow for chaining methods 996 */ 997 EditableArray addNumber( int index, 998 int value ); 999 1000 /** 1001 * Insert the value for the field at the given index to the supplied long value. 1002 * 1003 * @param index The index in the array at which the value is to be set 1004 * @param value the new value for the field 1005 * @return This document, to allow for chaining methods 1006 */ 1007 EditableArray addNumber( int index, 1008 long value ); 1009 1010 /** 1011 * Insert the value for the field at the given index to the supplied float value. 1012 * 1013 * @param index The index in the array at which the value is to be set 1014 * @param value the new value for the field 1015 * @return This document, to allow for chaining methods 1016 */ 1017 EditableArray addNumber( int index, 1018 float value ); 1019 1020 /** 1021 * Insert the value for the field at the given index to the supplied double value. 1022 * 1023 * @param index The index in the array at which the value is to be set 1024 * @param value the new value for the field 1025 * @return This document, to allow for chaining methods 1026 */ 1027 EditableArray addNumber( int index, 1028 double value ); 1029 1030 /** 1031 * Insert the value for the field at the given index to the supplied string value. 1032 * 1033 * @param index The index in the array at which the value is to be set 1034 * @param value the new value for the field 1035 * @return This document, to allow for chaining methods 1036 */ 1037 EditableArray addString( int index, 1038 String value ); 1039 1040 /** 1041 * Insert the value for the field at the given index to a {@link Symbol} created from the supplied string value. Symbols are 1042 * defined in the BSON specification as being similar to a string but which exists for those languages that have a specific 1043 * symbol type. Symbols are serialized to JSON as a normal string. 1044 * 1045 * @param index The index in the array at which the value is to be set 1046 * @param value the new value for the field 1047 * @return This document, to allow for chaining methods 1048 * @see #setString(int, String) 1049 */ 1050 EditableArray addSymbol( int index, 1051 String value ); 1052 1053 /** 1054 * Insert the value for the field at the given index to be a new, empty Document. 1055 * 1056 * @param index The index in the array at which the value is to be set 1057 * @return The editable document that was just created; never null 1058 */ 1059 EditableDocument addDocument( int index ); 1060 1061 /** 1062 * Insert the value for the field at the given index to be the supplied Document. 1063 * 1064 * @param index The index in the array at which the value is to be set 1065 * @param document the document 1066 * @return The editable document that was just set as the value at the supplied index in this array; never null and may or may 1067 * not be the same instance as the supplied <code>document</code>. 1068 */ 1069 EditableDocument addDocument( int index, 1070 Document document ); 1071 1072 /** 1073 * Insert the value for the field at the given index to be a new, empty array. 1074 * 1075 * @param index The index in the array at which the value is to be set 1076 * @return The editable array that was just created; never null 1077 */ 1078 EditableArray addArray( int index ); 1079 1080 /** 1081 * Insert the value for the field at the given index to be the supplied array. 1082 * 1083 * @param index The index in the array at which the value is to be set 1084 * @param array the array 1085 * @return The editable array that was just set as the value at the supplied index in this array; never null and may or may 1086 * not be the same instance as the supplied <code>array</code>. 1087 */ 1088 EditableArray addArray( int index, 1089 Array array ); 1090 1091 /** 1092 * Insert the value for the field at the given index to the supplied date value. 1093 * 1094 * @param index The index in the array at which the value is to be set 1095 * @param value the new value for the field 1096 * @return This document, to allow for chaining methods 1097 */ 1098 EditableArray addDate( int index, 1099 Date value ); 1100 1101 /** 1102 * Insert the value for the field at the given index to the date value parsed from the ISO-8601 date representation. 1103 * Specifically, the date string must match one of these patterns: 1104 * <ul> 1105 * <li>"<code><i>yyyy</i>-<i>MM</i>-<i>dd</i>T<i>HH</i>:<i>mm</i>:<i>ss</i></code>" where "<code>T</code>" is a literal 1106 * character</li> 1107 * <li>"<code><i>yyyy</i>-<i>MM</i>-<i>dd</i>T<i>HH</i>:<i>mm</i>:<i>ss</i>Z</code>" where "<code>T</code>" and " 1108 * <code>Z</code>" are literal characters</li> 1109 * <li>"<code><i>yyyy</i>-<i>MM</i>-<i>dd</i>T<i>HH</i>:<i>mm</i>:<i>ss</i>GMT+<i>00</i>:<i>00</i></code>" where " 1110 * <code>T</code>", and "<code>GMT</code>" are literal characters</li> 1111 * </ul> 1112 * 1113 * @param index The index in the array at which the value is to be set 1114 * @param isoDate the new value for the field 1115 * @return This document, to allow for chaining methods 1116 * @throws ParseException if the supplied value could not be parsed into a valid date 1117 */ 1118 EditableArray addDate( int index, 1119 String isoDate ) throws ParseException; 1120 1121 /** 1122 * Insert the value for the field at the given index to a {@link Timestamp} with the supplied time in seconds and increment. 1123 * Note that {@link Date} values are recommended for most purposes, as they are better suited to most applications' 1124 * representations of time instants. 1125 * 1126 * @param index The index in the array at which the value is to be set 1127 * @param timeInSeconds the time in seconds for the new Timestamp 1128 * @param increment the time increment for the new Timestamp 1129 * @return This document, to allow for chaining methods 1130 * @see #setDate(int, Date) 1131 */ 1132 EditableArray addTimestamp( int index, 1133 int timeInSeconds, 1134 int increment ); 1135 1136 /** 1137 * Insert the value for the field at the given index to an {@link ObjectId} created from the supplied hexadecimal binary 1138 * value. Object IDs are defined by the BSON specification as 12-byte binary values designed to have a reasonably high 1139 * probability of being unique when allocated. Since there is no explicit way to represent these in a JSON document, each 1140 * ObjectId value is serialized in a JSON document as a nested document of the form: 1141 * 1142 * <pre> 1143 * { "$oid" : "<i>12bytesOfIdInBase16</i>" } 1144 * </pre> 1145 * 1146 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 1147 * be converted to an ObjectId value. 1148 * <p> 1149 * For example, an ObjectId with time value of "1310745823", machine value of "1", process value of "2", and increment value 1150 * of "3" would be written as 1151 * 1152 * <pre> 1153 * { "$oid" : "4e2064df0000010002000003" } 1154 * </pre> 1155 * 1156 * </p> 1157 * 1158 * @param index The index in the array at which the value is to be set 1159 * @param hex the hexadecimal binary value for the ObjectId 1160 * @return This document, to allow for chaining methods 1161 * @see #setObjectId(int, byte[]) 1162 * @see #setObjectId(int, int, int, int, int) 1163 */ 1164 EditableArray addObjectId( int index, 1165 String hex ); 1166 1167 /** 1168 * Insert the value for the field at the given index to an {@link ObjectId} created from the supplied 12-byte binary value. 1169 * Object IDs are defined by the BSON specification as 12-byte binary values designed to have a reasonably high probability of 1170 * being unique when allocated. Since there is no explicit way to represent these in a JSON document, each ObjectId value is 1171 * serialized in a JSON document as a nested document of the form: 1172 * 1173 * <pre> 1174 * { "$oid" : "<i>12bytesOfIdInBase16</i>" } 1175 * </pre> 1176 * 1177 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 1178 * be converted to an ObjectId value. 1179 * <p> 1180 * For example, an ObjectId with time value of "1310745823", machine value of "1", process value of "2", and increment value 1181 * of "3" would be written as 1182 * 1183 * <pre> 1184 * { "$oid" : "4e2064df0000010002000003" } 1185 * </pre> 1186 * 1187 * </p> 1188 * 1189 * @param index The index in the array at which the value is to be set 1190 * @param bytes the 12-byte value for the ObjectId 1191 * @return This document, to allow for chaining methods 1192 * @see #setObjectId(int, String) 1193 * @see #setObjectId(int, int, int, int, int) 1194 */ 1195 EditableArray addObjectId( int index, 1196 byte[] bytes ); 1197 1198 /** 1199 * Insert the value for the field at the given index to an {@link ObjectId} created from the supplied hexadecimal binary 1200 * value. Object IDs are defined by the BSON specification as 12-byte binary values designed to have a reasonably high 1201 * probability of being unique when allocated. Since there is no explicit way to represent these in a JSON document, each 1202 * ObjectId value is serialized in a JSON document as a nested document of the form: 1203 * 1204 * <pre> 1205 * { "$oid" : "<i>12bytesOfIdInBase16</i>" } 1206 * </pre> 1207 * 1208 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 1209 * be converted to an ObjectId value. 1210 * <p> 1211 * For example, an ObjectId with time value of "1310745823", machine value of "1", process value of "2", and increment value 1212 * of "3" would be written as 1213 * 1214 * <pre> 1215 * { "$oid" : "4e2064df0000010002000003" } 1216 * </pre> 1217 * 1218 * </p> 1219 * 1220 * @param index The index in the array at which the value is to be set 1221 * @param time the Unix-style timestamp, which is a signed integer representing the number of seconds before or after January 1222 * 1st 1970 (UTC) 1223 * @param machine the first three bytes of the (md5) hash of the machine host name, or of the mac/network address, or the 1224 * virtual machine id 1225 * @param process the 2 bytes of the process id (or thread id) of the process generating the object id 1226 * @param inc an ever incrementing value, or a random number if a counter can't be used in the language/runtime 1227 * @return This document, to allow for chaining methods 1228 * @see #setObjectId(int, String) 1229 * @see #setObjectId(int, byte[]) 1230 */ 1231 EditableArray addObjectId( int index, 1232 int time, 1233 int machine, 1234 int process, 1235 int inc ); 1236 1237 /** 1238 * Insert the value for the field at the given index to the supplied regular expression. Regular expression values are 1239 * represented in memory using {@link Pattern} instances, and are stored natively in BSON as regular expressions. However, 1240 * when serialized to JSON, regular expressions are written as nested documents of the form: 1241 * 1242 * <pre> 1243 * { "$regex" : "<i>pattern</i>" } 1244 * </pre> 1245 * 1246 * where "<i>pattern</i>" is the regular expression pattern. 1247 * <p> 1248 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 1249 * be converted to a regular expression value. 1250 * </p> 1251 * 1252 * @param index The index in the array at which the value is to be set 1253 * @param pattern the regular expression pattern string 1254 * @return This document, to allow for chaining methods 1255 * @see #setRegularExpression(int, String, int) 1256 */ 1257 EditableArray addRegularExpression( int index, 1258 String pattern ); 1259 1260 /** 1261 * Insert the value for the field at the given index to the supplied regular expression. Regular expression values are 1262 * represented in memory using {@link Pattern} instances, and are stored natively in BSON as regular expressions. However, 1263 * when serialized to JSON, regular expressions are written as nested documents of the form: 1264 * 1265 * <pre> 1266 * { "$regex" : "<i>pattern</i>", "$options" : "<i>flags</i>" } 1267 * </pre> 1268 * 1269 * where "<i>pattern</i>" is the regular expression pattern, and "<i>flags</i>" is a string representation of the regular 1270 * expression options. 1271 * <p> 1272 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 1273 * be converted to a regular expression value. 1274 * </p> 1275 * 1276 * @param index The index in the array at which the value is to be set 1277 * @param pattern the regular expression pattern string 1278 * @param flags the bitwise-anded {@link Pattern} options: {@link Pattern#CANON_EQ}, {@link Pattern#CASE_INSENSITIVE}, 1279 * {@link Pattern#CASE_INSENSITIVE}, {@link Pattern#COMMENTS}, {@link Pattern#DOTALL}, {@link Pattern#LITERAL}, 1280 * {@link Pattern#MULTILINE}, {@link Pattern#UNICODE_CASE}, and {@link Pattern#UNIX_LINES} 1281 * @return This document, to allow for chaining methods 1282 * @see #setRegularExpression(int, String) 1283 */ 1284 EditableArray addRegularExpression( int index, 1285 String pattern, 1286 int flags ); 1287 1288 /** 1289 * Insert the value for the field at the given index to be a null value. Both JSON and BSON formats support null values, and 1290 * {@link Null} is used for the value in the in-memory representation. The {@link #isNull(String)} methods can be used to 1291 * determine if a field has been set to null, or {@link #isNullOrMissing(String)} if the field has not be set or if it has 1292 * been set to null. 1293 * 1294 * @param index The index in the array at which the value is to be set 1295 * @return This document, to allow for chaining methods 1296 * @see #isNull(String) 1297 * @see #isNullOrMissing(String) 1298 */ 1299 EditableArray addNull( int index ); 1300 1301 /** 1302 * Insert the value for the field at the given index to be a binary value. JSON does not formally support binary values, and 1303 * so such values will be encoded using a nested document of the form: 1304 * 1305 * <pre> 1306 * { "$type" : <i>typeAsInt</i>, "$base64" : "<i>bytesInBase64</i>" } 1307 * </pre> 1308 * 1309 * where "<i>typeAsInt</i>" is the integer representation of the {@link Bson.BinaryType BSON type}, and "<i>bytesInBase64</i>" is 1310 * the Base64 encoding of the actual Binary {@link Binary#getBytes() bytes}. 1311 * <p> 1312 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 1313 * be converted to Binary value. 1314 * </p> 1315 * 1316 * @param index The index in the array at which the value is to be set 1317 * @param type one of the {@link Bson.BinaryType BSON type} constants denoting the type of the {@link Binary} value 1318 * @param data the bytes for the {@link Binary} value 1319 * @return This document, to allow for chaining methods 1320 */ 1321 EditableArray addBinary( int index, 1322 byte type, 1323 byte[] data ); 1324 1325 /** 1326 * Insert the value for the field at the given index to be a {@link UUID}. JSON does not formally support binary values, and 1327 * so such values will be encoded using a nested document of the form: 1328 * 1329 * <pre> 1330 * { "$uuid" : "<i>string-form-of-uuid</i>" } 1331 * </pre> 1332 * 1333 * where "<i>string-form-of-uuid</i>" is the UUID's {@link UUID#toString() string representation} 1334 * <p> 1335 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 1336 * be converted to UUID value. 1337 * </p> 1338 * 1339 * @param index The index in the array at which the value is to be set 1340 * @param uuid the UUID value 1341 * @return This document, to allow for chaining methods 1342 */ 1343 EditableArray addUuid( int index, 1344 UUID uuid ); 1345 1346 /** 1347 * Insert the value for the field at the given index to be a {@link Code} or {@link CodeWithScope}. JSON does not formally 1348 * support such values, and so when written to JSON they will be encoded using a nested document of the form: 1349 * 1350 * <pre> 1351 * { "$code" : "<i>code</i>" } 1352 * </pre> 1353 * 1354 * or, if there is a scope document 1355 * 1356 * <pre> 1357 * { "$code" : "<i>code</i>", "$scope" : <i>scope document</i> } 1358 * </pre> 1359 * 1360 * where "<i>code</i>" is the {@link Code}'s {@link Code#getCode() JavaScript code} and <i>scopeDocument</i> is the nested 1361 * document representing the {@link CodeWithScope#getScope() scope} in which the JavaScript code should be evaluated. 1362 * <p> 1363 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 1364 * be converted to {@link Code} or {@link CodeWithScope} value. 1365 * </p> 1366 * <p> 1367 * Note that when <code>includeScope</code> is <code>true</code>, the returned {@link EditableArray} can be used to populate 1368 * the scope document. 1369 * 1370 * @param index The index in the array at which the value is to be set 1371 * @param code the code 1372 * @param includeScope true if the code should include a scope (and if this method should return an {@link EditableArray} for 1373 * this scope document), or false otherwise 1374 * @return if <code>includeScope</code> is <code>true</code>, then the {@link EditableDocument} for the scope; otherwise, this 1375 * array to allow for chaining methods 1376 * @see #setCode(int, String, Document) 1377 */ 1378 EditableDocument addCode( int index, 1379 String code, 1380 boolean includeScope ); 1381 1382 /** 1383 * Insert the value for the field at the given index to be a {@link Code} or {@link CodeWithScope}. JSON does not formally 1384 * support such values, and so when written to JSON they will be encoded using a nested document of the form: 1385 * 1386 * <pre> 1387 * { "$code" : "<i>code</i>" } 1388 * </pre> 1389 * 1390 * or, if there is a scope document 1391 * 1392 * <pre> 1393 * { "$code" : "<i>code</i>", "$scope" : <i>scope document</i> } 1394 * </pre> 1395 * 1396 * where "<i>code</i>" is the {@link Code}'s {@link Code#getCode() JavaScript code} and <i>scopeDocument</i> is the nested 1397 * document representing the {@link CodeWithScope#getScope() scope} in which the JavaScript code should be evaluated. 1398 * <p> 1399 * When nested documents of this form are read by this library's {@link Json JSON reader}, nested documents of this form will 1400 * be converted to {@link Code} or {@link CodeWithScope} value. 1401 * </p> 1402 * 1403 * @param index The index in the array at which the value is to be set 1404 * @param code the code 1405 * @param scope the scope in which the JavaScript code should be evaulated, or null if there is no scope 1406 * @return the {@link EditableDocument} for the scope; or this array if the scope is null 1407 * @see #setCode(int, String, boolean) 1408 */ 1409 EditableDocument addCode( int index, 1410 String code, 1411 Document scope ); 1412 1413 /** 1414 * Adds the supplied boolean value to this array. 1415 * 1416 * @param value the new value for the field 1417 * @return This document, to allow for chaining methods 1418 */ 1419 EditableArray addBoolean( boolean value ); 1420 1421 /** 1422 * Adds the supplied integer value to this array. 1423 * 1424 * @param value the new value for the field 1425 * @return This document, to allow for chaining methods 1426 */ 1427 EditableArray addNumber( int value ); 1428 1429 /** 1430 * Adds the supplied long value to this array. 1431 * 1432 * @param value the new value for the field 1433 * @return This document, to allow for chaining methods 1434 */ 1435 EditableArray addNumber( long value ); 1436 1437 /** 1438 * Adds the supplied float value to this array. 1439 * 1440 * @param value the new value for the field 1441 * @return This document, to allow for chaining methods 1442 */ 1443 EditableArray addNumber( float value ); 1444 1445 /** 1446 * Adds the supplied double value to this array. 1447 * 1448 * @param value the new value for the field 1449 * @return This document, to allow for chaining methods 1450 */ 1451 EditableArray addNumber( double value ); 1452 1453 /** 1454 * Adds the supplied string value to this array. 1455 * 1456 * @param value the new value for the field 1457 * @return This document, to allow for chaining methods 1458 */ 1459 EditableArray addString( String value ); 1460 1461 /** 1462 * Adds to this array a Symbol with the supplied string. 1463 * 1464 * @param value the new value for the field 1465 * @return This document, to allow for chaining methods 1466 * @see #addString(String) 1467 */ 1468 EditableArray addSymbol( String value ); 1469 1470 /** 1471 * Adds to this array a new empty document. 1472 * 1473 * @return The editable document that was just created; never null 1474 */ 1475 EditableDocument addDocument(); 1476 1477 /** 1478 * Adds to this array the supplied document. 1479 * 1480 * @param document the document 1481 * @return The editable document that was just added to this array; never null and may or may not be the same instance as the 1482 * supplied <code>document</code>. 1483 */ 1484 EditableDocument addDocument( Document document ); 1485 1486 /** 1487 * Adds to this array a new empty array. 1488 * 1489 * @return The editable array that was just created; never null 1490 */ 1491 EditableArray addArray(); 1492 1493 /** 1494 * Adds to this array the supplied array. 1495 * 1496 * @param array the array 1497 * @return The editable array that was just added to this array; never null and may or may not be the same instance as the 1498 * supplied <code>array</code>. 1499 */ 1500 EditableArray addArray( Array array ); 1501 1502 /** 1503 * Adds to this array the supplied date. 1504 * 1505 * @param value the new value for the field 1506 * @return This document, to allow for chaining methods 1507 */ 1508 EditableArray addDate( Date value ); 1509 1510 /** 1511 * Adds to this array a Date with the supplied ISO-8601 string. 1512 * 1513 * @param isoDate the new value for the field 1514 * @return This document, to allow for chaining methods 1515 * @see #addDate(Date) 1516 * @throws ParseException if the supplied value could not be parsed into a valid date 1517 */ 1518 EditableArray addDate( String isoDate ) throws ParseException; 1519 1520 /** 1521 * Adds to this array a Timestamp with the supplied time in seconds and increment value. 1522 * 1523 * @param timeInSeconds the time in seconds for the new Timestamp 1524 * @param increment the time increment for the new Timestamp 1525 * @return This document, to allow for chaining methods 1526 * @see #addDate(Date) 1527 */ 1528 EditableArray addTimestamp( int timeInSeconds, 1529 int increment ); 1530 1531 /** 1532 * Adds to this array an ObjectId with the supplied hexadecimal string. 1533 * 1534 * @param hex the hexadecimal binary value for the ObjectId 1535 * @return This document, to allow for chaining methods 1536 * @see #addObjectId(byte[]) 1537 * @see #addObjectId(int, int, int, int) 1538 */ 1539 EditableArray addObjectId( String hex ); 1540 1541 /** 1542 * Adds to this array an ObjectId with the supplied 12-byte value. 1543 * 1544 * @param bytes the 12-byte value for the ObjectId 1545 * @return This document, to allow for chaining methods 1546 * @see #addObjectId(String) 1547 * @see #addObjectId(int, int, int, int) 1548 */ 1549 EditableArray addObjectId( byte[] bytes ); 1550 1551 /** 1552 * Adds to this array an ObjectId with the supplied time, machine, process, and increment. 1553 * 1554 * @param time the Unix-style timestamp, which is a signed integer representing the number of seconds before or after January 1555 * 1st 1970 (UTC) 1556 * @param machine the first three bytes of the (md5) hash of the machine host name, or of the mac/network address, or the 1557 * virtual machine id 1558 * @param process the 2 bytes of the process id (or thread id) of the process generating the object id 1559 * @param inc an ever incrementing value, or a random number if a counter can't be used in the language/runtime 1560 * @return This document, to allow for chaining methods 1561 * @see #addObjectId(String) 1562 * @see #addObjectId(byte[]) 1563 */ 1564 EditableArray addObjectId( int time, 1565 int machine, 1566 int process, 1567 int inc ); 1568 1569 /** 1570 * Adds to this array a regular expression with the supplied pattern string. 1571 * 1572 * @param pattern the regular expression pattern string 1573 * @return This document, to allow for chaining methods 1574 */ 1575 EditableArray addRegularExpression( String pattern ); 1576 1577 /** 1578 * Adds to this array a regular expression with the supplied pattern string and option flags. 1579 * 1580 * @param pattern the regular expression pattern string 1581 * @param flags the bitwise-anded {@link Pattern} options: {@link Pattern#CANON_EQ}, {@link Pattern#CASE_INSENSITIVE}, 1582 * {@link Pattern#CASE_INSENSITIVE}, {@link Pattern#COMMENTS}, {@link Pattern#DOTALL}, {@link Pattern#LITERAL}, 1583 * {@link Pattern#MULTILINE}, {@link Pattern#UNICODE_CASE}, and {@link Pattern#UNIX_LINES} 1584 * @return This document, to allow for chaining methods 1585 */ 1586 EditableArray addRegularExpression( String pattern, 1587 int flags ); 1588 1589 /** 1590 * Adds to this array a {@link Null} value. 1591 * 1592 * @return This document, to allow for chaining methods 1593 * @see #isNull(String) 1594 * @see #isNullOrMissing(String) 1595 */ 1596 EditableArray addNull(); 1597 1598 /** 1599 * Adds to this array a {@link Binary} value with the supplied type and content. 1600 * 1601 * @param type one of the {@link Bson.BinaryType BSON type} constants denoting the type of the {@link Binary} value 1602 * @param data the bytes for the {@link Binary} value 1603 * @return This document, to allow for chaining methods 1604 */ 1605 EditableArray addBinary( byte type, 1606 byte[] data ); 1607 1608 /** 1609 * Adds to this array the supplied UUID. 1610 * 1611 * @param uuid the UUID value 1612 * @return This document, to allow for chaining methods 1613 */ 1614 EditableArray addUuid( UUID uuid ); 1615 1616 /** 1617 * Adds to this array a {@link Code} with the supplied JavaScript code. 1618 * 1619 * @param code the code 1620 * @param includeScope true if the code should include a scope (and if this method should return an {@link EditableArray} for 1621 * this scope document), or false otherwise 1622 * @return if <code>includeScope</code> is <code>true</code>, then the {@link EditableArray} for the scope; otherwise, this 1623 * document to allow for chaining methods 1624 * @see #addCode(String, Document) 1625 */ 1626 EditableDocument addCode( String code, 1627 boolean includeScope ); 1628 1629 /** 1630 * Adds to this array a {@link CodeWithScope} with the supplied JavaScript code and scope. 1631 * 1632 * @param code the code 1633 * @param scope the scope in which the JavaScript code should be evaulated, or null if there is no scope 1634 * @return the {@link EditableDocument} for the scope, or null if the <code>scope</code> reference is null 1635 * @see #addCode(String, boolean) 1636 */ 1637 EditableDocument addCode( String code, 1638 Document scope ); 1639 1640 /** 1641 * Adds the supplied boolean value to this array, if and only if an equivalent value doesn't already exist in the array. 1642 * 1643 * @param value the new value for the field 1644 * @return This document, to allow for chaining methods 1645 */ 1646 EditableArray addBooleanIfAbsent( boolean value ); 1647 1648 /** 1649 * Adds the supplied integer value to this array, if and only if an equivalent value doesn't already exist in the array. 1650 * 1651 * @param value the new value for the field 1652 * @return This document, to allow for chaining methods 1653 */ 1654 EditableArray addNumberIfAbsent( int value ); 1655 1656 /** 1657 * Adds the supplied long value to this array, if and only if an equivalent value doesn't already exist in the array. 1658 * 1659 * @param value the new value for the field 1660 * @return This document, to allow for chaining methods 1661 */ 1662 EditableArray addNumberIfAbsent( long value ); 1663 1664 /** 1665 * Adds the supplied float value to this array, if and only if an equivalent value doesn't already exist in the array. 1666 * 1667 * @param value the new value for the field 1668 * @return This document, to allow for chaining methods 1669 */ 1670 EditableArray addNumberIfAbsent( float value ); 1671 1672 /** 1673 * Adds the supplied double value to this array, if and only if an equivalent value doesn't already exist in the array. 1674 * 1675 * @param value the new value for the field 1676 * @return This document, to allow for chaining methods 1677 */ 1678 EditableArray addNumberIfAbsent( double value ); 1679 1680 /** 1681 * Adds the supplied string value to this array, if and only if an equivalent value doesn't already exist in the array. 1682 * 1683 * @param value the new value for the field 1684 * @return This document, to allow for chaining methods 1685 */ 1686 EditableArray addStringIfAbsent( String value ); 1687 1688 /** 1689 * Adds to this array a Symbol with the supplied string, if and only if an equivalent value doesn't already exist in the 1690 * array. 1691 * 1692 * @param value the new value for the field 1693 * @return This document, to allow for chaining methods 1694 * @see #addString(String) 1695 */ 1696 EditableArray addSymbolIfAbsent( String value ); 1697 1698 /** 1699 * Adds to this array the supplied document, if and only if an equivalent value doesn't already exist in the array. 1700 * 1701 * @param document the document 1702 * @return The editable document that was just added to this array; never null and may or may not be the same instance as the 1703 * supplied <code>document</code>. 1704 */ 1705 EditableDocument addDocumentIfAbsent( Document document ); 1706 1707 /** 1708 * Adds to this array the supplied array, if and only if an equivalent value doesn't already exist in the array. 1709 * 1710 * @param array the array 1711 * @return The editable array that was just added to this array; never null and may or may not be the same instance as the 1712 * supplied <code>array</code>. 1713 */ 1714 EditableArray addArrayIfAbsent( Array array ); 1715 1716 /** 1717 * Adds to this array the supplied date, if and only if an equivalent value doesn't already exist in the array. 1718 * 1719 * @param value the new value for the field 1720 * @return This document, to allow for chaining methods 1721 */ 1722 EditableArray addDateIfAbsent( Date value ); 1723 1724 /** 1725 * Adds to this array a Date with the supplied ISO-8601 string, if and only if an equivalent value doesn't already exist in 1726 * the array. 1727 * 1728 * @param isoDate the new value for the field 1729 * @return This document, to allow for chaining methods 1730 * @see #addDate(Date) 1731 * @throws ParseException if the supplied value could not be parsed into a valid date 1732 */ 1733 EditableArray addDateIfAbsent( String isoDate ) throws ParseException; 1734 1735 /** 1736 * Adds to this array a Timestamp with the supplied time in seconds and increment value, if and only if an equivalent value 1737 * doesn't already exist in the array. 1738 * 1739 * @param timeInSeconds the time in seconds for the new Timestamp 1740 * @param increment the time increment for the new Timestamp 1741 * @return This document, to allow for chaining methods 1742 * @see #addDate(Date) 1743 */ 1744 EditableArray addTimestampIfAbsent( int timeInSeconds, 1745 int increment ); 1746 1747 /** 1748 * Adds to this array an ObjectId with the supplied hexadecimal string, if and only if an equivalent value doesn't already 1749 * exist in the array. 1750 * 1751 * @param hex the hexadecimal binary value for the ObjectId 1752 * @return This document, to allow for chaining methods 1753 * @see #addObjectId(byte[]) 1754 * @see #addObjectId(int, int, int, int) 1755 */ 1756 EditableArray addObjectIdIfAbsent( String hex ); 1757 1758 /** 1759 * Adds to this array an ObjectId with the supplied 12-byte value, if and only if an equivalent value doesn't already exist in 1760 * the array. 1761 * 1762 * @param bytes the 12-byte value for the ObjectId 1763 * @return This document, to allow for chaining methods 1764 * @see #addObjectId(String) 1765 * @see #addObjectId(int, int, int, int) 1766 */ 1767 EditableArray addObjectIdIfAbsent( byte[] bytes ); 1768 1769 /** 1770 * Adds to this array an ObjectId with the supplied time, machine, process, and increment, if and only if an equivalent value 1771 * doesn't already exist in the array. 1772 * 1773 * @param time the Unix-style timestamp, which is a signed integer representing the number of seconds before or after January 1774 * 1st 1970 (UTC) 1775 * @param machine the first three bytes of the (md5) hash of the machine host name, or of the mac/network address, or the 1776 * virtual machine id 1777 * @param process the 2 bytes of the process id (or thread id) of the process generating the object id 1778 * @param inc an ever incrementing value, or a random number if a counter can't be used in the language/runtime 1779 * @return This document, to allow for chaining methods 1780 * @see #addObjectId(String) 1781 * @see #addObjectId(byte[]) 1782 */ 1783 EditableArray addObjectIdIfAbsent( int time, 1784 int machine, 1785 int process, 1786 int inc ); 1787 1788 /** 1789 * Adds to this array a regular expression with the supplied pattern string, if and only if an equivalent value doesn't 1790 * already exist in the array. 1791 * 1792 * @param pattern the regular expression pattern string 1793 * @return This document, to allow for chaining methods 1794 */ 1795 EditableArray addRegularExpressionIfAbsent( String pattern ); 1796 1797 /** 1798 * Adds to this array a regular expression with the supplied pattern string and option flags, if and only if an equivalent 1799 * value doesn't already exist in the array. 1800 * 1801 * @param pattern the regular expression pattern string 1802 * @param flags the bitwise-anded {@link Pattern} options: {@link Pattern#CANON_EQ}, {@link Pattern#CASE_INSENSITIVE}, 1803 * {@link Pattern#CASE_INSENSITIVE}, {@link Pattern#COMMENTS}, {@link Pattern#DOTALL}, {@link Pattern#LITERAL}, 1804 * {@link Pattern#MULTILINE}, {@link Pattern#UNICODE_CASE}, and {@link Pattern#UNIX_LINES} 1805 * @return This document, to allow for chaining methods 1806 */ 1807 EditableArray addRegularExpressionIfAbsent( String pattern, 1808 int flags ); 1809 1810 /** 1811 * Adds to this array a {@link Null} value, if and only if there is not already a null value in the array. 1812 * 1813 * @return This document, to allow for chaining methods 1814 * @see #isNull(String) 1815 * @see #isNullOrMissing(String) 1816 */ 1817 EditableArray addNullIfAbsent(); 1818 1819 /** 1820 * Adds to this array a {@link Binary} value with the supplied type and content, if and only if an equivalent value doesn't 1821 * already exist in the array. 1822 * 1823 * @param type one of the {@link Bson.BinaryType BSON type} constants denoting the type of the {@link Binary} value 1824 * @param data the bytes for the {@link Binary} value 1825 * @return This document, to allow for chaining methods 1826 */ 1827 EditableArray addBinaryIfAbsent( byte type, 1828 byte[] data ); 1829 1830 /** 1831 * Adds to this array the supplied UUID, if and only if an equivalent value doesn't already exist in the array. 1832 * 1833 * @param uuid the UUID value 1834 * @return This document, to allow for chaining methods 1835 */ 1836 EditableArray addUuidIfAbsent( UUID uuid ); 1837 1838 /** 1839 * Adds to this array a {@link CodeWithScope} with the supplied JavaScript code and scope, if and only if an equivalent value 1840 * doesn't already exist in the array. 1841 * 1842 * @param code the code 1843 * @param scope the scope in which the JavaScript code should be evaulated, or null if there is no scope 1844 * @return the {@link EditableDocument} for the scope, or null if the <code>scope</code> reference is null 1845 * @see #addCode(String, boolean) 1846 */ 1847 EditableDocument addCodeIfAbsent( String code, 1848 Document scope ); 1849 1850 @Override 1851 EditableArray clone(); 1852}