Exemple #1
0
        //public void InsertAt(T item, Index index)
        //    => InsertAt(item, index.FromEnd ? (VCount - index.Value) : index.Value);

        /// <summary>
        ///     Puts the top item of *this* pile on top of another pile.<br/>
        ///     Requires <see cref="CanDraw"/> or <see cref="CanBrowse"/> on this pile and <see cref="CanPut"/> on the target pile.
        /// </summary>
        /// <param name="targetPile">
        ///     The pile to place a item on.
        /// </param>
        /// <remarks>
        ///     <note type="note">
        ///         Calls <see cref="OnPut(T)"/> on the target pile.<br/>
        ///         If the last item of this pile was taken, calls <see cref="OnLastRemoved"/> as well.
        ///     </note>
        /// </remarks>
        /// <exception cref="InvalidOperationException">
        ///     This pile does not allow drawing or browsing items<br/>
        ///     -OR-<br/>
        ///     <paramref name="targetPile"/> was the same instance as the source<br/>
        ///     -OR-<br/>
        ///     <paramref name="targetPile"/> does not allow placing items on top<br/>
        ///     -OR-<br/>
        ///     This pile was empty.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="targetPile"/> was <see langword="null"/>.
        /// </exception>
        public void Mill(Pile <T> targetPile)
        {
            if (!(CanDraw || CanBrowse))
            {
                ThrowHelper.ThrowInvalidOp(PileErrorStrings.NoDraw);
            }
            if (targetPile is null)
            {
                ThrowHelper.ThrowArgNull(nameof(targetPile));
            }
            if (ReferenceEquals(this, targetPile))
            {
                ThrowHelper.ThrowInvalidOp(PileErrorStrings.MillTargetSamePile);
            }
            if (!targetPile.CanPut)
            {
                ThrowHelper.ThrowInvalidOp(PileErrorStrings.NoPutTarget);
            }

            using (_rwlock.UsingWriteLock())
                using (targetPile._rwlock.UsingWriteLock())
                {
                    var milled = MillCore(targetPile);

                    if (Count == 0)
                    {
                        OnLastRemoved();
                    }

                    targetPile.OnPut(milled);
                }
        }
Exemple #2
0
 private protected virtual T MillCore(Pile <T> targetPile)
 => _logic.Mill(_noOpTransformer, targetPile.Adder);
 private protected sealed override T MillCore(Pile <T> targetPile)
 => _logic.Mill(_truthyUnwrapper, targetPile.Adder);