org.deidentifier.arx

## Class DataHandle

- java.lang.Object
- - org.deidentifier.arx.DataHandle

Direct Known Subclasses:
  DataHandleInput, DataHandleOutput, DataHandleSubset

    public abstract class DataHandle
    extends java.lang.Object

This class provides access to dictionary encoded data. Furthermore, the data is linked to the associated input or output data. This means that, e.g., if the input data is sorted, the output data will be sorted accordingly. This ensures that original tuples and their generalized counterpart will always have the same row index, which is important for many use cases, e.g., for graphical tools that allow to compare the original dataset to generalized versions.

Author:
  Fabian Prasser, Florian Kohlmayer

### Constructor Summary

Constructors
Constructor and Description
`DataHandle()`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`abstract java.lang.String` `getAttributeName(int col)` Returns the name of the specified column.
`int` `getColumnIndexOf(java.lang.String attribute)` Returns the index of the given attribute, -1 if it is not in the header.
`DataType<?>` `getDataType(java.lang.String attribute)` Returns the according data type.
`java.util.Date` `getDate(int row, int col)` Returns a date/time value from the specified cell.
`DataDefinition` `getDefinition()` Returns the data definition.
`java.lang.String[]` `getDistinctValues(int column)` Returns an array containing the distinct values in the given column.
`java.lang.Double` `getDouble(int row, int col)` Returns a double value from the specified cell.
`java.lang.Float` `getFloat(int row, int col)` Returns a float value from the specified cell.
`abstract int` `getGeneralization(java.lang.String attribute)` Returns the generalization level for the attribute.
`java.lang.Integer` `getInt(int row, int col)` Returns an int value from the specified cell.
`java.lang.Long` `getLong(int row, int col)` Returns a long value from the specified cell.
`java.util.List<org.apache.commons.math3.util.Pair<DataType<?>,java.lang.Double>>` `getMatchingDataTypes(int column)` Returns a mapping from data types to the relative number of values that conform to the according type.
`<U> java.util.List<org.apache.commons.math3.util.Pair<DataType<?>,java.lang.Double>>` `getMatchingDataTypes(int column, java.lang.Class<U> clazz)` Returns a mapping from data types to the relative number of values that conform to the according type for a given wrapped class.
`<U> java.util.List<org.apache.commons.math3.util.Pair<DataType<?>,java.lang.Double>>` `getMatchingDataTypes(int column, java.lang.Class<U> clazz, double threshold)` Returns a mapping from data types to the relative number of values that conform to the according type for a given wrapped class.
`<U> java.util.List<org.apache.commons.math3.util.Pair<DataType<?>,java.lang.Double>>` `getMatchingDataTypes(int column, java.lang.Class<U> clazz, java.util.Locale locale)` Returns a mapping from data types to the relative number of values that conform to the according type for a given wrapped class.
`<U> java.util.List<org.apache.commons.math3.util.Pair<DataType<?>,java.lang.Double>>` `getMatchingDataTypes(int column, java.lang.Class<U> clazz, java.util.Locale locale, double threshold)` Returns a mapping from data types to the relative number of values that conform to the according type for a given wrapped class.
`java.util.List<org.apache.commons.math3.util.Pair<DataType<?>,java.lang.Double>>` `getMatchingDataTypes(int column, double threshold)` Returns a mapping from data types to the relative number of values that conform to the according type.
`java.util.List<org.apache.commons.math3.util.Pair<DataType<?>,java.lang.Double>>` `getMatchingDataTypes(int column, java.util.Locale locale)` Returns a mapping from data types to the relative number of values that conform to the according type This method only returns types that match at least 80% of all values in the column .
`java.util.List<org.apache.commons.math3.util.Pair<DataType<?>,java.lang.Double>>` `getMatchingDataTypes(int column, java.util.Locale locale, double threshold)` Returns a mapping from data types to the relative number of values that conform to the according type.
`java.lang.String[]` `getNonConformingValues(int column, DataType<?> type, int max)` Returns a set of values that do not conform to the given data type.
`abstract int` `getNumColumns()` Returns the number of columns in the dataset.
`int` `getNumConformingValues(int column, DataType<?> type)` Returns the number of (distinct) values that conform to the given data type.
`abstract int` `getNumRows()` Returns the number of rows in the dataset.
`RiskEstimateBuilder` `getRiskEstimator()` Returns a risk estimator, using the US population if required
`RiskEstimateBuilder` `getRiskEstimator(ARXPopulationModel model)` Returns a risk estimator
`RiskEstimateBuilder` `getRiskEstimator(ARXPopulationModel model, ARXSolverConfiguration config)` Returns a risk estimator
`RiskEstimateBuilder` `getRiskEstimator(ARXPopulationModel model, RiskModelHistogram classes)` Returns a risk estimator for the given set of equivalence classes.
`RiskEstimateBuilder` `getRiskEstimator(ARXPopulationModel model, RiskModelHistogram classes, ARXSolverConfiguration config)` Returns a risk estimator for the given set of equivalence classes.
`RiskEstimateBuilder` `getRiskEstimator(ARXPopulationModel model, java.util.Set<java.lang.String> qis)` Returns a risk estimator for the given set of quasi-identifiers
`RiskEstimateBuilder` `getRiskEstimator(ARXPopulationModel model, java.util.Set<java.lang.String> qis, ARXSolverConfiguration config)` Returns a risk estimator for the given set of quasi-identifiers
`abstract StatisticsBuilder` `getStatistics()` Returns an object providing access to basic descriptive statistics about the data represented by this handle.
`ARXLattice.ARXNode` `getTransformation()` Returns the transformation .
`abstract java.lang.String` `getValue(int row, int col)` Returns the value in the specified cell.
`DataHandle` `getView()` Returns a new data handle that represents a context specific view on the dataset.
`boolean` `isOptimized()` Has this handle been optimized with local recoding?
`boolean` `isOutlier(int row)` Determines whether a given row is an outlier in the currently associated data transformation.
`boolean` `isReleased()` Determines whether this handle is orphaned, i.e., should not be used anymore
`boolean` `isSuppressed(int row)` Determines whether a given row is completely suppressed
`abstract java.util.Iterator<java.lang.String[]>` `iterator()` Returns an iterator over the data.
`void` `release()` Releases this handle and all associated resources.
`ElementData` `render()` Renders this object
`boolean` `replace(int column, java.lang.String original, java.lang.String replacement)` Replaces the original value with the replacement in the given column.
`void` `save(java.io.File file)` Writes the data to a CSV file.
`void` `save(java.io.File file, char separator)` Writes the data to a CSV file.
`void` `save(java.io.File file, CSVSyntax config)` Writes the data to a CSV file.
`void` `save(java.io.OutputStream out)` Writes the data to a CSV file.
`void` `save(java.io.OutputStream out, char separator)` Writes the data to a CSV file.
`void` `save(java.io.OutputStream out, CSVSyntax config)` Writes the data to a CSV file.
`void` `save(java.lang.String path)` Writes the data to a CSV file.
`void` `save(java.lang.String path, char separator)` Writes the data to a CSV file.
`void` `save(java.lang.String path, CSVSyntax config)` Writes the data to a CSV file.
`void` `sort(boolean ascending, int... columns)` Sorts the dataset according to the given columns.
`void` `sort(int from, int to, boolean ascending, int... columns)` Sorts the dataset according to the given columns and the given range.
`void` `sort(cern.colt.Swapper swapper, boolean ascending, int... columns)` Sorts the dataset according to the given columns.
`void` `sort(cern.colt.Swapper swapper, int from, int to, boolean ascending, int... columns)` Sorts the dataset according to the given columns and the given range.
`void` `swap(int row1, int row2)` Swaps both rows.

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### DataHandle

    public DataHandle()

