Exemplo n.º 1
0
        /// <summary>Modify a row of data.</summary>
        /// <param name="row">The row to be modified.</param>
        /// <param name="x">  The data to be modified.  This should be an
        /// array of objects.  It is described as an Object
        /// here since other table implementations may
        /// use other methods to store the data (e.g.,</param>
        /// <seealso cref="">ColumnTable.getColumn.</seealso>
        public virtual void SetRow(int row, Object x)
        {
            if (ArrayFuncs.CountDimensions(x) != 1)           //!(x is Object[]))
            {
                throw new TableException("setRow: Incompatible row");
            }

            for (int col = 0; col < arrays.Length; col += 1)
            {
                SetElement(row, col, ((Array)x).GetValue(col));
            }
        }
Exemplo n.º 2
0
        /// <summary>Modify an element of the table.</summary>
        /// <param name="row">The row containing the element.</param>
        /// <param name="col">The column containing the element.</param>
        /// <param name="x">  The new datum.  This should be 1-d primitive array.</param>
        /// <exception cref=""> TableException Thrown when the new data
        /// is not of the same type as the data it replaces.</exception>
        public virtual void SetElement(int row, int col, Object x)
        {
            //String classname = x.GetType().FullName;

            //if(!classname.Equals("[" + types[col]))
            if (!(ArrayFuncs.CountDimensions(x) == 1 &&
                  bases[col].Equals(ArrayFuncs.GetBaseClass(x))))
            {
                throw new TableException("setElement: Incompatible element type");
            }

            if (((Array)x).Length != sizes[col])
            {
                throw new TableException("setElement: Incompatible element size");
            }

            Array.Copy((Array)x, 0, (Array)arrays[col], sizes[col] * row, sizes[col]);
        }
Exemplo n.º 3
0
        private int CheckColumnConsistency(Array data, int ratio, int size)
        {
            //if (classname[0] != '[' || classname.Length != 2)
            if (ArrayFuncs.CountDimensions(data) != 1 || !ArrayFuncs.GetBaseClass(data).IsPrimitive)
            {
                throw new TableException("Non-primitive array for column");
            }

            int thisSize = data.Length;

            // suggested in .99.2 version: change
            if (thisSize == 0 && size != 0 && ratio != 0 || thisSize != 0 && size == 0)
            {
                throw new TableException("Size mismatch in column");
            }

            // The row size must evenly divide the size of the array.
            if (size != 0 && thisSize % size != 0)
            {
                throw new TableException("Row size does not divide array for column");
            }

            // Finally the ratio of sizes must be the same for all columns -- this
            // is the number of rows in the table.
            int thisRatio = 0;

            if (size > 0)
            {
                thisRatio = thisSize / size;

                if (ratio != 0 && (thisRatio != ratio))
                {
                    throw new TableException("Different number of rows in different columns");
                }
            }
            if (thisRatio > 0)
            {
                return(thisRatio);
            }
            else
            {
                return(ratio);
            }
        }