/// <summary>
 /// Locate a listener is in the list of listeners.
 /// </summary>
 /// <param name="listenerArray">
 /// The array of listeners to sarch
 /// </param>
 /// <param name="listener">
 /// The <see cref="ICacheListener"/> to search for.
 /// </param>
 /// <returns>
 /// The index of the listener in the list of listeners.
 /// </returns>
 private int IndexOf(ICacheListener[] listenerArray, ICacheListener listener)
 {
     for (int i = 0, c = listenerArray.Length; i < c; ++i)
     {
         if (listener.Equals(listenerArray[i]))
         {
             return(i);
         }
     }
     return(-1);
 }
        /// <summary>
        /// Remove a listener.
        /// </summary>
        /// <param name="listener">
        /// The <see cref="ICacheListener"/> to remove.
        /// </param>
        public virtual void Remove(ICacheListener listener)
        {
            lock (this)
            {
                // Swing (Kestrel) will add/remove null listeners
                if (listener == null)
                {
                    return;
                }
                ICacheListener[] oldArray = GetListenerListFor(listener);
                int count = oldArray.Length;

                // most common case - exactly one listener
                if (count == 1)
                {
                    if (listener.Equals(oldArray[0]))
                    {
                        SetListenerListFor(listener, BLANKLIST);
                    }
                    return;
                }
                if (count > 0)
                {
                    // locate the listener in the list
                    int index = IndexOf(oldArray, listener);
                    if (index >= 0)
                    {
                        // remove the listener from the list
                        ICacheListener[] newArray = new ICacheListener[count - 1];
                        if (index > 0)
                        {
                            Array.Copy(oldArray, newArray, index);
                        }
                        if (index + 1 < count)
                        {
                            Array.Copy(oldArray, index + 1, newArray, index, count - index - 1);
                        }
                        SetListenerListFor(listener, newArray);
                    }
                }
            }
        }