/// <summary> /// Returns a portion of the list whose keys are greater that the lowerLimit parameter less than the upperLimit parameter. /// </summary> /// <param name="list">The list where the portion will be extracted.</param> /// <param name="lowerLimit">The start element of the portion to extract.</param> /// <param name="upperLimit">The end element of the portion to extract.</param> /// <returns>The portion of the collection.</returns> public static System.Collections.SortedList SubMap(System.Collections.SortedList list, object lowerLimit, object upperLimit) { System.Collections.Comparer comparer = System.Collections.Comparer.Default; System.Collections.SortedList newList = new System.Collections.SortedList(); if (list != null) { if ((list.Count > 0) && (!(lowerLimit.Equals(upperLimit)))) { int index = 0; while (comparer.Compare(list.GetKey(index), lowerLimit) < 0) { index++; } for (; index < list.Count; index++) { if (comparer.Compare(list.GetKey(index), upperLimit) >= 0) { break; } newList.Add(list.GetKey(index), list[list.GetKey(index)]); } } } return(newList); }
public override bool Next() { if (termEnum == null) { return(false); } // another term in this field? if (termEnum.Next() && (System.Object)termEnum.Term().Field() == (System.Object)field) { return(true); // yes, keep going } termEnum.Close(); // close old termEnum // find the next field with terms, if any if (fieldIterator == null) { System.Collections.Comparer comparer = System.Collections.Comparer.Default; System.Collections.SortedList newList = new System.Collections.SortedList(); if (Enclosing_Instance.fieldToReader != null) { if (Enclosing_Instance.fieldToReader.Count > 0) { int index = 0; while (comparer.Compare(Enclosing_Instance.fieldToReader.GetKey(index), field) < 0) { index++; } for (; index < Enclosing_Instance.fieldToReader.Count; index++) { newList.Add(Enclosing_Instance.fieldToReader.GetKey(index), Enclosing_Instance.fieldToReader[Enclosing_Instance.fieldToReader.GetKey(index)]); } } } fieldIterator = newList.Keys.GetEnumerator(); fieldIterator.MoveNext(); System.Object generatedAux = fieldIterator.Current; // Skip field to get next one } while (fieldIterator.MoveNext()) { field = ((System.String)fieldIterator.Current); termEnum = ((IndexReader)Enclosing_Instance.fieldToReader[field]).Terms(new Term(field)); Term term = termEnum.Term(); if (term != null && (System.Object)term.Field() == (System.Object)field) { return(true); } else { termEnum.Close(); } } return(false); // no more fields }
/// <summary> /// Compares the specified values using specified relational operator. /// </summary> /// <param name="leftValue">The first value.</param> /// <param name="rightValue">The second value.</param> /// <param name="relationalOperator">The relational operator.</param> /// <returns>Result of the given relational operator.</returns> private static object Compare(object leftValue, object rightValue, ConditionRelationalOperator relationalOperator) { #if !NETSTANDARD1_0 StringComparer comparer = StringComparer.InvariantCulture; #else var comparer = new System.Collections.Comparer(CultureInfo.InvariantCulture); #endif PromoteTypes(ref leftValue, ref rightValue); switch (relationalOperator) { case ConditionRelationalOperator.Equal: return(comparer.Compare(leftValue, rightValue) == 0); case ConditionRelationalOperator.NotEqual: return(comparer.Compare(leftValue, rightValue) != 0); case ConditionRelationalOperator.Greater: return(comparer.Compare(leftValue, rightValue) > 0); case ConditionRelationalOperator.GreaterOrEqual: return(comparer.Compare(leftValue, rightValue) >= 0); case ConditionRelationalOperator.LessOrEqual: return(comparer.Compare(leftValue, rightValue) <= 0); case ConditionRelationalOperator.Less: return(comparer.Compare(leftValue, rightValue) < 0); default: throw new NotSupportedException($"Relational operator {relationalOperator} is not supported."); } }
/// <summary> /// Returns a portion of the list whose keys are less than the limit object parameter. /// </summary> /// <param name="l">The list where the portion will be extracted.</param> /// <param name="limit">The end element of the portion to extract.</param> /// <returns>The portion of the collection whose elements are less than the limit object parameter.</returns> public static System.Collections.SortedList HeadMap(System.Collections.SortedList l, object limit) { System.Collections.Comparer comparer = System.Collections.Comparer.Default; System.Collections.SortedList newList = new System.Collections.SortedList(); for (int i = 0; i < l.Count; i++) { if (comparer.Compare(l.GetKey(i), limit) >= 0) { break; } newList.Add(l.GetKey(i), l[l.GetKey(i)]); } return(newList); }
/// <summary> /// Returns a portion of the list whose keys are greater than the limit object parameter. /// </summary> /// <param name="list">The list where the portion will be extracted.</param> /// <param name="limit">The start element of the portion to extract.</param> /// <returns>The portion of the collection whose elements are greater than the limit object parameter.</returns> public static System.Collections.SortedList TailMap(System.Collections.SortedList list, object limit) { System.Collections.Comparer comparer = System.Collections.Comparer.Default; System.Collections.SortedList newList = new System.Collections.SortedList(); if (list != null) { if (list.Count > 0) { int index = 0; while (comparer.Compare(list.GetKey(index), limit) < 0) { index++; } for (; index < list.Count; index++) { newList.Add(list.GetKey(index), list[list.GetKey(index)]); } } } return(newList); }
/// <summary> /// 倒序 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> int IComparer <UrlObject> .Compare(UrlObject x, UrlObject y) { System.Collections.Comparer c = new System.Collections.Comparer(System.Globalization.CultureInfo.CurrentCulture); return(c.Compare(y.Access, x.Access)); }