/// <summary> /// Retrieves the numerical index of the specified item in the collection or -1 if not found. /// </summary> /// <param name="item"></param> /// <returns></returns> public int IndexOf(IMetricSample item) { lock (m_Lock) { return(m_List.IndexOfKey(item.Sequence)); } }
/// <summary> /// Remove the specified MetricSample item without firing an event. The outer Remove method should fire the event. /// </summary> /// <param name="item"></param> /// <returns></returns> private bool RemoveItem(IMetricSample item) { lock (m_Lock) { bool result = m_List.Remove(item.Sequence); return(result); } }
/// <summary> /// Determines whether an element is in the collection. /// </summary> /// <remarks>This method determines equality using the default equality comparer for the type of values in the list. It performs /// a linear search and therefore is an O(n) operation.</remarks> /// <param name="item">The object to locate in the collection.</param> /// <returns>true if the item is found in the collection; otherwise false.</returns> public bool Contains(IMetricSample item) { lock (m_Lock) { //here we are relying on the fact that the MetricSample object implements IComparable sufficiently to guarantee uniqueness return(m_List.ContainsKey(item.Sequence)); } }
/// <summary> /// Determines if the provided object is identical to this object. /// </summary> /// <param name="other">The object to compare this object to</param> /// <returns>True if the objects represent the same data.</returns> public bool Equals(IMetricSample other) { // Careful, it could be null; check it without recursion if (object.ReferenceEquals(other, null)) { return(false); // Since we're a live object we can't be equal to a null instance. } //look at the metric packets to let them make the call return(m_MetricSamplePacket.Equals(((MetricSample)other).Packet)); }
/// <summary> /// Add the specified MetricSample item to the collection /// </summary> /// <param name="item">The new MetricSample item to add</param> public void Add(IMetricSample item) { if (item == null) { throw new ArgumentNullException(nameof(item), "A new metric sample item must be provided to add it to the collection."); } lock (m_Lock) { //add it to both lookup collections m_List.Add(item.Sequence, item); } //and fire our event OnCollectionChanged(new CollectionChangedEventArgs <IMetricSampleCollection, IMetricSample>(this, item, CollectionAction.Added)); }
/// <summary> /// Remove the specified MetricSample item. If the MetricSample isn't in the collection, no exception is thrown. /// </summary> /// <param name="item">The MetricSample item to remove.</param> public bool Remove(IMetricSample item) { if (item == null) { throw new ArgumentNullException(nameof(item), "A metric sample item must be provided to remove it from the collection."); } bool result = RemoveItem(item); //and fire our event //and fire our event if we changed something if (result) { OnCollectionChanged(new CollectionChangedEventArgs <IMetricSampleCollection, IMetricSample>(this, item, CollectionAction.Removed)); } return(result); }
/// <summary> /// Not supported. /// </summary> /// <param name="index"></param> /// <param name="item"></param> public void Insert(int index, IMetricSample item) { //we don't support setting an object by index; we are sorted. throw new NotSupportedException(); }
/// <summary> /// Compare this metric sample with another to determine if they are the same or how they should be sorted relative to each other. /// </summary> /// <remarks>MetricSample instances are sorted by their Sequence number property.</remarks> /// <param name="other"></param> /// <returns>0 for an exact match, otherwise the relationship between the two for sorting.</returns> public int CompareTo(IMetricSample other) { //for performance reasons we've duped the key check here. return(m_MetricSamplePacket.Sequence.CompareTo(other.Sequence)); }