Class Value

    • Method Detail

      • to

        public final <T> Result<T> to​(Codec<T> codec)
        Attempts to convert the value using the Codec passed.
        Type Parameters:
        T - the type to convert to
        Parameters:
        codec - codec function to attempt conversion
        Returns:
        the Result of the conversion
        See Also:
        Codec
      • to

        public final <T> Result<T> to​(Class<T> clazz)
        Attempts to decode the value using the reflection Decoder.
        Type Parameters:
        T - the type to convert to
        Parameters:
        clazz - a class type to convert
        Returns:
        the Result of the conversion
        See Also:
        Decoder
      • from

        public static <T> Result<Value> from​(T obj)
        Attempts to encode an object as a Value using the reflection Encoder.
        Type Parameters:
        T - the type to convert from
        Parameters:
        obj - the object instance to encode
        Returns:
        the Result of the conversion
      • asMapOf

        public final <T> Result<Map<String,​T>> asMapOf​(Class<T> valueType)
        Attempts to convert the value to a Map.
        Type Parameters:
        T - the type of the values on Map
        Parameters:
        valueType - the type of the desired Map's values.
        Returns:
        a Result containing the resulting Map.
        See Also:
        Decoder, Types
      • toMap

        public final <T> Map<String,​T> toMap​(Class<T> valueType)
        Attempts to convert the value to a Map.
        Type Parameters:
        T - the type of the values in the Map
        Parameters:
        valueType - the type of the values in the Map
        Returns:
        a Map
        See Also:
        Decoder, Types
      • collect

        public final <T> Collection<T> collect​(Class<T> elementType)
        Attempts to convert the value to a Collection.
        Type Parameters:
        T - the type of the elements in the Collection
        Parameters:
        elementType - the type of the elements in the Collection
        Returns:
        a new collection
        See Also:
        Decoder, Types
      • get

        public final <T> T get​(Field<T> field)
        Extract a Field from the value.
        Type Parameters:
        T - the type of returned field
        Parameters:
        field - the Field to extract
        Returns:
        the resulting value of extracting the Field from this value
        Throws:
        IllegalStateException - if Field does not exists on this value
        See Also:
        Field
      • get

        public final <T> T get​(Class<T> clazz)
        Attempts to decode the value using the reflection Decoder.
        Type Parameters:
        T - the type to convert to
        Parameters:
        clazz - a class type to convert
        Returns:
        the converted result
        See Also:
        Decoder
      • getOptional

        public final <T> Optional<T> getOptional​(Field<T> field)
        Safely attempts to extract a Field from this value.
        Type Parameters:
        T - the type of returned field
        Parameters:
        field - Field to extract
        Returns:
        An Optional containing the resulting value, if the field extraction was successful. It returns Optional.empty(), otherwise.
        See Also:
        Field
      • orNull

        public final Value orNull()
        Returns this value, or returns null if no value is present.
        Returns:
        the value or null
      • collect

        public final <T> List<T> collect​(Field<T> field)
        Assuming the underlying value is a collection, it collects the Field provided for all elements in the collection.

        For example:

        
           Field<String> userName = Field.at("name").to(String.class);
           Value result = client.query(getAllUsersQuery).get();
           List<String> userNames = result.at("data").collect(userName);
         
        Type Parameters:
        T - the type of the elements in the resulting List
        Parameters:
        field - the Field to extract from each element in the underlying collection
        Returns:
        a List with the collected fields
        See Also:
        Field
      • at

        public final Value at​(String... keys)
        Assuming the underlying value is a key/value map, it traverses to a desired path.

        For example:

        
           Value result = client.query(getUser).get();
           Value zipCode = result.at("data", "address", "zipCode");
         
        Parameters:
        keys - the object keys to traverse
        Returns:
        the Value under the path provided
      • at

        public final Value at​(int... indexes)
        Assuming the underlying value is a collection, it traverses to a desired path.

        For example:

        
           Value result = client.query(getAllUsers).get();
           Value firstUser = result.at("data").at(0);
         
        Parameters:
        indexes - the collection indexes to traverse
        Returns:
        the Value under the path provided