### Method Detail

#### getAttributeName

    public abstract java.lang.String getAttributeName(int col)

Returns the name of the specified column.

Parameters:
  `col` - The column index
Returns:
  the attribute name

#### getColumnIndexOf

    public int getColumnIndexOf(java.lang.String attribute)

Returns the index of the given attribute, -1 if it is not in the header.

Parameters:
  `attribute` - the attribute
Returns:
  the column index of

#### getDataType

    public DataType<?> getDataType(java.lang.String attribute)

Returns the according data type.

Parameters:
  `attribute` - the attribute
Returns:
  the data type

#### getDate

    public java.util.Date getDate(int row,
                                  int col)
                           throws java.text.ParseException

Returns a date/time value from the specified cell.

Parameters:
  `row` - The cell's row index
  `col` - The cell's column index
Returns:
  the date
Throws:
  `java.text.ParseException` - the parse exception

#### getDefinition

    public DataDefinition getDefinition()

Returns the data definition.

Returns:
  the definition

#### getDistinctValues

    public final java.lang.String[] getDistinctValues(int column)

Returns an array containing the distinct values in the given column.

Parameters:
  `column` - The column to process
Returns:
  the distinct values

#### getDouble

    public java.lang.Double getDouble(int row,
                                      int col)
                               throws java.text.ParseException

