Class AppendStoreBuilder

java.lang.Object
ca.spatial.table.AppendStoreBuilder

public class AppendStoreBuilder extends Object
This class provides a simpler way to set up an AppendStore than by using the ApendStore constructor.

Use this class by first repeatedly calling the addColumn(java.lang.String, java.lang.String, int, int) method to define the columns of interest. Then repeatedly call the addTable(ca.spatial.table.AttributeStore, java.lang.String, int, java.lang.String[]) method to add the tables to be appended as well as the way the columns should be populated with data from each table. Finally, call the build() method to generate the table.

An example of using this class is as follows:

   appendStores = new AppendStoreBuilder();

   /* Add the column definitions */ 
   appendStores.addColumn("Scenario", "C", 6, 0);
   appendStores.addColumn("PLANFU", "C", 6, 0);
   appendStores.addColumn("SI", "C", 8, 0);
   appendStores.addColumn("HECTARES", "N", 8, 2);
   appendStores.addColumn("AV_STKG", "N", 6, 4);
   appendStores.addColumn("AV_SC", "N", 6, 4);

   /*
    * Add the definition for the first table to be appended.
    * The definition consists of a reference to the source table,
    * a reselect expression, the period of interest, 
    * and a list of expressions that will be used to calculate
    * the column data for this table.
    */
   appendStores.addTable(table1, "true", 0, new String[] {
      "'Scenario1'",
      "PLANFU",
      "Scenario",
      "Shape_Area/10000",
      "STKG/Shape_Area",
      "SC/Shape_Area"
   }); 

   /* Add the definition for the second table to be appended. */
   appendStores.addTable(table2, "true", 0, new String[] {
      "'Scenario2'",
      "FU",
      "ScenName",
      "Area/10000",
      "STKG/Area",
      "SC/Area"
   }); 

   /* Build the appended table */
   appData = appendStores.build();

   /* Show the appended table */
   appData.showTable(true);
 
The above example will create a new virtual table that refects the appended inputs. The output table will show 6 columns, and the values in the output will be transformed from the input according to expressions in each of the addTable methods.

Note that the data in the resulting append store is reflected from the source tables. The orginal tables must remain open and accessible so long as the AppendStore is being used.

See Also:
AppendStore
  • Constructor Details

    • AppendStoreBuilder

      public AppendStoreBuilder()
      The default constructor does not require any arguments
    • AppendStoreBuilder

      public AppendStoreBuilder(AttributeStore prototype)
      This contstructor will copy the attribute structure from the prototype table
      Parameters:
      prototype - A reference to a table that will provide the colummns to be used
  • Method Details

    • addColumn

      public AppendStoreBuilder addColumn(String name, String type, int width, int dec)
      Add a column definition. All column definitions must be completed prior to adding table definitions.
      Parameters:
      name - the name to be used for the column
      type - the data type, which may be C, I, N or L (String, Integer, Number, Boolean)
      width - the field width to be used on output
      dec - the number of digits of precision after the decimal place, used on output
    • addColumn

      public AppendStoreBuilder addColumn(String name, int type, int width, int dec)
      Add a column definition. All column definitions must be completed prior to adding table definitions.
      Parameters:
      name - the name to be used for the column
      type - the data type, as taken from the AttributeFormat class. Valid types are INTEGER, NUMBER, BOOLEAN and STRING.
      width - the field width to be used on output
      dec - the number of digits of precision after the decimal place, used on output
    • addColumn

      public AppendStoreBuilder addColumn(AttributeFormat af)
    • getColumnCount

      public int getColumnCount()
      Return the number of defined columns
    • getColumnSpec

      public AppendColumnSpec getColumnSpec(int i)
      Return a column definition
    • addTable

      public AppendStoreBuilder addTable(AttributeStore store, String reselect, int period, String[] exprs)
      Add a table definition. All column definitions must be completed prior to adding table definitions.
      Parameters:
      store - A reference to the atttribute store for this table
      reselect - A reselect expression to limit the number of records included from the table. This may be null to include all records.
      period - The period to evaluate the expression in.
      exprs - An array of expressions represent the data to populate in to the columns of the AppendStore. The expression may use any of the columns from the input table. This parameter amy be null, or any of the array values may be null, in which case the corresponding colymn name will be used as the expression.
    • addTable

      public AppendStoreBuilder addTable(AttributeStore store, String[] exprs)
      Add a table definition. All column definitions must be completed prior to adding table definitions.
      Parameters:
      store - A reference to the atttribute store for this table
      exprs - An array of expressions represent the data to populate in to the columns of the AppendStore. The expression may use any of the columns from the input table. This parameter amy be null, or any of the array values may be null, in which case the corresponding colymn name will be used as the expression.
    • getTableCount

      public int getTableCount()
      Return the number of defined tables
    • getTable

      public AttributeStore getTable(int i)
      Return a table definition
      Parameters:
      i - The table number of interest
    • getTableColumns

      public String[] getTableColumns(int i)
      Return the column expressions for a table
      Parameters:
      i - The table number of interest
    • getTablePeriod

      public int getTablePeriod(int i)
      Return the period of interest a table
      Parameters:
      i - The table number of interest
    • getTableReselect

      public String getTableReselect(int i)
      Return the reselect expression used for a table
      Parameters:
      i - The table number of interest
    • build

      public AppendStore build()
      This method will construct an AppendStore object based on the columns and tables that have been specified.