com.google.gwt.visualization.client
Class DataColumn<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<T>
          extended by com.google.gwt.visualization.client.DataColumn<T>
All Implemented Interfaces:
java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>

public abstract class DataColumn<T>
extends java.util.AbstractList<T>

Represents a list view of a data column in an AbstractDataTable. For example:

   int columnIndex = ...;
   DataColumn<Integer> intColumn =
       DataColumn.integers(data, columnIndex);
   for (int value : intColumn) {
     ...
   }
   DataColumn<String> stringColumn =
       DataColumn.strings(data, stringColumnIndex);
   ...
 
Or if the column type is unknown:
   DataColumn<?> column = DataColumn.of(data, columnIndex);
 
This is useful for looping through a single column with the Java enhanced for loop. It also allows utilities provided in Java collection framework to be used. For example, Collections.min(java.util.Collection), Collections.max(java.util.Collection), Collections.binarySearch(List, Object) or Guava utilities such as com.google.common.collect.Iterable.filter etc. Passing around DataColumn object is also easier than passing around a data table along with the column index integer.

No mutation method such as List.add(Object) is supported, except List.set(int, Object), which writes through to the underlying data if the data is an instance of DataTable.

In order to add a row to the underlying table, use DataTable.addRow(). And then setValue(int, T) or set(int, T) can be used to set cell values.


Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Method Summary
static DataColumn<java.lang.Boolean> booleans(AbstractDataTable table, int columnIndex)
          Returns the column identified by columnIndex in table.
static DataColumn<java.lang.Boolean> booleans(AbstractDataTable table, java.lang.String columnId)
          Returns the column identified by columnId in table.
static DataColumn<java.util.Date> dates(AbstractDataTable table, int columnIndex)
          Returns the column identified by columnIndex in table.
static DataColumn<java.util.Date> dates(AbstractDataTable table, java.lang.String columnId)
          Returns the column identified by columnId in table.
static DataColumn<java.util.Date> datetimes(AbstractDataTable table, int columnIndex)
          Returns the column identified by columnIndex in table.
static DataColumn<java.util.Date> datetimes(AbstractDataTable table, java.lang.String columnId)
          Returns the column identified by columnId in table.
static DataColumn<java.lang.Double> doubles(AbstractDataTable table, int columnIndex)
          Returns the column identified by columnIndex in table.
static DataColumn<java.lang.Double> doubles(AbstractDataTable table, java.lang.String columnId)
          Returns the column identified by columnId in table.
abstract  T get(int row)
          Returns the cell value at row.
static java.util.List<DataColumn<?>> getAllColumns(AbstractDataTable dataTable)
          Returns a list of all the columns in the specified table, in the order they appear in the table.
 java.lang.String getColumnId()
          Returns the column id.
 int getColumnIndex()
          Returns the column index.
 java.lang.String getColumnLabel()
          Returns the column label.
 AbstractDataTable.ColumnType getColumnType()
          Returns the column type.
 AbstractDataTable getDataTable()
          Returns the underlying table that this object reads from or writes to.
static DataColumn<java.lang.Integer> integers(AbstractDataTable table, int columnIndex)
          Returns the column identified by columnIndex in table.
static DataColumn<java.lang.Integer> integers(AbstractDataTable table, java.lang.String columnId)
          Returns the column identified by columnId in table.
static DataColumn<?> of(AbstractDataTable table, int columnIndex)
          Returns the column identified by columnIndex in table.
static DataColumn<?> of(AbstractDataTable table, java.lang.String columnId)
          Returns the column identified by columnId in table.
 T set(int row, T value)
          Sets the cell value at row to value and returns the previous cell value.
 void setValue(int row, T value)
          Sets the cell value at row to value.
 int size()
          Returns the number of rows in the underlying table.
static DataColumn<java.lang.String> strings(AbstractDataTable table, int columnIndex)
          Returns the column identified by columnIndex in table.
static DataColumn<java.lang.String> strings(AbstractDataTable table, java.lang.String columnId)
          Returns the column identified by columnId in table.
static DataColumn<TimeOfDay> timeOfDays(AbstractDataTable table, int columnIndex)
          Returns the column identified by columnIndex in table.
static DataColumn<TimeOfDay> timeOfDays(AbstractDataTable table, java.lang.String columnId)
          Returns the column identified by columnId in table.
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Method Detail

getColumnId

public final java.lang.String getColumnId()
Returns the column id. @see AbstractDataTable#getColumnId(int)


getColumnType

