if (getRowCount() == 0 || getProperties().length == 0 || filter == null) return null;
String[] filterPropertyIds = filter.getPropertyIds();
if (filterPropertyIds.length == 0) return null;
// Create a target filter containing only those properties belonging to this dataset.
FilterByCriteria targetFilter = filter.cloneFilter();
String[] remainingPropIds = filter.getPropertyIds();
for (String propId : remainingPropIds) {
if (getPropertyById(propId) == null) {
targetFilter.removeProperty(propId);
}
}
// Go ahead only if the target filter contains at least one property.
if (targetFilter.getPropertyIds().length == 0) {
return null;
}
// Add filter constraints to the current thread.
ProfilerHelper.addRuntimeConstraint(new DataSetFilterConstraints(this));
// Create the result data set instance.
DefaultDataSet _result = new DefaultDataSet(provider);
_result.setPropertySize(propertyValues.length);
for (int j=0; j<propertyValues.length; j++) {
DataProperty dataProp = getPropertyByColumn(j);
DataProperty _prop = dataProp.cloneProperty();
_result.addProperty(_prop, j);
}
// Get only the subset of rows to be analyzed.
Set<Integer> targetRows = preProcessFilter(targetFilter);
if (targetRows.isEmpty() && targetFilter.getPropertyIds().length == 0) {
// Return an empty data set if there is no more criteria to filter for.
return _result;
}
// Filter the target rows and build the results matrix.
Iterator<Integer> _rowIt = targetRows.iterator();
Map _rowMap = new HashMap();
Object[] _rowArray = new Object[propertyValues.length];
boolean _continue = true;
int _index = 0;
int _row = 0;
int _nrows = 0;
while (_continue) {
// Iterate against the target rows or over the whole data set.
if (!targetRows.isEmpty()) _row = _rowIt.next();
else _row = _index++;
// If all properties has been processed then no additional filter is required.
if (targetFilter.getPropertyIds().length == 0) {
fillArrayWithRow(_row, _rowArray);
_result.addRowValues(_rowArray);
}
// Else, check every target row with the target filter.
else {
fillMapWithRow(_row, _rowMap);
if (targetFilter.pass(_rowMap)) {
fillArrayWithRow(_row, _rowArray);
_result.addRowValues(_rowArray);
}
}
// Check filter constraints (every 1000 rows)