public void TestMatchLongAndGreaterEquals() { FilterParamIndexCompare index = MakeOne("LongBoxed", FilterOperator.GREATER_OR_EQUAL); index.Put(1L, _testEvaluator); index.Put(2L, _testEvaluator); index.Put(4L, _testEvaluator); // Should not match with null VerifyLongBoxed(index, null, 0); VerifyLongBoxed(index, 0L, 0); VerifyLongBoxed(index, 1L, 1); VerifyLongBoxed(index, 2L, 2); VerifyLongBoxed(index, 3L, 2); VerifyLongBoxed(index, 4L, 3); VerifyLongBoxed(index, 10L, 3); // Put a long primitive in - should work index.Put(9l, _testEvaluator); try { index.Put(10, _testEvaluator); Assert.IsTrue(false); } catch (InvalidOperationException ex) { Assert.That(ex.InnerException, Is.InstanceOf <ArgumentException>()); } }
public void TestMatchDoubleAndGreater() { FilterParamIndexCompare index = MakeOne("DoublePrimitive", FilterOperator.GREATER); index.Put(1.5, _testEvaluator); index.Put(2.1, _testEvaluator); index.Put(2.2, _testEvaluator); VerifyDoublePrimitive(index, 1.5, 0); VerifyDoublePrimitive(index, 1.7, 1); VerifyDoublePrimitive(index, 2.2, 2); VerifyDoublePrimitive(index, 2.1999999, 2); VerifyDoublePrimitive(index, -1, 0); VerifyDoublePrimitive(index, 99, 3); Assert.AreEqual(_testEvaluator, index.Get(1.5d)); Assert.IsTrue(index.ReadWriteLock != null); Assert.IsTrue(index.Remove(1.5d)); Assert.IsFalse(index.Remove(1.5d)); Assert.AreEqual(null, index.Get(1.5d)); try { index["a"] = _testEvaluator; Assert.IsTrue(false); } catch (InvalidOperationException ex) { Assert.That(ex.InnerException, Is.InstanceOf <ArgumentException>()); } }
public void TestMatchDoubleAndLessOrEqualThan() { FilterParamIndexCompare index = MakeOne("DoubleBoxed", FilterOperator.LESS_OR_EQUAL); index.Put(7.4D, _testEvaluator); index.Put(7.5D, _testEvaluator); index.Put(7.6D, _testEvaluator); VerifyDoubleBoxed(index, 7.39, 3); VerifyDoubleBoxed(index, 7.4, 3); VerifyDoubleBoxed(index, 7.41, 2); VerifyDoubleBoxed(index, 7.5, 2); VerifyDoubleBoxed(index, 7.51, 1); VerifyDoubleBoxed(index, 7.6, 1); VerifyDoubleBoxed(index, 7.61, 0); }
public void TestMatchLongAndLessThan() { FilterParamIndexCompare index = MakeOne("LongPrimitive", FilterOperator.LESS); index.Put(1L, _testEvaluator); index.Put(10L, _testEvaluator); index.Put(100L, _testEvaluator); VerifyLongPrimitive(index, 100, 0); VerifyLongPrimitive(index, 101, 0); VerifyLongPrimitive(index, 99, 1); VerifyLongPrimitive(index, 11, 1); VerifyLongPrimitive(index, 10, 1); VerifyLongPrimitive(index, 9, 2); VerifyLongPrimitive(index, 2, 2); VerifyLongPrimitive(index, 1, 2); VerifyLongPrimitive(index, 0, 3); }
/// <summary> /// Factory for indexes that store filter parameter constants for a given event property and filter operator. /// <para /> /// Does not perform any check of validity of property name. /// </summary> /// <param name="lookupable">The lookupable.</param> /// <param name="lockFactory">The lock factory.</param> /// <param name="filterOperator">is the type of index to use</param> /// <returns> /// the proper index based on the filter operator type /// </returns> /// <exception cref="System.ArgumentException">Cannot create filter index instance for filter operator + filterOperator</exception> public static FilterParamIndexBase CreateIndex(FilterSpecLookupable lookupable, FilterServiceGranularLockFactory lockFactory, FilterOperator filterOperator) { FilterParamIndexBase index; Type returnValueType = lookupable.ReturnType; // Handle all EQUAL comparisons if (filterOperator == FilterOperator.EQUAL) { index = new FilterParamIndexEquals(lookupable, lockFactory.ObtainNew()); return(index); } // Handle all NOT-EQUAL comparisons if (filterOperator == FilterOperator.NOT_EQUAL) { index = new FilterParamIndexNotEquals(lookupable, lockFactory.ObtainNew()); return(index); } if (filterOperator == FilterOperator.IS) { index = new FilterParamIndexEqualsIs(lookupable, lockFactory.ObtainNew()); return(index); } if (filterOperator == FilterOperator.IS_NOT) { index = new FilterParamIndexNotEqualsIs(lookupable, lockFactory.ObtainNew()); return(index); } // Handle all GREATER, LESS etc. comparisons if ((filterOperator == FilterOperator.GREATER) || (filterOperator == FilterOperator.GREATER_OR_EQUAL) || (filterOperator == FilterOperator.LESS) || (filterOperator == FilterOperator.LESS_OR_EQUAL)) { if (returnValueType != typeof(String)) { index = new FilterParamIndexCompare(lookupable, lockFactory.ObtainNew(), filterOperator); } else { index = new FilterParamIndexCompareString(lookupable, lockFactory.ObtainNew(), filterOperator); } return(index); } // Handle all normal and inverted RANGE comparisons if (filterOperator.IsRangeOperator()) { if (returnValueType != typeof(String)) { index = new FilterParamIndexDoubleRange(lookupable, lockFactory.ObtainNew(), filterOperator); } else { index = new FilterParamIndexStringRange(lookupable, lockFactory.ObtainNew(), filterOperator); } return(index); } if (filterOperator.IsInvertedRangeOperator()) { if (returnValueType != typeof(String)) { return(new FilterParamIndexDoubleRangeInverted(lookupable, lockFactory.ObtainNew(), filterOperator)); } else { return(new FilterParamIndexStringRangeInverted(lookupable, lockFactory.ObtainNew(), filterOperator)); } } // Handle all IN and NOT IN comparisons if (filterOperator == FilterOperator.IN_LIST_OF_VALUES) { return(new FilterParamIndexIn(lookupable, lockFactory.ObtainNew())); } if (filterOperator == FilterOperator.NOT_IN_LIST_OF_VALUES) { return(new FilterParamIndexNotIn(lookupable, lockFactory.ObtainNew())); } // Handle all bool expression if (filterOperator == FilterOperator.BOOLEAN_EXPRESSION) { return(new FilterParamIndexBooleanExpr(lockFactory.ObtainNew())); } throw new ArgumentException("Cannot create filter index instance for filter operator " + filterOperator); }
/// <summary> /// Factory for indexes that store filter parameter constants for a given event property and filter operator. /// <para /> /// Does not perform any check of validity of property name. /// </summary> /// <param name="lookupable">The lookupable.</param> /// <param name="lockFactory">The lock factory.</param> /// <param name="filterOperator">is the type of index to use</param> /// <returns> /// the proper index based on the filter operator type /// </returns> /// <exception cref="System.ArgumentException">Cannot create filter index instance for filter operator + filterOperator</exception> public static FilterParamIndexBase CreateIndex( FilterSpecLookupable lookupable, FilterServiceGranularLockFactory lockFactory, FilterOperator filterOperator) { FilterParamIndexBase index; Type returnValueType = lookupable.ReturnType; // Handle all EQUAL comparisons if (filterOperator == FilterOperator.EQUAL) { index = new FilterParamIndexEquals(lookupable, lockFactory.ObtainNew()); return(index); } // Handle all NOT-EQUAL comparisons if (filterOperator == FilterOperator.NOT_EQUAL) { index = new FilterParamIndexNotEquals(lookupable, lockFactory.ObtainNew()); return(index); } if (filterOperator == FilterOperator.IS) { index = new FilterParamIndexEqualsIs(lookupable, lockFactory.ObtainNew()); return(index); } if (filterOperator == FilterOperator.IS_NOT) { index = new FilterParamIndexNotEqualsIs(lookupable, lockFactory.ObtainNew()); return(index); } // Handle all GREATER, LESS etc. comparisons if ((filterOperator == FilterOperator.GREATER) || (filterOperator == FilterOperator.GREATER_OR_EQUAL) || (filterOperator == FilterOperator.LESS) || (filterOperator == FilterOperator.LESS_OR_EQUAL)) { if (returnValueType != typeof(String)) { index = new FilterParamIndexCompare(lookupable, lockFactory.ObtainNew(), filterOperator); } else { index = new FilterParamIndexCompareString(lookupable, lockFactory.ObtainNew(), filterOperator); } return(index); } // Handle all normal and inverted RANGE comparisons if (filterOperator.IsRangeOperator()) { if (returnValueType != typeof(String)) { index = new FilterParamIndexDoubleRange(lookupable, lockFactory.ObtainNew(), filterOperator); } else { index = new FilterParamIndexStringRange(lookupable, lockFactory.ObtainNew(), filterOperator); } return(index); } if (filterOperator.IsInvertedRangeOperator()) { if (returnValueType != typeof(String)) { return(new FilterParamIndexDoubleRangeInverted(lookupable, lockFactory.ObtainNew(), filterOperator)); } else { return(new FilterParamIndexStringRangeInverted(lookupable, lockFactory.ObtainNew(), filterOperator)); } } // Handle all IN and NOT IN comparisons if (filterOperator == FilterOperator.IN_LIST_OF_VALUES) { return(new FilterParamIndexIn(lookupable, lockFactory.ObtainNew())); } if (filterOperator == FilterOperator.NOT_IN_LIST_OF_VALUES) { return(new FilterParamIndexNotIn(lookupable, lockFactory.ObtainNew())); } // Handle all bool expression if (filterOperator == FilterOperator.BOOLEAN_EXPRESSION) { return(new FilterParamIndexBooleanExpr(lockFactory.ObtainNew())); } // Handle advanced-index if (filterOperator == FilterOperator.ADVANCED_INDEX) { FilterSpecLookupableAdvancedIndex advLookable = (FilterSpecLookupableAdvancedIndex)lookupable; if (advLookable.IndexType.Equals(EngineImportApplicationDotMethodPointInsideRectangle.INDEX_TYPE_NAME)) { return(new FilterParamIndexQuadTreePointRegion(lockFactory.ObtainNew(), lookupable)); } else if (advLookable.IndexType.Equals(EngineImportApplicationDotMethodRectangeIntersectsRectangle.INDEX_TYPE_NAME)) { return(new FilterParamIndexQuadTreeMXCIF(lockFactory.ObtainNew(), lookupable)); } else { throw new IllegalStateException("Unrecognized index type " + advLookable.IndexType); } } throw new ArgumentException("Cannot create filter index instance for filter operator " + filterOperator); }