/// <summary>
        /// Adds a prioritized item to the list.
        /// </summary>
        /// <param name="item">The prioritized item to add.</param>
        public void Add(PrioritizedItem <T> item)
        {
            var itemCount = _items.Count;

            if (itemCount == 0)
            {
                _items.Add(item);
                return;
            }

            var lastItemPriority = _items[itemCount - 1].Priority;

            if (SortDirection == ListSortDirection.Ascending && item.Priority >= lastItemPriority ||
                SortDirection == ListSortDirection.Descending && item.Priority <= lastItemPriority)
            {
                _items.Add(item);
                return;
            }

            for (var i = 0; i < itemCount; i++)
            {
                if (SortDirection == ListSortDirection.Ascending && item.Priority < _items[i].Priority ||
                    SortDirection == ListSortDirection.Descending && item.Priority > _items[i].Priority)
                {
                    _items.Insert(i, item);
                    return;
                }
            }
        }
        /// <inheritdoc />
        public bool Equals(PrioritizedItem <T> other)
        {
            if (default(T) == null)
            {
                return(ReferenceEquals(Item, other.Item));
            }

            return(EqualityComparer <T> .Default.Equals(Item, other.Item));
        }
        /// <summary>
        /// Gets the index of a prioritized item in the list.
        /// </summary>
        /// <param name="item">The item to get the index for.</param>
        /// <returns>The index of the item in the list or -1 if not found.</returns>
        public int IndexOf(PrioritizedItem <T> item)
        {
            var comparer = EqualityComparer <PrioritizedItem <T> > .Default;

            for (var i = 0; i < _items.Count; i++)
            {
                if (comparer.Equals(item, _items[i]))
                {
                    return(i);
                }
            }

            return(-1);
        }
        /// <summary>
        /// Checks whether the list contains the specified prioritized item.
        /// </summary>
        /// <param name="item">The item to check if the list contains.</param>
        /// <returns>True if found, false otherwise.</returns>
        public bool Contains(PrioritizedItem <T> item)
        {
            var comparer = EqualityComparer <PrioritizedItem <T> > .Default;

            var itemCount = _items.Count;

            for (var i = 0; i < itemCount; i++)
            {
                if (comparer.Equals(item, _items[i]))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #5
0
        /// <summary>
        /// Adds a prioritized item to the list.
        /// </summary>
        /// <param name="item">The prioritized item to add.</param>
        public void Add(PrioritizedItem <T> item)
        {
            if (_items.Count == 0)
            {
                _items.Add(item);
                return;
            }

            if (item.Priority >= _items[_items.Count - 1].Priority)
            {
                _items.Add(item);
                return;
            }

            for (var i = 0; i < _items.Count; i++)
            {
                if (item.Priority < _items[i].Priority)
                {
                    _items.Insert(i, item);
                    return;
                }
            }
        }
 void IList <PrioritizedItem <T> > .Insert(int index, PrioritizedItem <T> item)
 {
     throw new NotImplementedException("Inserting at a specific index is not supported.");
 }
        /// <summary>
        /// Adds an item to the list with the specified priority.
        /// </summary>
        /// <param name="item">The item to add.</param>
        /// <param name="priority">The priority to give the item.</param>
        public void Add(T item, int priority)
        {
            var prioritizedItem = new PrioritizedItem <T>(item, priority);

            Add(prioritizedItem);
        }
예제 #8
0
 public bool Equals(PrioritizedItem <T> other)
 {
     return(EqualityComparer <T> .Default.Equals(Item, other.Item));
 }
예제 #9
0
 /// <summary>
 /// Gets the index of a prioritized item in the list.
 /// </summary>
 /// <param name="item">The item to get the index for.</param>
 /// <returns>The index of the item in the list or -1 if not found.</returns>
 public int IndexOf(PrioritizedItem <T> item)
 {
     return(_items.IndexOf(item));
 }
예제 #10
0
 /// <summary>
 /// Checks whether the list contains the specified prioritized item.
 /// </summary>
 /// <param name="item">The item to check if the list contains.</param>
 /// <returns>True if found, false otherwise.</returns>
 public bool Contains(PrioritizedItem <T> item)
 {
     return(_items.Contains(item));
 }
예제 #11
0
 /// <summary>
 /// Removes a prioritized item from the list.
 /// </summary>
 /// <param name="item">The item to remove.</param>
 /// <returns>True if found and removed, false otherwise.</returns>
 public bool Remove(PrioritizedItem <T> item)
 {
     return(_items.Remove(item));
 }