package com.brilliance.mda.runtime.mda.impl;

import com.brilliance.mda.runtime.mda.IAttributeValue;
import com.brilliance.mda.runtime.mda.IDatafield;
import com.brilliance.mda.runtime.mda.IValue;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Description
 * @Author s_guodong
 * @Date 2022/11/15
 */
public class StreamGrid extends ArrayList<IValue[]> {
    static IAttributeValue[] EMPTY = new IAttributeValue[0];

    IAttributeValue[] headers;

    List<IAttributeValue[]> extHeaders;

    int index = -1;

    IDatafield datafield;

    public IAttributeValue[] getHeaders() {
        if (this.headers == null)
            return EMPTY;
        return this.headers;
    }

    public void setHeaders(IAttributeValue[] headers) {
        this.headers = headers;
    }

    public List<IAttributeValue[]> getExtHeaders() {
        if (this.extHeaders == null)
            return Collections.EMPTY_LIST;
        return this.extHeaders;
    }

    public void setExtHeaders(List<IAttributeValue[]> extHeaders) {
        this.extHeaders = extHeaders;
    }

    public int getIndex() {
        if (this.index >= size())
            setIndex(-1);
        return this.index;
    }

    public void setIndex(int index) {
        if (index >= size() || index < 0)
            index = -1;
        this.index = index;
    }

    public IDatafield getDatafield() {
        return this.datafield;
    }

    public void setDatafield(IDatafield datafield) {
        this.datafield = datafield;
    }

    public void clear() {
        this.datafield = null;
        this.index = -1;
        super.clear();
    }
}