Returns a double value from the specified cell.

Parameters:
  `row` - The cell's row index
  `col` - The cell's column index
Returns:
  the double
Throws:
  `java.text.ParseException` - the parse exception

#### getFloat

    public java.lang.Float getFloat(int row,
                                    int col)
                             throws java.text.ParseException

Returns a float value from the specified cell.

Parameters:
  `row` - The cell's row index
  `col` - The cell's column index
Returns:
  the float
Throws:
  `java.text.ParseException` - the parse exception

#### getGeneralization

    public abstract int getGeneralization(java.lang.String attribute)

Returns the generalization level for the attribute.

Parameters:
  `attribute` - the attribute
Returns:
  the generalization

#### getInt

    public java.lang.Integer getInt(int row,
                                    int col)
                             throws java.text.ParseException

Returns an int value from the specified cell.

Parameters:
  `row` - The cell's row index
  `col` - The cell's column index
Returns:
  the int
Throws:
  `java.text.ParseException` - the parse exception

#### getLong

    public java.lang.Long getLong(int row,
                                  int col)
                           throws java.text.ParseException

Returns a long value from the specified cell.

Parameters:
  `row` - The cell's row index
  `col` - The cell's column index
Returns:
  the long
Throws:
  `java.text.ParseException` - the parse exception

#### getMatchingDataTypes

    public java.util.List<org.apache.commons.math3.util.Pair<DataType<?>,java.lang.Double>> getMatchingDataTypes(int column)

Returns a mapping from data types to the relative number of values that conform to the according type. This method uses the default locale. This method only returns types that match at least 80% of all values in the column .

Parameters:
  `column` - the column
Returns:
  the matching data types

#### getMatchingDataTypes

    public <U> java.util.List<org.apache.commons.math3.util.Pair<DataType<?>,java.lang.Double>> getMatchingDataTypes(int column,
                                                                                                                     java.lang.Class<U> clazz)

Returns a mapping from data types to the relative number of values that conform to the according type for a given wrapped class. This method uses the default locale. This method only returns types that match at least 80% of all values in the column .

Type Parameters:
  `U` - the generic type
Parameters:
  `column` - the column
  `clazz` - The wrapped class
Returns:
  the matching data types

#### getMatchingDataTypes

    public <U> java.util.List<org.apache.commons.math3.util.Pair<DataType<?>,java.lang.Double>> getMatchingDataTypes(int column,
                                                                                                                     java.lang.Class<U> clazz,
                                                                                                                     double threshold)

Returns a mapping from data types to the relative number of values that conform to the according type for a given wrapped class. This method uses the default locale.

Type Parameters:
  `U` - the generic type
Parameters:
  `column` - the column
  `clazz` - The wrapped class
  `threshold` - Relative minimal number of values that must match to include a data type in the results
Returns:
  the matching data types

#### getMatchingDataTypes

    public <U> java.util.List<org.apache.commons.math3.util.Pair<DataType<?>,java.lang.Double>> getMatchingDataTypes(int column,
                                                                                                                     java.lang.Class<U> clazz,
                                                                                                                     java.util.Locale locale)

Returns a mapping from data types to the relative number of values that conform to the according type for a given wrapped class. This method only returns types that match at least 80% of all values in the column .

Type Parameters:
  `U` - the generic type
Parameters:
  `column` - the column
  `clazz` - The wrapped class
  `locale` - The locale to use
Returns:
  the matching data types

#### getMatchingDataTypes

    public <U> java.util.List<org.apache.commons.math3.util.Pair<DataType<?>,java.lang.Double>> getMatchingDataTypes(int column,
                                                                                                                     java.lang.Class<U> clazz,
                                                                                                                     java.util.Locale locale,
                                                                                                                     double threshold)

Returns a mapping from data types to the relative number of values that conform to the according type for a given wrapped class.

Type Parameters:
  `U` - the generic type
Parameters:
  `column` - the column
  `clazz` - The wrapped class
  `locale` - The locale to use
  `threshold` - Relative minimal number of values that must match to include a data type in the results
Returns:
  the matching data types

#### getMatchingDataTypes

    public java.util.List<org.apache.commons.math3.util.Pair<DataType<?>,java.lang.Double>> getMatchingDataTypes(int column,
                                                                                                                 double threshold)

Returns a mapping from data types to the relative number of values that conform to the according type. This method uses the default locale.

Parameters:
  `column` - the column
  `threshold` - Relative minimal number of values that must match to include a data type in the results
Returns:
  the matching data types

