Class Field<T>


  • public final class Field<T>
    extends Object
    A field extractor for a FaunaDB Value.

    The field extractor can be used to extract field's values from key/value maps or collections returned by FaunaDB.

    Example:

    
     Field<String> userNameField = Field.at("data", "name").to(String.class);
     Value result = client.query(getUser).get();
     String name = result.get(userNameField);
     
    See Also:
    Value
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> Field<T> as​(Codec<T> codec)
      Creates a field that converts its underlying value using the Codec provided.
      static <T> Field<T> as​(Class<T> clazz)
      Creates a field that converts its underyling value to the Class provided.
      static <A> Field<List<A>> asListOf​(Field<A> field)
      Assuming the Value instance is a collection, creates a field extractor that collects the Field provided for each element in the underlying collection.
      static <A> Field<Map<String,​A>> asMapOf​(Field<A> field)  
      static Field<Value> at​(int... indexes)
      Creates a field that extracts the underlying value from the indexes provided, assuming the Value instance is a collection or nested collections.
      <A> Field<A> at​(Field<A> other)
      Creates a field extractor composed with another nested Field instance.
      static Field<Value> at​(String... keys)
      Creates a field that extracts the underlying value from the path provided, assuming the Value instance is a key/value map.
      <A> Field<List<A>> collect​(Field<A> field)
      Assuming the Value instance is a collection, creates a field extractor that collects the Field provided for each element in the underlying collection.
      boolean equals​(Object other)  
      int hashCode()  
      <A> Field<A> to​(Codec<A> codec)
      Creates a field extractor that converts its value using the codec provided.
      <A> Field<A> to​(Class<A> type)
      Creates a field extractor that converts its value to the class provided.
      String toString()  
    • Method Detail

      • at

        public static Field<Value> at​(String... keys)
        Creates a field that extracts the underlying value from the path provided, assuming the Value instance is a key/value map.
        Parameters:
        keys - the path to the desired field
        Returns:
        a new Field instance
        See Also:
        Field, Value
      • at

        public static Field<Value> at​(int... indexes)
        Creates a field that extracts the underlying value from the indexes provided, assuming the Value instance is a collection or nested collections.
        Parameters:
        indexes - the path to the desired field
        Returns:
        a new Field instance
      • as

        public static <T> Field<T> as​(Codec<T> codec)
        Creates a field that converts its underlying value using the Codec provided.
        Type Parameters:
        T - the desired final type
        Parameters:
        codec - Codec used to convert the field's value
        Returns:
        a new Field instance
      • as

        public static <T> Field<T> as​(Class<T> clazz)
        Creates a field that converts its underyling value to the Class provided.
        Type Parameters:
        T - the desired final type
        Parameters:
        clazz - the desired class type
        Returns:
        a new Field instance
      • asListOf

        public static <A> Field<List<A>> asListOf​(Field<A> field)
        Assuming the Value instance is a collection, creates a field extractor that collects the Field provided for each element in the underlying collection.
        Type Parameters:
        A - the desired final type for each collection element
        Parameters:
        field - the Field to be extracted from each collection element
        Returns:
        a new Field instance
      • at

        public <A> Field<A> at​(Field<A> other)
        Creates a field extractor composed with another nested Field instance.
        Type Parameters:
        A - the desired final type
        Parameters:
        other - a nested Field to compose with
        Returns:
        a new Field instance
      • to

        public <A> Field<A> to​(Codec<A> codec)
        Creates a field extractor that converts its value using the codec provided.
        Type Parameters:
        A - the desired final type
        Parameters:
        codec - the Codec to be used to convert the field's underlying value
        Returns:
        a new Field instance
      • to

        public <A> Field<A> to​(Class<A> type)
        Creates a field extractor that converts its value to the class provided.
        Type Parameters:
        A - the desired final type
        Parameters:
        type - the class to be used to convert the field's value
        Returns:
        a new Field instance
      • collect

        public <A> Field<List<A>> collect​(Field<A> field)
        Assuming the Value instance is a collection, creates a field extractor that collects the Field provided for each element in the underlying collection.
        Type Parameters:
        A - the desired final type for each collection element
        Parameters:
        field - the Field to be extracted from each collection element
        Returns:
        a new Field instance
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object