dm.datacube
Class DataCube

java.lang.Object
  |
  +--dm.datacube.DataCube

public class DataCube
extends java.lang.Object

Implements a DataCube using an array and a DCComp object

Author:
Scott Sanner

Inner Class Summary
 class DataCube.DataElement
          Internal class for data storage (not static because we want to access parent class fields)
 class DataCube.DataSet
          Internal class for iterator element storage (not static because we want to access parent class fields)
 
Field Summary
 java.util.ArrayList _alDimensions
           
 java.util.ArrayList _alPrintDimOrder
           
 boolean _bSealed
           
 DCComp _comp
           
 DataCube.DataElement[] _data
          Local data members
 java.text.DecimalFormat _df
           
 java.util.List _lParams
           
 int _nAgFun
           
 int _nDataSize
           
 int _nIterEnd
           
 int _nIterPos
          Iterator position
 int _nIterStart
           
 int _nTableWidth
          The following parameters are for printing only
 java.io.PrintStream _ps
           
 java.lang.String _sValLabel
           
static int INITIAL_SIZE
          Constants
 
Constructor Summary
DataCube(java.util.ArrayList dimensions, java.lang.String val_label)
          Constructor - default
 
Method Summary
 void addElement(java.lang.Integer[] key, java.lang.Integer val)
          Add a new entry to the data cube (don't sort)
 boolean addRestriction(java.lang.String dim_name, java.lang.Integer value)
          Adds a restriction to the DataCube and resort the DataCube
 java.lang.String computeAgVal(java.util.List data, int ag_fun, java.util.List params)
          Given a data list (of Integers), an aggregation function, a list of fun params, and width, returns a String resulting from the application of the specified function to the list
 boolean drillDownDim(java.lang.String dim_name)
          Adds a dimension to the DataCube and resort the DataCube
 boolean dropRestriction(java.lang.String dim_name)
          Drops a restriction from the DataCube and resort the DataCube
 int findRestrictionRange(boolean max)
          Find min or max key for data with current restrictions
 java.util.Set getActiveDims()
          Get a set of the current active datacube dimensions
 java.util.Set getAllDims()
          Get a set of all dimensions (active, inactive, restricted)
 Dimension getDim(int index)
          Get the Dimension object for a key index
 int getDimIndex(java.lang.String dim_name)
          Finds dimension index
 java.util.Set getDimKeys(java.lang.String dim_name)
          Get the possible set of keys for a dimension
 java.util.List getIndexList()
          Get a list of indices for the non-dropped Dimensions (in the order they are compared)
 java.util.Map getRestrictions()
          Get a set of the current active datacube restrictions
 java.util.List getValues(java.lang.Integer[] key)
          Retrieves all values for the given key according to current comparator (Comp)
 boolean hasNext()
          Returns whether there are more elements to iterate over
static java.lang.String indent(int level)
          A simple method for producing an indent based on level
 DataCube.DataSet next()
          Returns the next DataSet object for entries sharing the same key, starting at _nIterPos.
static java.lang.String pad(java.lang.String s, int len)
          A simple method for padding Strings to a given length
 void printCube(java.io.PrintStream ps, int table_width, int ag_fun, java.util.List params)
          Print this data cube to the given output stream
 void printDimension(int index, java.lang.Integer[] key)
          Recurse on the dimensions and print them
static java.lang.String repeat(java.lang.String s, int n)
          Produces repeated String
 void resetIterator()
          Resets the iterator
 void resortData()
          Resort the data according to the current Comparator (_comp)
 boolean rollUpDim(java.lang.String dim_name)
          Drops a dimension from the DataCube and resort the DataCube
 void sealDataCube()
          Once this is executed, the data is sorted but no more elements can be added due to the computational complexity of doing so
 int size()
          Get the size of this datacube
static java.lang.String trunc(java.lang.String s, int len)
          A simple method for truncating (or padding) string to a length
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INITIAL_SIZE

public static final int INITIAL_SIZE
Constants

_data

public DataCube.DataElement[] _data
Local data members

_alDimensions

public java.util.ArrayList _alDimensions

_sValLabel

public java.lang.String _sValLabel

_comp

public DCComp _comp

_bSealed

public boolean _bSealed

_nDataSize

public int _nDataSize

_nIterPos

public int _nIterPos
Iterator position

_nIterStart

public int _nIterStart

_nIterEnd

public int _nIterEnd

_nTableWidth

public int _nTableWidth
The following parameters are for printing only

_alPrintDimOrder

public java.util.ArrayList _alPrintDimOrder

_ps

public java.io.PrintStream _ps

_nAgFun

public int _nAgFun

_lParams

public java.util.List _lParams

_df

public java.text.DecimalFormat _df
Constructor Detail

DataCube

public DataCube(java.util.ArrayList dimensions,
                java.lang.String val_label)
Constructor - default
Parameters:
dimensions - Must be a list with the dimensions in the order that they appear.
Method Detail

addElement

public void addElement(java.lang.Integer[] key,
                       java.lang.Integer val)
Add a new entry to the data cube (don't sort)
Parameters:
key - Array of dim keys (same order as _alDimensions)
val - Value for this key

sealDataCube

public void sealDataCube()
Once this is executed, the data is sorted but no more elements can be added due to the computational complexity of doing so

resortData

public void resortData()
Resort the data according to the current Comparator (_comp)

drillDownDim

public boolean drillDownDim(java.lang.String dim_name)
Adds a dimension to the DataCube and resort the DataCube
Parameters:
dim_name - The name of the dimension to add
Returns:
Whether successful

rollUpDim

public boolean rollUpDim(java.lang.String dim_name)
Drops a dimension from the DataCube and resort the DataCube
Parameters:
dim_name - The name of the dimension to add
Returns:
Whether successful

addRestriction

public boolean addRestriction(java.lang.String dim_name,
                              java.lang.Integer value)
Adds a restriction to the DataCube and resort the DataCube
Parameters:
dim_name - The name of the dimension to add
Returns:
Whether successful

dropRestriction

public boolean dropRestriction(java.lang.String dim_name)
Drops a restriction from the DataCube and resort the DataCube
Parameters:
dim_name - The name of the dimension to add
Returns:
Whether successful

getDimIndex

public int getDimIndex(java.lang.String dim_name)
Finds dimension index
Parameters:
dim_name - The name of the dimension
Returns:
index of dimension, -1 if not found

getAllDims

public java.util.Set getAllDims()
Get a set of all dimensions (active, inactive, restricted)
Returns:
Set of Strings (dim names)

getRestrictions

public java.util.Map getRestrictions()
Get a set of the current active datacube restrictions
Returns:
Set of Strings (dim names)

getActiveDims

public java.util.Set getActiveDims()
Get a set of the current active datacube dimensions
Returns:
Set of Strings (dim names)

getDimKeys

public java.util.Set getDimKeys(java.lang.String dim_name)
Get the possible set of keys for a dimension
Parameters:
dim_name - Name of the dimension
Returns:
Set of keys (Integers)

getIndexList

public java.util.List getIndexList()
Get a list of indices for the non-dropped Dimensions (in the order they are compared)
Returns:
List of indices (Integers) for non-dropped Dimensions

getDim

public Dimension getDim(int index)
Get the Dimension object for a key index
Parameters:
index - The key index for this DataCube
Returns:
The Dimension object for the given key index

size

public int size()
Get the size of this datacube
Returns:
Number of elements in datacube

getValues

public java.util.List getValues(java.lang.Integer[] key)
Retrieves all values for the given key according to current comparator (Comp)
Parameters:
key - Array of key values in same order as _alDimensions
Returns:
List of values for the given key (empty list if nothing)

findRestrictionRange

public int findRestrictionRange(boolean max)
Find min or max key for data with current restrictions
Parameters:
max - if true will return max key, otherwise min key
Returns:
index of min or max key associated with current restrictions

resetIterator

public void resetIterator()
Resets the iterator

hasNext

public boolean hasNext()
Returns whether there are more elements to iterate over
Returns:
True if more elements to iterate over

next

public DataCube.DataSet next()
Returns the next DataSet object for entries sharing the same key, starting at _nIterPos. Note that the key should not be changed, it is not a copy but rather an actual key! Assumes the array has been sorted for the current Comparator (_comp) used to test equality.
Returns:
Next DataSet object (i.e. key and values)

printCube

public void printCube(java.io.PrintStream ps,
                      int table_width,
                      int ag_fun,
                      java.util.List params)
Print this data cube to the given output stream
Parameters:
ps - Stream to print to
table_width - Max width of a table element
ag_fun - int ID of aggregation function to use (see DMQL.Display)
params - List of parameters for the aggregation function

printDimension

public void printDimension(int index,
                           java.lang.Integer[] key)
Recurse on the dimensions and print them
Parameters:
dims - List of Dimensions (in order)
index - Dimension to print

computeAgVal

public java.lang.String computeAgVal(java.util.List data,
                                     int ag_fun,
                                     java.util.List params)
Given a data list (of Integers), an aggregation function, a list of fun params, and width, returns a String resulting from the application of the specified function to the list
Parameters:
data - List of data
ag_fun - int ID of the aggregation function (see DMQL.Display)
params - List of params for the aggregation function
Returns:
String representation of function result

trunc

public static java.lang.String trunc(java.lang.String s,
                                     int len)
A simple method for truncating (or padding) string to a length
Parameters:
s - String to process
len - Length to pad/truncate to
Returns:
Truncated/Padded version of string

indent

public static java.lang.String indent(int level)
A simple method for producing an indent based on level
Parameters:
level - Level to indent for
Returns:
String of spaces for indentation

repeat

public static java.lang.String repeat(java.lang.String s,
                                      int n)
Produces repeated String
Parameters:
s - String to repeat
n - number of times to repeat
Returns:
Repeated String

pad

public static java.lang.String pad(java.lang.String s,
                                   int len)
A simple method for padding Strings to a given length
Parameters:
s - String to pad
len - Length to pad to
Returns:
Padded version of string