Class FieldValue

java.lang.Object
com.google.cloud.firestore.FieldValue

public abstract class FieldValue extends Object
Sentinel values that can be used when writing document fields with set() or update().
  • Method Summary

    Modifier and Type
    Method
    Description
    static FieldValue
    arrayRemove(Object... elements)
    Returns a special value that can be used with set(), create() or update() that tells the server to remove the given elements from any array value that already exists on the server.
    static FieldValue
    arrayUnion(Object... elements)
    Returns a special value that can be used with set(), create() or update() that tells the server to union the given elements with any array value that already exists on the server.
    static FieldValue
    Returns a sentinel used with update() to mark a field for deletion.
    boolean
    Returns true if this FieldValue is equal to the provided object.
    int
     
    static FieldValue
    increment(double d)
    Returns a special value that can be used with set(), create() or update() that tells the server to increment the field's current value by the given value.
    static FieldValue
    increment(long l)
    Returns a special value that can be used with set(), create() or update() that tells the server to increment the field's current value by the given value.
    static FieldValue
    Returns a sentinel used with set() or update() to include a server-generated timestamp in the written data.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • serverTimestamp

      @Nonnull public static FieldValue serverTimestamp()
      Returns a sentinel used with set() or update() to include a server-generated timestamp in the written data.
    • delete

      @Nonnull public static FieldValue delete()
      Returns a sentinel used with update() to mark a field for deletion.
    • increment

      @Nonnull public static FieldValue increment(long l)
      Returns a special value that can be used with set(), create() or update() that tells the server to increment the field's current value by the given value.

      If the current field value is an integer, possible integer overflows are resolved to Long.MAX_VALUE or Long.MIN_VALUE. If the current field value is a double, both values will be interpreted as doubles and the arithmetic will follow IEEE 754 semantics.

      If the current field is not an integer or double, or if the field does not yet exist, the transformation will set the field to the given value.

      Returns:
      The FieldValue sentinel for use in a call to set(), create() or update().
    • increment

      @Nonnull public static FieldValue increment(double d)
      Returns a special value that can be used with set(), create() or update() that tells the server to increment the field's current value by the given value.

      If the current value is an integer or a double, both the current and the given value will be interpreted as doubles and all arithmetic will follow IEEE 754 semantics. Otherwise, the transformation will set the field to the given value.

      Returns:
      The FieldValue sentinel for use in a call to set(), create() or update().
    • arrayUnion

      @Nonnull public static FieldValue arrayUnion(@Nonnull Object... elements)
      Returns a special value that can be used with set(), create() or update() that tells the server to union the given elements with any array value that already exists on the server. Each specified element that doesn't already exist in the array will be added to the end. If the field being modified is not already an array it will be overwritten with an array containing exactly the specified elements.
      Parameters:
      elements - The elements to union into the array.
      Returns:
      The FieldValue sentinel for use in a call to set() or update().
    • arrayRemove

      @Nonnull public static FieldValue arrayRemove(@Nonnull Object... elements)
      Returns a special value that can be used with set(), create() or update() that tells the server to remove the given elements from any array value that already exists on the server. All instances of each element specified will be removed from the array. If the field being modified is not already an array it will be overwritten with an empty array.
      Parameters:
      elements - The elements to remove from the array.
      Returns:
      The FieldValue sentinel for use in a call to set() or update().
    • equals

      public boolean equals(Object obj)
      Returns true if this FieldValue is equal to the provided object.
      Overrides:
      equals in class Object
      Parameters:
      obj - The object to compare against.
      Returns:
      Whether this FieldValue is equal to the provided object.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object