public final AbstractDataTable.ColumnType getColumnType()
Returns the column type. @see AbstractDataTable#getColumnType(int)


getColumnLabel

public final java.lang.String getColumnLabel()
Returns the column label. @see AbstractDataTable#getColumnLabel(int)


getColumnIndex

public final int getColumnIndex()
Returns the column index.


getDataTable

public final AbstractDataTable getDataTable()
Returns the underlying table that this object reads from or writes to.


get

public abstract T get(int row)
Returns the cell value at row.

Specified by:
get in interface java.util.List<T>
Specified by:
get in class java.util.AbstractList<T>

set

public final T set(int row,
                   T value)
Sets the cell value at row to value and returns the previous cell value. Unsupported unless the underlying table is an instance of DataTable.

When the previous value isn't need, use setValue(int, Object) for better performance.

Specified by:
set in interface java.util.List<T>
Overrides:
set in class java.util.AbstractList<T>

setValue

public final void setValue(int row,
                           T value)
Sets the cell value at row to value. Unsupported unless the underlying table is an instance of DataTable.


size

public final int size()
Returns the number of rows in the underlying table.

Specified by:
size in interface java.util.Collection<T>
Specified by:
size in interface java.util.List<T>
Specified by:
size in class java.util.AbstractCollection<T>

of

public static DataColumn<?> of(AbstractDataTable table,
                               java.lang.String columnId)
Returns the column identified by columnId in table.

Throws:
java.lang.IllegalArgumentException - if columnId is not found

of

public static DataColumn<?> of(AbstractDataTable table,
                               int columnIndex)
Returns the column identified by columnIndex in table.


booleans

public static DataColumn<java.lang.Boolean> booleans(AbstractDataTable table,
                                                     java.lang.String columnId)
Returns the column identified by columnId in table.

Throws:
java.lang.IllegalArgumentException - if columnId is not found

booleans

public static DataColumn<java.lang.Boolean> booleans(AbstractDataTable table,
                                                     int columnIndex)
Returns the column identified by columnIndex in table.


integers

public static DataColumn<java.lang.Integer> integers(AbstractDataTable table,
                                                     java.lang.String columnId)
Returns the column identified by columnId in table.

Throws:
java.lang.IllegalArgumentException - if columnId is not found

integers

public static DataColumn<java.lang.Integer> integers(AbstractDataTable table,
                                                     int columnIndex)
Returns the column identified by columnIndex in table.


doubles

public static DataColumn<java.lang.Double> doubles(AbstractDataTable table,
                                                   java.lang.String columnId)
Returns the column identified by columnId in table.

Throws:
java.lang.IllegalArgumentException - if columnId is not found

doubles

public static DataColumn<java.lang.Double> doubles(AbstractDataTable table,
                                                   int columnIndex)
Returns the column identified by columnIndex in table.


strings

public static DataColumn<java.lang.String> strings(AbstractDataTable table,
                                                   java.lang.String columnId)
Returns the column identified by columnId in table.

Throws:
java.lang.IllegalArgumentException - if columnId is not found

strings

public static DataColumn<java.lang.String> strings(AbstractDataTable table,
                                                   int columnIndex)
Returns the column identified by columnIndex in table.


dates

public static DataColumn<java.util.Date> dates(AbstractDataTable table,
                                               java.lang.String columnId)
Returns the column identified by columnId in table.

Throws:
java.lang.IllegalArgumentException - if columnId is not found

dates

public static DataColumn<java.util.Date> dates(AbstractDataTable table,
                                               int columnIndex)
Returns the column identified by columnIndex in table.


datetimes

public static DataColumn<java.util.Date> datetimes(AbstractDataTable table,
                                                   java.lang.String columnId)
Returns the column identified by columnId in table.

Throws:
java.lang.IllegalArgumentException - if columnId is not found

datetimes

public static DataColumn<java.util.Date> datetimes(AbstractDataTable table,
                                                   int columnIndex)
Returns the column identified by columnIndex in table.


timeOfDays

public static DataColumn<TimeOfDay> timeOfDays(AbstractDataTable table,
                                               java.lang.String columnId)
Returns the column identified by columnId in table.

Throws:
java.lang.IllegalArgumentException - if columnId is not found

timeOfDays

public static DataColumn<TimeOfDay> timeOfDays(AbstractDataTable table,
                                               int columnIndex)
Returns the column identified by columnIndex in table.


getAllColumns

public static java.util.List<DataColumn<?>> getAllColumns(AbstractDataTable dataTable)
Returns a list of all the columns in the specified table, in the order they appear in the table.