using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;

using CategoryTheory;
using DiagramUI;
using FormulaEditor;
using GeneralLinearMethod;
using AnalyticPolynom;


namespace DataPerformer
{
    /// <summary>
    /// Array selection
    /// </summary>
    public class ArraySelection : IMeasure, IStructuredSelection
    {

        #region Fields

        private ArrayReturnType type;
        protected string name = "";
        protected double[] data;

        private MeasureParameter p;

        #endregion

        #region Constructors

        public ArraySelection(string name, double[] data)
        {
            p = new MeasureParameter(parameter);
            this.name = name + "";
            Array = data;
        }

        #endregion

        #region IMeasure Members

        public MeasureParameter Parameter
        {
            get
            {
                return p;
            }
        }

        public MeasureParameter Derivation
        {
            get
            {
                return null;
            }
        }

        public string Name
        {
            get
            {
                return name;
            }
        }

        public double Factor
        {
            get
            {
                return 1;
            }
        }

        public object Type
        {
            get
            {
                return type;
            }
        }

        #endregion

        #region IStructuredSelection Members

        public bool HasFixedAmount
        {
            get
            {
                return true;
            }
        }

        public double? this[int n]
        {
            get
            {
                return data[n];
            }
        }

        public int GetTolerance(int n)
        {
            return 0;
        }

        public void SetTolerance(int n, int tolerance)
        {
        }

        public double GetWeight(int n)
        {
            return 1;
        }

        public int DataDimension
        {
            get
            {
                return data.Length;
            }
        }

        public double GetApriorWeight(int n)
        {
            return 0;
        }

        #endregion

        #region Specific Members

        public double[] Array
        {
            set
            {
                Double a = 0;
                data = new double[value.Length];
                type = new ArrayReturnType(a, new int[]{value.Length});
                for (int i = 0; i < value.Length; i++)
                {
                    data[i] = value[i];
                    //type[i] = 0;
                }
            }
        }

        public string MeasureName
        {
            set
            {
                name = value;
            }
        }

        private object parameter()
        {
            return data;
        }

        #endregion
    }
}