#### getMatchingDataTypes

    public java.util.List<org.apache.commons.math3.util.Pair<DataType<?>,java.lang.Double>> getMatchingDataTypes(int column,
                                                                                                                 java.util.Locale locale)

Returns a mapping from data types to the relative number of values that conform to the according type This method only returns types that match at least 80% of all values in the column .

Parameters:
  `column` - the column
  `locale` - The locale to use
Returns:
  the matching data types

#### getMatchingDataTypes

    public java.util.List<org.apache.commons.math3.util.Pair<DataType<?>,java.lang.Double>> getMatchingDataTypes(int column,
                                                                                                                 java.util.Locale locale,
                                                                                                                 double threshold)

Returns a mapping from data types to the relative number of values that conform to the according type.

Parameters:
  `column` - the column
  `locale` - The locale to use
  `threshold` - Relative minimal number of values that must match to include a data type in the results
Returns:
  the matching data types

#### getNonConformingValues

    public java.lang.String[] getNonConformingValues(int column,
                                                     DataType<?> type,
                                                     int max)

Returns a set of values that do not conform to the given data type.

Parameters:
  `column` - The column to test
  `type` - The type to test
  `max` - The maximal number of values returned by this method
Returns:
  the non conforming values

#### getNumColumns

    public abstract int getNumColumns()

Returns the number of columns in the dataset.

Returns:
  the num columns

#### getNumConformingValues

    public int getNumConformingValues(int column,
                                      DataType<?> type)

Returns the number of (distinct) values that conform to the given data type.

Parameters:
  `column` - The column to test
  `type` - The type to test
Returns:
  the num conforming values

#### getNumRows

    public abstract int getNumRows()

Returns the number of rows in the dataset.

Returns:
  the num rows

#### getRiskEstimator

    public RiskEstimateBuilder getRiskEstimator()

Returns a risk estimator, using the US population if required

Returns:

#### getRiskEstimator

    public RiskEstimateBuilder getRiskEstimator(ARXPopulationModel model)

Returns a risk estimator

Parameters:
  `model` -
Returns:

#### getRiskEstimator

    public RiskEstimateBuilder getRiskEstimator(ARXPopulationModel model,
                                                ARXSolverConfiguration config)

Returns a risk estimator

Parameters:
  `model` -
  `config` -
Returns:

#### getRiskEstimator

    public RiskEstimateBuilder getRiskEstimator(ARXPopulationModel model,
                                                RiskModelHistogram classes)

Returns a risk estimator for the given set of equivalence classes. Saves resources by re-using existing classes

Parameters:
  `model` -
  `classes` -
Returns:

#### getRiskEstimator

    public RiskEstimateBuilder getRiskEstimator(ARXPopulationModel model,
                                                RiskModelHistogram classes,
                                                ARXSolverConfiguration config)

Returns a risk estimator for the given set of equivalence classes. Saves resources by re-using existing classes

Parameters:
  `model` -
  `classes` -
  `config` -
Returns:

#### getRiskEstimator

    public RiskEstimateBuilder getRiskEstimator(ARXPopulationModel model,
                                                java.util.Set<java.lang.String> qis)

Returns a risk estimator for the given set of quasi-identifiers

Parameters:
  `model` -
  `qis` -
Returns:

#### getRiskEstimator

    public RiskEstimateBuilder getRiskEstimator(ARXPopulationModel model,
                                                java.util.Set<java.lang.String> qis,
                                                ARXSolverConfiguration config)

Returns a risk estimator for the given set of quasi-identifiers

Parameters:
  `model` -
  `qis` -
  `config` -
Returns:

#### getStatistics

    public abstract StatisticsBuilder getStatistics()

Returns an object providing access to basic descriptive statistics about the data represented by this handle.

Returns:
  the statistics

#### getTransformation

    public ARXLattice.ARXNode getTransformation()

Returns the transformation .

Returns:
  the transformation

#### getValue

    public abstract java.lang.String getValue(int row,
                                              int col)

Returns the value in the specified cell.

Parameters:
  `row` - The cell's row index
  `col` - The cell's column index
Returns:
  the value

#### getView

    public DataHandle getView()

Returns a new data handle that represents a context specific view on the dataset.

Returns:
  the view

#### isOptimized

    public boolean isOptimized()

Has this handle been optimized with local recoding?

Returns:

#### isOutlier

    public boolean isOutlier(int row)

Determines whether a given row is an outlier in the currently associated data transformation.

Parameters:
  `row` - the row
Returns:
  true, if is outlier

#### isReleased

    public boolean isReleased()

Determines whether this handle is orphaned, i.e., should not be used anymore

