@Override public DataTable sample(int newSize){
  int rowCount=getRowNumber();
  if (rowCount <= newSize) {
    return this;
  }
  int[] sampledSelectedIndices=new int[rowCount];
  for (int i=0; i < rowCount; ++i) {
    sampledSelectedIndices[i]=i;
  }
  Random rng=new Random(0);
  int swapIdx;
  int tmpValue;
  for (int i=0; i < rowCount; ++i) {
    swapIdx=rng.nextInt(rowCount);
    tmpValue=sampledSelectedIndices[swapIdx];
    sampledSelectedIndices[swapIdx]=sampledSelectedIndices[i];
    sampledSelectedIndices[i]=tmpValue;
  }
  DataTableView sampledDataTable=new DataTableView(this);
  Vector<Integer> sampledSelectedIndicesVector=new Vector<Integer>(newSize);
  for (int i=0; i < newSize; ++i) {
    sampledSelectedIndicesVector.add(sampledSelectedIndices[i]);
  }
  sampledDataTable.setSelectedIndices(sampledSelectedIndicesVector);
  return sampledDataTable;
}

@ Override public DataTable sample ( int newSize ) { int rowCount = getRowNumber ( ) ; if ( rowCount <= newSize ) { return this ; } int [ ] sampledSelectedIndices = new int [ rowCount ] ; for ( int i = 0 ; i < rowCount ; ++ i ) { sampledSelectedIndices [ i ] = i ; } Random rng = new Random ( 0 ) ; int swapIdx ; int tmpValue ; for ( int i = 0 ; i < rowCount ; ++ i ) { swapIdx = rng . nextInt ( rowCount ) ; tmpValue = sampledSelectedIndices [ swapIdx ] ; sampledSelectedIndices [ swapIdx ] = sampledSelectedIndices [ i ] ; sampledSelectedIndices [ i ] = tmpValue ; } DataTableView sampledDataTable = new DataTableView ( this ) ; Vector < Integer > sampledSelectedIndicesVector = new Vector < Integer > ( newSize ) ; for ( int i = 0 ; i < newSize ; ++ i ) { sampledSelectedIndicesVector . add ( sampledSelectedIndices [ i ] ) ; } sampledDataTable . setSelectedIndices ( sampledSelectedIndicesVector ) ; return sampledDataTable ; }
performs a simple sampling without replacement . if newsize is greater than the size of this datatableview , this datatableview is returned . creates a view onto this datatableview ( i . e . the this datatableview won ' t get garbage collected as long as the sampled datatableview is around . )
