示例#1
0
            public override bool include(HDict dict, IPather pather)
            {
                HVal val = dict.get(m_path.get(0), false);

                if (m_path.size() != 1)
                {
                    HDict nt = dict;
                    for (int i = 1; i < m_path.size(); i++)
                    {
                        if (!(val is HRef))
                        {
                            val = null;
                            break;
                        }
                        nt = pather.find(((HRef)val).ToString());
                        if (nt == null)
                        {
                            val = null;
                            break;
                        }
                        val = nt.get(m_path.get(i), false);
                    }
                }
                return(doInclude(val));
            }
示例#2
0
 public override bool doInclude(HVal v)
 {
     // Problem here is same type checks for null but this does not
     //   here .NET on the compareto throws an exception (null reference)
     //  Added check for v == null
     return(v != null && sameType(v) && v.CompareTo(m_val) >= 0);
 }
示例#3
0
 // Construct from timestamp, value
 public static HHisItem make(HDateTime ts, HVal val)
 {
     if (ts == null || val == null)
     {
         throw new ArgumentException("ts or val is null");
     }
     return(new HHisItem(ts, val));
 }
        /**
         * Parse from string using the given timezone as context for
         * date based ranges.  The formats are:
         *  - "today"
         *  - "yesterday"
         *  - "{date}"
         *  - "{date},{date}"
         *  - "{dateTime},{dateTime}"
         *  - "{dateTime}"  // anything after given timestamp
         * Throw ParseException is invalid string format.
         */
        public static HDateTimeRange make(string str, HTimeZone tz)
        {
            // handle keywords
            str = str.Trim();
            if (str.CompareTo("today") == 0)
            {
                return(make(HDate.today(), tz));
            }
            if (str.CompareTo("yesterday") == 0)
            {
                return(make(HDate.today().minusDays(1), tz));
            }

            // parse scalars
            int  comma = str.IndexOf(',');
            HVal start = null, end = null;

            if (comma < 0)
            {
                start = new HZincReader(str).readVal();
            }
            else
            {
                start = new HZincReader(str.Substring(0, comma)).readVal();
                end   = new HZincReader(str.Substring(comma + 1)).readVal();
            }

            // figure out what we parsed for start,end
            if (start is HDate)
            {
                if (end == null)
                {
                    return(make((HDate)start, tz));
                }
                if (end is HDate)
                {
                    return(make((HDate)start, (HDate)end, tz));
                }
            }
            else if (start is HDateTime)
            {
                if (end == null)
                {
                    return(make((HDateTime)start, HDateTime.now(tz)));
                }
                if (end is HDateTime)
                {
                    return(make((HDateTime)start, (HDateTime)end));
                }
            }

            throw new FormatException("Invalid HDateTimeRange: " + str);
        }
 // Add tag name and value.  Return this.
 public HDictBuilder add(string name, HVal val)
 {
     if (!HDict.isTagName(name))
     {
         throw new InvalidOperationException("Invalid tag name: " + name);
     }
     if (m_map == null)
     {
         m_map = new Dictionary <string, HVal>();
     }
     m_map.Add(name, val);
     return(this);
 }
示例#6
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);
        }
示例#7
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);
        }
