/// <summary>
        /// Returns the set of events that have the same property value as the given event.
        /// </summary>
        /// <param name="keyStart">to compare against</param>
        /// <param name="keyEnd">to compare against</param>
        /// <param name="allowRangeReversal">indicate whether "a between 60 and 50" should return no results (equivalent to a&gt;= X and a &lt;=Y) or should return results (equivalent to 'between' and 'in'</param>
        /// <returns>set of events with property value, or null if none found (never returns zero-sized set)</returns>
        public override ISet <EventBean> LookupRange(object keyStart, bool includeStart, object keyEnd, bool includeEnd, bool allowRangeReversal)
        {
            if (keyStart == null || keyEnd == null)
            {
                return(EmptySet);
            }
            keyStart = Coerce(keyStart);
            keyEnd   = Coerce(keyEnd);
            IDictionary <object, ISet <EventBean> > submap;

            try {
                submap = _propertyIndex.Between(keyStart, includeStart, keyEnd, includeEnd);
            }
            catch (ArgumentException ex)
            {
                if (allowRangeReversal)
                {
                    submap = _propertyIndex.Between(keyEnd, includeStart, keyStart, includeEnd);
                }
                else
                {
                    return(EmptySet);
                }
            }
            return(Normalize(submap));
        }
Esempio n. 2
0
        public void LookupRange(
            ICollection <EventBean> result,
            OrderedDictionary <object, object> propertyIndex,
            object keyStart,
            bool includeStart,
            object keyEnd,
            bool includeEnd,
            bool allowRangeReversal,
            CompositeIndexQueryResultPostProcessor postProcessor)
        {
            if (keyStart == null || keyEnd == null)
            {
                return;
            }
            keyStart = Coerce(keyStart);
            keyEnd   = Coerce(keyEnd);
            IEnumerable <KeyValuePair <object, object> > submap;

            try
            {
                submap = propertyIndex.Between(keyStart, includeStart, keyEnd, includeEnd);
            }
            catch (ArgumentException)
            {
                if (allowRangeReversal)
                {
                    submap = propertyIndex.Between(keyEnd, includeStart, keyStart, includeEnd);
                }
                else
                {
                    return;
                }
            }
            Normalize(result, submap, postProcessor);
        }
        public static IDictionary <ContextStatePathKey, ContextStatePathValue> GetChildContexts(ContextControllerFactoryContext factoryContext, int pathId, OrderedDictionary <ContextStatePathKey, ContextStatePathValue> states)
        {
            ContextStatePathKey start = new ContextStatePathKey(factoryContext.NestingLevel, pathId, int.MinValue);
            ContextStatePathKey end   = new ContextStatePathKey(factoryContext.NestingLevel, pathId, int.MaxValue);

            return(states.Between(start, true, end, true));
        }
Esempio n. 4
0
        public void ShouldGetItemsBetween()
        {
            var orderedDictionary = new OrderedDictionary <string, int>();

            orderedDictionary["a"] = 1;
            orderedDictionary["c"] = 2;
            orderedDictionary["e"] = 3;
            orderedDictionary["b"] = 4;
            orderedDictionary["z"] = 5;
            orderedDictionary["q"] = 6;

            Assert.That(orderedDictionary.Keys.Count, Is.EqualTo(6));

            var subMap = orderedDictionary.Between("b", true, "q", true);

            Assert.That(subMap.Keys.Count, Is.EqualTo(4));
            Assert.That(string.Join(",", subMap.Keys), Is.EqualTo("b,c,e,q"));
            Assert.That(string.Join(",", subMap.Values), Is.EqualTo("4,2,3,6"));

            subMap = orderedDictionary.Between("b", true, "r", true);
            Assert.That(subMap.Keys.Count, Is.EqualTo(4));
            Assert.That(string.Join(",", subMap.Keys), Is.EqualTo("b,c,e,q"));
            Assert.That(string.Join(",", subMap.Values), Is.EqualTo("4,2,3,6"));

            subMap = orderedDictionary.Between("b", true, "q", false);
            Assert.That(subMap.Keys.Count, Is.EqualTo(3));
            Assert.That(string.Join(",", subMap.Keys), Is.EqualTo("b,c,e"));
            Assert.That(string.Join(",", subMap.Values), Is.EqualTo("4,2,3"));

            subMap = orderedDictionary.Between("b", true, "r", false);
            Assert.That(subMap.Keys.Count, Is.EqualTo(4));
            Assert.That(string.Join(",", subMap.Keys), Is.EqualTo("b,c,e,q"));
            Assert.That(string.Join(",", subMap.Values), Is.EqualTo("4,2,3,6"));

            subMap = orderedDictionary.Between("b", true, "zz", false);
            Assert.That(subMap.Keys.Count, Is.EqualTo(5));
            Assert.That(string.Join(",", subMap.Keys), Is.EqualTo("b,c,e,q,z"));
            Assert.That(string.Join(",", subMap.Values), Is.EqualTo("4,2,3,6,5"));

            subMap = orderedDictionary.Between("b", false, "q", true);
            Assert.That(subMap.Keys.Count, Is.EqualTo(3));
            Assert.That(string.Join(",", subMap.Keys), Is.EqualTo("c,e,q"));
            Assert.That(string.Join(",", subMap.Values), Is.EqualTo("2,3,6"));

            subMap = orderedDictionary.Between("a", false, "q", true);
            Assert.That(subMap.Keys.Count, Is.EqualTo(4));
            Assert.That(string.Join(",", subMap.Keys), Is.EqualTo("b,c,e,q"));
            Assert.That(string.Join(",", subMap.Values), Is.EqualTo("4,2,3,6"));

            subMap = orderedDictionary.Between("0", false, "q", true);
            Assert.That(subMap.Keys.Count, Is.EqualTo(5));
            Assert.That(string.Join(",", subMap.Keys), Is.EqualTo("a,b,c,e,q"));
            Assert.That(string.Join(",", subMap.Values), Is.EqualTo("1,4,2,3,6"));
        }