static Array create(Value firstValue, Value secondValue, Value... additionalValues) { Value[] values = new Value[additionalValues.length + 2]; values[0] = Value.create(firstValue); values[1] = Value.create(secondValue); for (int i = 0; i != additionalValues.length; ++i) { values[i + 2] = Value.create(additionalValues[i]); } return new BasicArray(values); }
/** * Set the value for the field with the given name to the supplied long value. * * @param name The name of the field * @param value the new value for the field * @return This document, to allow for chaining methods */ default Document setNumber(CharSequence name, long value) { setValue(name, Value.create(value)); return this; }
/** * Set the value for the field with the given name to the supplied double value. * * @param name The name of the field * @param value the new value for the field * @return This document, to allow for chaining methods */ default Document setNumber(CharSequence name, double value) { setValue(name, Value.create(value)); return this; }
/** * Adds the double value to the end of this array. * * @param value the double value; may not be null * @return this array to allow for chaining methods */ default Array add(double value) { add(Value.create(value)); return this; }
/** * Set the value for the field with the given name to the supplied float value. * * @param index the index of the field; must be greater than or equal to 0 or less than or equal to {@link #size() size} * @param value the new value for the field * @return this array to allow for chaining methods */ default Array setNumber(int index, float value) { return setValue(index, Value.create(value)); }
/** * Set the value for the field with the given name to the supplied big integer value. * * @param index the index of the field; must be greater than or equal to 0 or less than or equal to {@link #size() size} * @param value the new value for the field * @return this array to allow for chaining methods */ default Array setNumber(int index, BigInteger value) { return setValue(index, Value.create(value)); }
/** * If the current size of the array is smaller than the given size, expand it and use the supplied value for all new entries. * This method does nothing if the current size is larger than the supplied {@code desiredSize}. * * @param desiredSize the desired size of the array; may be negative * @param value the new value for any new entries * @return this array to allow for chaining methods */ default Array expand(int desiredSize, int value) { return expand(desiredSize,Value.create(value)); }
/** * Increment the numeric value at the given location by the designated amount. * @param index the index of the field; must be greater than or equal to 0 and less than or equal to {@link #size() size} * @param increment the amount to increment the existing value; may be negative to decrement * @return this array to allow for chaining methods * @throws IllegalArgumentException if the current value is not a number */ default Array increment( int index, double increment ) { return increment(index,Value.create(increment)); }
/** * Increment the numeric value in the given field by the designated amount. * * @param name The name of the field * @param increment the amount to increment the existing value; may be negative to decrement * @return this array to allow for chaining methods * @throws IllegalArgumentException if the current value is not a number */ default Document increment(CharSequence name, float increment) { return increment(name, Value.create(increment)); }
/** * Gets the value in this document for the given field name. * * @param index the index * @param defaultValue the default value to return if there is no such entry * @return The value if found or <code>defaultValue</code> if there is no such entry */ default Value get(int index, Object defaultValue) { Value value = get(index); return value != null ? value : Value.create(defaultValue); }
/** * Adds the integer value to the end of this array. * * @param value the integer value; may not be null * @return this array to allow for chaining methods */ default Array add(int value) { add(Value.create(value)); return this; }
/** * Adds the float value to the end of this array. * * @param value the float value; may not be null * @return this array to allow for chaining methods */ default Array add(float value) { add(Value.create(value)); return this; }
/** * Set the value for the field with the given name to the supplied double value. * * @param index the index of the field; must be greater than or equal to 0 or less than or equal to {@link #size() size} * @param value the new value for the field * @return this array to allow for chaining methods */ default Array setNumber(int index, double value) { return setValue(index, Value.create(value)); }
/** * Set the value for the field with the given name to the supplied big integer value. * * @param index the index of the field; must be greater than or equal to 0 or less than or equal to {@link #size() size} * @param value the new value for the field * @return this array to allow for chaining methods */ default Array setNumber(int index, BigDecimal value) { return setValue(index, Value.create(value)); }
/** * Set the value for the field with the given name to the supplied string value. * * @param index the index of the field; must be greater than or equal to 0 or less than or equal to {@link #size() size} * @param value the new value for the field * @return this array to allow for chaining methods */ default Array setString(int index, String value) { return setValue(index, Value.create(value)); }
/** * Increment the numeric value at the given location by the designated amount. * @param index the index of the field; must be greater than or equal to 0 and less than or equal to {@link #size() size} * @param increment the amount to increment the existing value; may be negative to decrement * @return this array to allow for chaining methods * @throws IllegalArgumentException if the current value is not a number */ default Array increment( int index, int increment ) { return increment(index,Value.create(increment)); }
/** * Increment the numeric value at the given location by the designated amount. * @param index the index of the field; must be greater than or equal to 0 and less than or equal to {@link #size() size} * @param increment the amount to increment the existing value; may be negative to decrement * @return this array to allow for chaining methods * @throws IllegalArgumentException if the current value is not a number */ default Array increment( int index, float increment ) { return increment(index,Value.create(increment)); }
static Array create(Object... values) { if (values == null || values.length == 0) { return create(); } Value[] vals = new Value[values.length]; for (int i = 0; i != values.length; ++i) { vals[i] = Value.create(values[i]); } return new BasicArray(vals); }
static Array create(Iterable<?> values) { if (values == null) return create(); BasicArray array = new BasicArray(); values.forEach(obj -> array.add(Value.create(obj))); return array; }
protected void assertPair( Iterator<Map.Entry<Path, Value>> iterator, String path, Object value ) { Map.Entry<Path,Value> entry = iterator.next(); assertThat((Object)entry.getKey()).isEqualTo(Path.parse(path)); assertThat(entry.getValue()).isEqualTo(Value.create(value)); }