public bool Equals(RecordToken <T> recordToken) { if (recordToken == null) { return(false); } return(Equals(_id, recordToken._id) && new DictionaryEqualityComparer <string, object>().Equals(_queryResults, recordToken._queryResults)); }
private static object GetFieldValue(RecordToken <T> token, SortDefinition definition) { object value; if (token == null) { value = null; } else if (definition.Field == "RepositoryId") { value = token.Id; } else { if (!token.TryGetValue(definition.Field, out value)) { value = null; } } return(value); }
public int Compare(RecordToken <T> x, RecordToken <T> y) { int result = 0; foreach (SortDefinition definition in _sortDefinitions) { var xValue = GetFieldValue(x, definition); var yValue = GetFieldValue(y, definition); result = definition.Comparer.Compare(xValue, yValue); if (result != 0) { return(result); } if (xValue != null && xValue.GetHashCode() != yValue.GetHashCode()) { // bugfix WS-33997. Khmer (invariant culture) strings when compared return "same", // when in fact they are different strings. In this case, use an ordinal compare. return(string.CompareOrdinal(xValue.ToString(), yValue.ToString())); } } result = x.Id.CompareTo(y.Id); return(result); }
/// <summary> /// Removes any entries for which the predicate canBeRemoved is true /// and another record token with the same repository Id exists /// </summary> /// <param name="fieldName"></param> /// <param name="canBeRemoved"></param> public void Coalesce(string fieldName, Predicate <object> canBeRemoved) { List <RecordToken <T> > results = new List <RecordToken <T> >(_results); SortByRepositoryId(results); bool hasValidEntry = false; List <RecordToken <T> > removeable = new List <RecordToken <T> >(); RecordToken <T> previousToken = null; foreach (RecordToken <T> token in results) { if ((previousToken != null) && (token.Id != previousToken.Id)) { if (hasValidEntry) { RemoveTokens(removeable); } removeable.Clear(); hasValidEntry = false; } if (canBeRemoved(token[fieldName])) { removeable.Add(token); } else { hasValidEntry = true; } previousToken = token; } if (hasValidEntry) { RemoveTokens(removeable); } }
public int CompareTo(RecordToken <T> other) { // Evaluate order in increasing expense, returning order at the earliest opportunity. if (other == null) { return(1); } int order = Id.CompareTo(other.Id); if (order != 0) { return(order); } SortedDictionary <string, object> theirResults = other._queryResults; if (_queryResults == null) { if (theirResults == null) { return(0); } return(-1); } if (theirResults == null) { return(1); } order = _queryResults.Count.CompareTo(theirResults.Count); if (order != 0) { return(order); } List <string> theirKeys = new List <string>(theirResults.Keys); int i = 0; foreach (string key in _queryResults.Keys) { order = key.CompareTo(theirKeys[i]); if (order != 0) { return(order); } order = ((IComparable)_queryResults[key]).CompareTo(theirResults[key]); if (order != 0) { return(order); } // bugfix WS-33997. Khmer (invariant culture) strings when compared return "same", // when in fact they are different strings. In this case, use an ordinal compare. if (_queryResults[key] != null && _queryResults[key].GetHashCode() != theirResults[key].GetHashCode()) { string a = _queryResults[key].ToString(); string b = theirResults[key].ToString(); order = String.Compare(a, b, StringComparison.Ordinal); if (order != 0) { return(order); } } ++i; } return(0); }
public int FindFirstIndex(RecordToken <T> token, int startIndex) { return(_results.FindIndex(startIndex, delegate(RecordToken <T> r) { return (r == token); })); }