Beispiel #1
0
        /// <summary>
        ///     Find an index that matches one of the filter parameters passed.
        ///     The parameter type and index type match up if the property name and
        ///     filter operator are the same for the index and the filter parameter.
        ///     For instance, for a filter parameter of "count EQUALS 10", the index against property "count" with
        ///     operator type EQUALS will be returned, if present.
        ///     NOTE: The caller is expected to obtain locks, if necessary, on the collections passed in.
        ///     NOTE: Doesn't match non-property based index - thus bool expressions don't get found and are always entered as a
        ///     new index
        /// </summary>
        /// <param name="parameters">is the list of sorted filter parameters</param>
        /// <param name="indizes">is the collection of indexes</param>
        /// <returns>
        ///     A matching pair of filter parameter and index, if any matches were found. Null if no matches were found.
        /// </returns>
        public static Pair<FilterValueSetParam, FilterParamIndexBase> FindIndex(
            ICollection<FilterValueSetParam> parameters,
            IList<FilterParamIndexBase> indizes)
        {
            foreach (FilterValueSetParam parameter in parameters)
            {
                FilterSpecLookupable lookupable = parameter.Lookupable;
                FilterOperator @operator = parameter.FilterOperator;

                foreach (FilterParamIndexBase index in indizes)
                {
                    // if property-based index, we prefer this in matching
                    if (index is FilterParamIndexLookupableBase)
                    {
                        var propBasedIndex = (FilterParamIndexLookupableBase) index;
                        if ((lookupable.Equals(propBasedIndex.Lookupable)) &&
                            (@operator.Equals(propBasedIndex.FilterOperator)))
                        {
                            return new Pair<FilterValueSetParam, FilterParamIndexBase>(parameter, index);
                        }
                    }
                    else if (index is FilterParamIndexBooleanExpr && parameters.Count == 1)
                    {
                        // if bool-expression then match only if this is the last parameter,
                        // all others considered are higher order and sort ahead
                        if (@operator.Equals(FilterOperator.BOOLEAN_EXPRESSION))
                        {
                            return new Pair<FilterValueSetParam, FilterParamIndexBase>(parameter, index);
                        }
                    }
                }
            }

            return null;
        }
Beispiel #2
0
        /// <summary>
        ///     Determine among the passed in filter parameters any parameter that matches the given index on property name and
        ///     filter operator type. Returns null if none of the parameters matches the index.
        /// </summary>
        /// <param name="parameters">is the filter parameter list</param>
        /// <param name="index">is a filter parameter constant value index</param>
        /// <returns>filter parameter, or null if no matching parameter found.</returns>
        public static FilterValueSetParam FindParameter(
            ICollection<FilterValueSetParam> parameters,
            FilterParamIndexBase index)
        {
            if (index is FilterParamIndexLookupableBase)
            {
                var propBasedIndex = (FilterParamIndexLookupableBase) index;
                FilterSpecLookupable indexLookupable = propBasedIndex.Lookupable;
                FilterOperator indexOperator = propBasedIndex.FilterOperator;

                foreach (FilterValueSetParam parameter in parameters)
                {
                    FilterSpecLookupable lookupable = parameter.Lookupable;
                    FilterOperator paramOperator = parameter.FilterOperator;

                    if ((lookupable.Equals(indexLookupable)) &&
                        (paramOperator.Equals(indexOperator)))
                    {
                        return parameter;
                    }
                }
            }
            else
            {
                foreach (FilterValueSetParam parameter in parameters)
                {
                    FilterOperator paramOperator = parameter.FilterOperator;

                    if (paramOperator.Equals(index.FilterOperator))
                    {
                        return parameter;
                    }
                }
            }

            return null;
        }