package org.das2.qds; import java.util.Map; /** * pull out a subset of the dataset by reducing the number of columns in the * last dimension. This does not reduce rank. This assumes the dataset has no * row with length>end. * * @author jbf */ public class LeafTrimDataSet extends AbstractDataSet { final QDataSet ds; final int start; final int end; /** * @param source the rank 1 or greater dataset to back this dataset. * @param start first index to include. * @param end last index, exclusive */ public LeafTrimDataSet( QDataSet source, int start, int end ) { if ( source.rank()==0 ) { throw new IllegalArgumentException( "source is rank 0"); } this.ds= source; this.start= start; this.end= end; int len= 0; if ( ds.rank()==1 ) { len= ds.length(); } else if ( ds.rank()==2 ) { len= ds.length(0); } else if ( ds.rank()==3 ) { len= ds.length(0,0); } else if ( ds.rank()==4 ) { len= ds.length(0,0,0); } else { throw new IllegalArgumentException("rank exception"); // TODO: consider return the dataset for rank 0. } if ( end>len ) { throw new IndexOutOfBoundsException("end is greater than last dimension length"); } if ( start<0 ) { throw new IndexOutOfBoundsException("start is less than 0"); } if ( start>end ) { throw new IndexOutOfBoundsException("start is greater than end"); } String depNName = "DEPEND_" + (ds.rank() - 1); QDataSet depN = (QDataSet) ds.property(depNName); if (depN != null) { if ( depN.rank()==2 ) { depN = new LeafTrimDataSet(depN, start, end); properties.put(depNName, depN); } else { depN= depN.trim(start, end); properties.put(depNName, depN); } } String bundleNName = "BUNDLE_" + (ds.rank() - 1); QDataSet bds = (QDataSet) ds.property(bundleNName); if ( bds != null) { bds = bds.trim( start, end ); properties.put( bundleNName, bds ); } for ( int i=0; i ps= DataSetOps.sliceProperties0(i,DataSetUtil.getProperties(this)); ps= DataSetUtil.sliceProperties( ds, i, ps ); DataSetUtil.putProperties( ps, result ); return result; } } @Override public QDataSet trim(int start, int end) { if ( this.rank()==1 ) { return ds.trim( this.start+start, this.start+end ); } else { LeafTrimDataSet result= new LeafTrimDataSet( ds.trim(start, end), this.start, this.end ); for ( int i=1; i