Пример #1
0
        // Map HGrid to HHisItem[].  Grid must have ts and val columns.
        public static HHisItem[] gridToItems(HGrid grid)
        {
            HCol ts  = grid.col("ts");
            HCol val = grid.col("val");

            HHisItem[] items = new HHisItem[grid.numRows];
            for (int i = 0; i < items.Length; ++i)
            {
                HRow row = grid.row(i);
                // Timestamp can't be NULL but val can
                items[i] = new HHisItem((HDateTime)row.get(ts, true), row.get(val, false));
            }
            return(items);
        }
Пример #2
0
        // Get a cell by column.  If cell is null then raise
        //    UnknownNameException or return  null based on checked flag.
        public HVal get(HCol col, bool bchecked)
        {
            HVal val = m_cells[col.Index];

            if (val != null)
            {
                return(val);
            }
            // Ian Davies - .NET port - this could cause a unknown name exception
            //              for a null value - back to previous comment
            if (bchecked)
            {
                throw new UnknownNameException(col.Name);
            }
            return(null);
        }
Пример #3
0
        public override string getKeyAt(int iIndex, bool bChecked)
        {
            string strRet = null;

            if (iIndex < Size)
            {
                HCol col = Grid.col(iIndex);
                strRet = col.Name;
            }
            if ((strRet != null) || (!bChecked))
            {
                return(strRet);
            }
            else
            {
                throw new IndexOutOfRangeException(iIndex.ToString() + " out of range");
            }
        }
Пример #4
0
        // Get a cell by column name.  If the column is undefined or
        //    the cell is null then raise UnknownNameException or return
        //    null based on checked flag.
        public override HVal get(string name, bool bchecked)
        {
            HCol col = Grid.col(name, false);

            if (col != null)
            {
                HVal val = get(col, bchecked);
                if (val != null)
                {
                    return(val);
                }
            }
            if (bchecked)
            {
                throw new UnknownNameException(name);
            }
            return(null);
        }
Пример #5
0
        // Get a column by name.  If not found and checked if false then
        //    return null, otherwise throw UnknownNameException
        public HCol col(string name, bool bchecked)
        {
            HCol colRet = null;

            if (m_colsByName.ContainsKey(name))
            {
                colRet = m_colsByName[name];
            }
            if (colRet != null)
            {
                return(colRet);
            }
            if (bchecked)
            {
                throw new UnknownNameException(name);
            }
            return(null);
        }
Пример #6
0
 public static HaystackColumn Map(HCol value)
 {
     return(value.Source);
 }
Пример #7
0
        // Convenience to build grid from array of HDict.
        //    Any null entry will be row of all null cells.
        public static HGrid dictsToGrid(HDict meta, HDict[] dicts)
        {
            HCol colEmpty = new HCol(0, "empty", HDict.Empty);

            // If empty return an empty cols collection and no values Grid
            if (dicts.Length == 0)
            {
                List <List <HVal> > rowListEmpty = new List <List <HVal> >();
                List <HCol>         rowEmpty     = new List <HCol>();
                rowEmpty.Add(colEmpty);
                return(new HGrid(meta, rowEmpty, rowListEmpty));
            }

            HGridBuilder b = new HGridBuilder();

            b.Meta.add(meta);

            // collect column names - why does this need to be a dictionary (hashmap in the java code)?
            //      it only stores the col name twice.
            Dictionary <string, string> colsByName = new Dictionary <string, string>();

            for (int i = 0; i < dicts.Length; ++i)
            {
                HDict dict = dicts[i];
                if (dict != null)
                {
                    for (int it = 0; it < dict.size(); it++)
                    {
                        string name = dict.getKeyAt(it, false);
                        if (name != null)
                        {
                            if (!colsByName.Keys.Contains(name))
                            {
                                colsByName.Add(name, name);
                                b.addCol(name);
                            }
                        }
                    }
                }
            }

            // if all dicts were null, handle special case
            // by creating a dummy column
            if (colsByName.Count == 0)
            {
                colsByName.Add("empty", "empty");
                b.addCol("empty");
            }

            // now map rows
            int numCols = b.colCount;

            for (int ri = 0; ri < dicts.Length; ++ri)
            {
                HDict  dict  = dicts[ri];
                HVal[] cells = new HVal[numCols];
                for (int ci = 0; ci < numCols; ++ci)
                {
                    if (dict == null)
                    {
                        cells[ci] = null;
                    }
                    else
                    {
                        BCol colatci = b.GetColAt(ci);
                        if (colatci != null)
                        {
                            cells[ci] = dict.get(colatci.Name, false);
                        }
                    }
                }
                b.addRow(cells);
            }

            return(b.toGrid());
        }