//-----------------------------------------------------------------------
        /// <summary>
        /// Obtains a {@code TemporalAdjuster} that wraps a date adjuster.
        /// <para>
        /// The {@code TemporalAdjuster} is based on the low level {@code Temporal} interface.
        /// This method allows an adjustment from {@code LocalDate} to {@code LocalDate}
        /// to be wrapped to match the temporal-based interface.
        /// This is provided for convenience to make user-written adjusters simpler.
        /// </para>
        /// <para>
        /// In general, user-written adjusters should be static constants:
        /// <pre>{@code
        ///  static TemporalAdjuster TWO_DAYS_LATER =
        ///       TemporalAdjusters.ofDateAdjuster(date -> date.plusDays(2));
        /// }</pre>
        ///
        /// </para>
        /// </summary>
        /// <param name="dateBasedAdjuster">  the date-based adjuster, not null </param>
        /// <returns> the temporal adjuster wrapping on the date adjuster, not null </returns>
        public static TemporalAdjuster OfDateAdjuster(UnaryOperator <LocalDate> dateBasedAdjuster)
        {
            Objects.RequireNonNull(dateBasedAdjuster, "dateBasedAdjuster");
//JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate:
            return((temporal) =>
            {
                LocalDate input = LocalDate.From(temporal);
                LocalDate output = dateBasedAdjuster.Apply(input);
                return temporal.with(output);
            });
        }
Beispiel #2
0
        /// <summary>
        /// Atomically updates the current value with the results of
        /// applying the given function, returning the previous value. The
        /// function should be side-effect-free, since it may be re-applied
        /// when attempted updates fail due to contention among threads.
        /// </summary>
        /// <param name="updateFunction"> a side-effect-free function </param>
        /// <returns> the previous value
        /// @since 1.8 </returns>
        public V GetAndUpdate(UnaryOperator <V> updateFunction)
        {
            V prev, next;

            do
            {
                prev = Get();
                next = updateFunction.Apply(prev);
            } while (!CompareAndSet(prev, next));
            return(prev);
        }
        /// <summary>
        /// Atomically updates the field of the given object managed by this updater
        /// with the results of applying the given function, returning the updated
        /// value. The function should be side-effect-free, since it may be
        /// re-applied when attempted updates fail due to contention among threads.
        /// </summary>
        /// <param name="obj"> An object whose field to get and set </param>
        /// <param name="updateFunction"> a side-effect-free function </param>
        /// <returns> the updated value
        /// @since 1.8 </returns>
        public V UpdateAndGet(T obj, UnaryOperator <V> updateFunction)
        {
            V prev, next;

            do
            {
                prev = Get(obj);
                next = updateFunction.Apply(prev);
            } while (!CompareAndSet(obj, prev, next));
            return(next);
        }
        /// <summary>
        /// Atomically updates the element at index {@code i} with the results
        /// of applying the given function, returning the updated value. The
        /// function should be side-effect-free, since it may be re-applied
        /// when attempted updates fail due to contention among threads.
        /// </summary>
        /// <param name="i"> the index </param>
        /// <param name="updateFunction"> a side-effect-free function </param>
        /// <returns> the updated value
        /// @since 1.8 </returns>
        public E UpdateAndGet(int i, UnaryOperator <E> updateFunction)
        {
            long offset = CheckedByteOffset(i);
            E    prev, next;

            do
            {
                prev = GetRaw(offset);
                next = updateFunction.Apply(prev);
            } while (!CompareAndSetRaw(offset, prev, next));
            return(next);
        }