Returns:
  true, if this handle has been released

#### isSuppressed

    public boolean isSuppressed(int row)

Determines whether a given row is completely suppressed

Parameters:
  `row` - the row
Returns:
  true, if is suppressed

#### iterator

    public abstract java.util.Iterator<java.lang.String[]> iterator()

Returns an iterator over the data.

Returns:
  the iterator

#### release

    public void release()

Releases this handle and all associated resources. If a input handle is released all associated results are released as well.

#### render

    public ElementData render()

Renders this object

Returns:

#### replace

    public boolean replace(int column,
                           java.lang.String original,
                           java.lang.String replacement)

Replaces the original value with the replacement in the given column. Only supported by handles for input data.

Parameters:
  `column` - the column
  `original` - the original
  `replacement` - the replacement
Returns:
  Whether the original value was found

#### save

    public void save(java.io.File file)
              throws java.io.IOException

Writes the data to a CSV file.

Parameters:
  `file` - the file
Throws:
  `java.io.IOException` - Signals that an I/O exception has occurred.

#### save

    public void save(java.io.File file,
                     char separator)
              throws java.io.IOException

Writes the data to a CSV file.

Parameters:
  `file` - A file
  `separator` - The utilized separator character
Throws:
  `java.io.IOException` - Signals that an I/O exception has occurred.

#### save

    public void save(java.io.File file,
                     CSVSyntax config)
              throws java.io.IOException

Writes the data to a CSV file.

Parameters:
  `file` - the file
  `config` - the config
Throws:
  `java.io.IOException` - Signals that an I/O exception has occurred.

#### save

    public void save(java.io.OutputStream out)
              throws java.io.IOException

Writes the data to a CSV file.

Parameters:
  `out` - the out
Throws:
  `java.io.IOException` - Signals that an I/O exception has occurred.

#### save

    public void save(java.io.OutputStream out,
                     char separator)
              throws java.io.IOException

Writes the data to a CSV file.

Parameters:
  `out` - Output stream
  `separator` - The utilized separator character
Throws:
  `java.io.IOException` - Signals that an I/O exception has occurred.

#### save

    public void save(java.io.OutputStream out,
                     CSVSyntax config)
              throws java.io.IOException

Writes the data to a CSV file.

Parameters:
  `out` - the out
  `config` - the config
Throws:
  `java.io.IOException` - Signals that an I/O exception has occurred.

#### save

    public void save(java.lang.String path)
              throws java.io.IOException

Writes the data to a CSV file.

Parameters:
  `path` - the path
Throws:
  `java.io.IOException` - Signals that an I/O exception has occurred.

#### save

    public void save(java.lang.String path,
                     char separator)
              throws java.io.IOException

Writes the data to a CSV file.

Parameters:
  `path` - A path
  `separator` - The utilized separator character
Throws:
  `java.io.IOException` - Signals that an I/O exception has occurred.

#### save

    public void save(java.lang.String path,
                     CSVSyntax config)
              throws java.io.IOException

Writes the data to a CSV file.

Parameters:
  `path` - the path
  `config` - the config
Throws:
  `java.io.IOException` - Signals that an I/O exception has occurred.

#### sort

    public void sort(boolean ascending,
                     int... columns)

Sorts the dataset according to the given columns. Will sort input and output analogously.

Parameters:
  `ascending` - Sort ascending or descending
  `columns` - An integer array containing column indicides

#### sort

    public void sort(int from,
                     int to,
                     boolean ascending,
                     int... columns)

Sorts the dataset according to the given columns and the given range. Will sort input and output analogously.

Parameters:
  `from` - The lower bound
  `to` - The upper bound
  `ascending` - Sort ascending or descending
  `columns` - An integer array containing column indicides

#### sort

    public void sort(cern.colt.Swapper swapper,
                     boolean ascending,
                     int... columns)

Sorts the dataset according to the given columns. Will sort input and output analogously.

Parameters:
  `swapper` - A swapper
  `ascending` - Sort ascending or descending
  `columns` - An integer array containing column indicides

#### sort

    public void sort(cern.colt.Swapper swapper,
                     int from,
                     int to,
                     boolean ascending,
                     int... columns)

Sorts the dataset according to the given columns and the given range. Will sort input and output analogously.

Parameters:
  `swapper` - A swapper
  `from` - The lower bound
  `to` - The upper bound
  `ascending` - Sort ascending or descending
  `columns` - An integer array containing column indicides

#### swap

    public void swap(int row1,
                     int row2)

Swaps both rows.

Parameters:
  `row1` - the row1
  `row2` - the row2