示例#8
0
            public bool sameType(HVal v)
            {
                Type refClass  = m_val.GetType();
                Type testClass = v.GetType();

                if (v == null)
                {
                    return(false);
                }
                if (refClass == testClass)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        // Get a tag by name.  If not found and checked if false then
        //    return null, otherwise throw UnknownNameException
        public HVal get(string name, bool bchecked)
        {
            HVal val = null;

            if (m_map.ContainsKey(name))
            {
                val = m_map[name];
            }
            if (val != null)
            {
                return(val);
            }
            if (!bchecked)
            {
                return(null);
            }
            throw new UnknownNameException(name);
        }
示例#10
0
        //////////////////////////////////////////////////////////////////////////
        // Utils
        //////////////////////////////////////////////////////////////////////////

        // Convenience to build one row grid from HDict.
        public static HGrid dictToGrid(HDict dict)
        {
            HGridBuilder b      = new HGridBuilder();
            int          iIndex = 0;
            List <HVal>  cells  = new List <HVal>();

            for (iIndex = 0; iIndex < dict.size(); iIndex++)
            {
                string strKey = dict.getKeyAt(iIndex, false);
                if (strKey != null)
                {
                    HVal val = dict.get(strKey);
                    b.addCol(strKey);
                    cells.Add(val);
                }
            }
            b.addRow(cells.ToArray());
            return(b.toGrid());
        }
示例#11
0
            private HVal val()
            {
                if (m_tokCur.Literal)
                {
                    HVal val = (HVal)m_curVal;
                    consume();
                    return(val);
                }

                if (m_tokCur == HaystackToken.id)
                {
                    // NOTE: once again we are assuming m_curVal is a string
                    if ("true".Equals(m_curVal))
                    {
                        consume(); return(HBool.TRUE);
                    }
                    if ("false".Equals(m_curVal))
                    {
                        consume(); return(HBool.FALSE);
                    }
                }

                throw err("Expecting value literal, not " + curToStr());
            }
示例#12
0
        }                                // size is two - timestamp and value

        // Private constructor
        private HHisItem(HDateTime ts, HVal val) : base(new Dictionary <string, HVal>(11))
        {
            TimeStamp = ts;
            hsVal     = val;
        }
 public static HHisItem make(HDateTime ts, HVal val) => M.Map(new HaystackHistoryItem(M.Map(ts), M.Map(val)));
示例#14
0
 public abstract bool doInclude(HVal val);
示例#15
0
 public static HaystackValue Map(HVal value)
 {
     if (value == null)
     {
         return(null);
     }
     if (value is HBin bin)
     {
         return(bin.Source);
     }
     if (value is HBool @bool)
     {
         return(@bool.Source);
     }
     if (value is HCoord coord)
     {
         return(coord.Source);
     }
     if (value is HDate date)
     {
         return(date.Source);
     }
     if (value is HDateTime dateTime)
     {
         return(dateTime.Source);
     }
     if (value is HDef def)
     {
         return(def.Source);
     }
     if (value is HDict dict)
     {
         return(dict.Source);
     }
     if (value is HGrid grid)
     {
         return(grid.Source);
     }
     if (value is HHisItem hisItem)
     {
         return(hisItem.Source);
     }
     if (value is HList list)
     {
         return(list.Source);
     }
     if (value is HMarker marker)
     {
         return(marker.Source);
     }
     if (value is HNA na)
     {
         return(na.Source);
     }
     if (value is HNum num)
     {
         return(num.Source);
     }
     if (value is HRef @ref)
     {
         return(@ref.Source);
     }
     if (value is HRemove remove)
     {
         return(remove.Source);
     }
     if (value is HRow row)
     {
         return(row.Source);
     }
     if (value is HStr str)
     {
         return(str.Source);
     }
     if (value is HTime time)
     {
         return(time.Source);
     }
     if (value is HUri uri)
     {
         return(uri.Source);
     }
     if (value is HXStr xstr)
     {
         return(xstr.Source);
     }
     throw new InvalidOperationException($"Cannot map value of type {value.GetType().Name}");
 }
示例#16
0
 public CmpFilter(Path p, HVal val) : base(p)
 {
     m_path = p;
     m_val  = val;
 }
示例#17
0
 public override bool doInclude(HVal v)
 {
     return(v == null);
 }
示例#18
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());
        }
示例#19
0
 public override bool doInclude(HVal v)
 {
     return(v != null && !v.hequals(m_val));
 }
示例#20
0
 public override void Add(string key, HVal value) => Source.Add(key, M.Map(value));
示例#21
0
 /**
  * Match records which have tags less than the specified value.
  * If the path is not defined then it is unmatched.
  */
 public static HFilter lt(string path, HVal val)
 {
     return(new Lt(Path.make(path), val));
 }
示例#22
0
 /**
  * Match records which have a tag not equal to the specified value.
  * If the path is not defined then it is unmatched.
  */
 public static HFilter ne(string path, HVal val)
 {
     return(new Ne(Path.make(path), val));
 }
示例#23
0
 public Ge(Path p, HVal v) : base(p, v)
 {
     m_path = p;
     m_val  = v;
 }
示例#24
0
 /**
  * Match records which have a tag are equal to the specified value.
  * If the path is not defined then it is unmatched.
  */
 public static HFilter eq(string path, HVal val)
 {
     return(new Eq(Path.make(path), val));
 }