Class DataRow.Builder

  • Enclosing class:
    DataRow

    public class DataRow.Builder
    extends Object
    Used with DataRow.build(Consumer<DataRow.Builder>).

    Infinite recursion while using Supplier for value of field

    In following code snippet, the builder will set-up a field which cause infinite recursion while getting data:
    
     builder -> builder.fieldOfValueSupplier(
         "ct_1", () -> 30 + builder.getDataSupplier("ct_1").get().get()
     )
     
    Since the lazy evaluation of lambda expression, the new lambda expression of "ct_1" would be a self-reference to builder.
    Instead, you should keep "the old instance of lambda expression":
    
     builder -> {
         final Supplier<Integer> oldSupplier = builder.getDataSupplier("ct_1").get();
         builder.fieldOfValueSupplier("ct_1", () -> 30 + oldSupplier.get());
     }
     
    • Method Detail

      • tableSchema

        public DataRow.Builder tableSchema​(SchemaTable newTableSchema)
        Sets the table schema.
        Parameters:
        newTableSchema - The table schema
        Returns:
        cascading self
      • fieldOfValue

        public <T> DataRow.Builder fieldOfValue​(String columnName,
                                                T value)
        Sets value of a field.
        Type Parameters:
        T - The type of value
        Parameters:
        columnName - The name of column
        value - The value instance
        Returns:
        cascading self
      • fieldOfValueSupplier

        public <T> DataRow.Builder fieldOfValueSupplier​(String columnName,
                                                        Supplier<T> valueSupplier)
        Sets value supplier of a field.
        Type Parameters:
        T - The type of value
        Parameters:
        columnName - The name of column
        valueSupplier - The value instance
        Returns:
        cascading self
      • getValidated

        public boolean getValidated()
        Whether the data row is validated or not.
        Returns:
        true if validated
      • getTableName

        public String getTableName()
        Gets name of table.
        Returns:
        the name of table
        See Also:
        getTable()
      • getData

        public <T> Optional<T> getData​(String columnName)
        Gets value of data.
        Type Parameters:
        T - The type of data
        Parameters:
        columnName - The name of column
        Returns:
        empty option if the column is not existing or the value is empty
      • getDataSupplier

        public <T> Optional<Supplier<T>> getDataSupplier​(String columnName)
        Gets supplier of data.

        Note: be careful of lazy building, which may cause infinite recursion

        Following code will cause infinite recursion
        
         Supplier<Integer> wrappedSupplier = () -> 20 + builder.<Integer>getDataSupplier("ct_1").get().get();
         builder.fieldOfValueSupplier("col_1", wrappedSupplier);
         
        Instead, you should:
        
         // Keep the reference of supplier in current lambda of builder
         Supplier<Integer> sourceSupplier = builder.<Integer>getDataSupplier("ct_1").get();
         Supplier<Integer> wrappedSupplier = () -> 20 + sourceSupplier.get();
        
         builder.fieldOfValueSupplier("col_1", wrappedSupplier);
         
        Type Parameters:
        T - The type of data for the supplier
        Parameters:
        columnName - The name of column
        Returns:
        empty option if the column is not existing or the value supplier is empty
      • getDataField

        public <T> Optional<DataField<T>> getDataField​(String columnName)
        Gets field of data.
        Type Parameters:
        T - The data type of field
        Parameters:
        columnName - The name of column
        Returns:
        empty option if the column is not existing
      • getStreamOfFields

        public Stream<DataField<?>> getStreamOfFields()
        Gets the fields as Stream.
        Returns:
        The data fields as stream