

package org.dcm4cheri.data;

import org.dcm4che.dict.VRs;
import org.dcm4che.data.*;

/**
 *
 * @author  gunter.zeilinger@tiani.com
 * @version 1.0.0
 */
class FilterSQElement extends DcmElementImpl {
    
    private final SQElement sqElem;
    private final Dataset filter;
    private int totlen = -1;

    /** Creates a new instance of ElementImpl */
    public FilterSQElement(SQElement sqElem, Dataset filter) {
        super(sqElem.tag());
        this.sqElem = sqElem;
        this.filter = filter;
    }
    
    public final int vr() {
        return VRs.SQ;
    }

    public final int vm(SpecificCharacterSet cs) {
        return sqElem.vm(cs);
    }
    
    public final int countItems() {
        return sqElem.countItems();
    }
    
    public Dataset getItem(int index) {
        return new FilterDataset.Selection(sqElem.getItem(index), filter);
    }
    
    public int calcLength(DcmEncodeParam param) {
        totlen = param.undefSeqLen ? 8 : 0;
        for (int i = 0, n = countItems(); i < n; ++i)
            totlen += getItem(i).calcLength(param) +
                    (param.undefItemLen ? 16 : 8);
        return totlen;
    }
    
    public int length() {
        return totlen;
    }  
    
    public String toString() {
    	return "FilterSQElement["+sqElem.toString()+"]";
    }
}
