text:
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Runtime.CompilerServices;
using Dot.Net.DevFast.Etc;
using System.Collections.Generic;
using Dot.Net.DevFast.Extensions.StringExt;

namespace Dot.Net.DevFast.Extensions
{
    /// <summary>
    /// Extension library to produce conditional error based on a predicate
    /// </summary>
    public static class ThrowIfPredicate
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static void ThrowDfError(this DdnDfErrorCode code)
        {
            throw new DdnDfException(code);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static void ThrowDfError(this DdnDfErrorCode code, string message)
        {
            throw new DdnDfException(code, message);
        }

        #region ThrowIf

        /// <summary>
        /// Throws exception when <paramref name="truthValue"/> is true.
        /// </summary>
        /// <param name="truthValue">truth value</param>
        /// <param name="errorCode">error code of the exception</param>
        /// <param name="obj">Object to return if condition is false</param>
        /// <exception cref="DdnDfException"></exception>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static T ThrowIf<T>(this bool truthValue, DdnDfErrorCode errorCode, T obj)
        {
            if (truthValue) errorCode.ThrowDfError();
            return obj;
        }

        /// <summary>
        /// Throws exception when <paramref name="truthValue"/> is true.
        /// </summary>
        /// <param name="truthValue">truth value</param>
        /// <param name="errorCode">error code of the exception</param>
        /// <param name="errorMessage">Error message</param>
        /// <param name="obj">Object to return if condition is false</param>
        /// <exception cref="DdnDfException"></exception>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static T ThrowIf<T>(this bool truthValue, DdnDfErrorCode errorCode, string errorMessage, T obj)
        {
            if (truthValue) errorCode.ThrowDfError(errorMessage);
            return obj;
        }

        /// <summary>
        /// Throws exception when <paramref name="truthValue"/> is true.
        /// </summary>
        /// <param name="truthValue">truth value</param>
        /// <param name="errorCode">error code of the exception</param>
        /// <param name="errorMessageDelegate">Error message delegate</param>
        /// <param name="obj">Object to return if condition is false</param>
        /// <exception cref="DdnDfException"></exception>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static T ThrowIf<T>(this bool truthValue, DdnDfErrorCode errorCode, Func<string> errorMessageDelegate,
            T obj)
        {
            if (truthValue) errorCode.ThrowDfError(errorMessageDelegate());
            return obj;
        }

        #endregion

        #region ThrowIfNot

        /// <summary>
        /// Throws exception when <paramref name="truthValue"/> is false.
        /// </summary>
        /// <param name="truthValue">truth value</param>
        /// <param name="errorCode">error code of the exception</param>
        /// <param name="obj">Object to return if condition is true</param>
        /// <exception cref="DdnDfException"></exception>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static T ThrowIfNot<T>(this bool truthValue, DdnDfErrorCode errorCode, T obj)
        {
            return (!truthValue).ThrowIf(errorCode, obj);
        }

        /// <summary>
        /// Throws exception when <paramref name="truthValue"/> is false.
        /// </summary>
        /// <param name="truthValue">truth value</param>
        /// <param name="errorCode">error code of the exception</param>
        /// <param name="errorMessage">Error message</param>
        /// <param name="obj">Object to return if condition is true</param>
        /// <exception cref="DdnDfException"></exception>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static T ThrowIfNot<T>(this bool truthValue, DdnDfErrorCode errorCode, string errorMessage, T obj)
        {
            return (!truthValue).ThrowIf(errorCode, errorMessage, obj);
        }

        /// <summary>
        /// Throws exception when <paramref name="truthValue"/> is false.
        /// </summary>
        /// <param name="truthValue">truth value</param>
        /// <param name="errorCode">error code of the exception</param>
        /// <param name="errorMessageDelegate">Error message delegate</param>
        /// <param name="obj">Object to return if condition is true</param>
        /// <exception cref="DdnDfException"></exception>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static T ThrowIfNot<T>(this bool truthValue, DdnDfErrorCode errorCode, Func<string> errorMessageDelegate,
            T obj)
        {
            return (!truthValue).ThrowIf(errorCode, errorMessageDelegate, obj);
        }

        #endregion

        #region ThrowIfNull

        /// <summary>
        /// Throws exception when provided object is null else same object instance is returned
        /// to performed method chaining.
        /// </summary>
        /// <typeparam name="T">Any reference type</typeparam>
        /// <param name="obj">instance</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.NullObject"/></exception>
        public static T ThrowIfNull<T>(this T obj) where T : class
        {
            return ThrowIfNullPredicate(obj).ThrowIf(DdnDfErrorCode.NullObject, obj);
        }

        /// <summary>
        /// Throws exception when provided object is null else same object instance is returned
        /// to performed method chaining.
        /// </summary>
        /// <typeparam name="T">Any reference type</typeparam>
        /// <param name="obj">instance</param>
        /// <param name="errorMessage">error message of the exception</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.NullObject"/></exception>
        public static T ThrowIfNull<T>(this T obj, string errorMessage) where T : class
        {
            return ThrowIfNullPredicate(obj).ThrowIf(DdnDfErrorCode.NullObject, errorMessage, obj);
        }

        /// <summary>
        /// Throws exception when provided object is null else same object instance is returned
        /// to performed method chaining.
        /// </summary>
        /// <typeparam name="T">Any reference type</typeparam>
        /// <param name="obj">instance</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.NullObject"/></exception>
        public static T ThrowIfNull<T>(this T obj, Func<string> errorMessageDelegate) where T : class
        {
            return ThrowIfNullPredicate(obj).ThrowIf(DdnDfErrorCode.NullObject, errorMessageDelegate, obj);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static bool ThrowIfNullPredicate<T>(T obj) where T : class => obj is null;

        #endregion

        #region ThrowIfNullOrEmpty

        /// <summary>
        /// Throws error if the string is empty or contains only whitespaces
        /// else returns the original string value.
        /// </summary>
        /// <param name="val">Val to check</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.EmptyOrWhiteSpacedString"/></exception>
        public static string ThrowIfNullOrEmpty(this string val)
        {
            return val.ThrowIfNullOrEmpty("String is either empty of contains only whitespaces.");
        }

        /// <summary>
        /// Throws error if the string is empty or contains only whitespaces
        /// else returns the original string value.
        /// </summary>
        /// <param name="val">Val to check</param>
        /// <param name="errorMessage">Error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.EmptyOrWhiteSpacedString"/></exception>
        public static string ThrowIfNullOrEmpty(this string val, string errorMessage)
        {
            return val.IsNows().ThrowIf(DdnDfErrorCode.EmptyOrWhiteSpacedString, errorMessage, val);
        }

        /// <summary>
        /// Throws error if the string is empty or contains only whitespaces
        /// else returns the original string value.
        /// </summary>
        /// <param name="val">Val to check</param>
        /// <param name="errorMessageDelegate">Error message delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.EmptyOrWhiteSpacedString"/></exception>
        public static string ThrowIfNullOrEmpty(this string val, Func<string> errorMessageDelegate)
        {
            return val.IsNows().ThrowIf(DdnDfErrorCode.EmptyOrWhiteSpacedString, errorMessageDelegate, val);
        }

        /// <summary>
        /// Throws exception when provided array is either null or empty. Same object instance is returned
        /// to performed method chaining.
        /// </summary>
        /// <typeparam name="T">Collection type</typeparam>
        /// <param name="obj">instance</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.NullOrEmptyCollection"/></exception>
        public static T ThrowIfNullOrEmpty<T>(this T obj) where T : ICollection
        {
            return ThrowIfNullOrEmptyPredicate(obj).ThrowIf(DdnDfErrorCode.NullOrEmptyCollection, obj);
        }

        /// <summary>
        /// Throws exception when provided array is either null or empty. Same object instance is returned
        /// to performed method chaining.
        /// </summary>
        /// <typeparam name="T">Collection type</typeparam>
        /// <param name="obj">instance</param>
        /// <param name="errorMessage">error message of the exception</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.NullOrEmptyCollection"/></exception>
        public static T ThrowIfNullOrEmpty<T>(this T obj, string errorMessage) where T : ICollection
        {
            return ThrowIfNullOrEmptyPredicate(obj).ThrowIf(DdnDfErrorCode.NullOrEmptyCollection, errorMessage, obj);
        }

        /// <summary>
        /// Throws exception when provided array is either null or empty. Same object instance is returned
        /// to performed method chaining.
        /// </summary>
        /// <typeparam name="T">Collection type</typeparam>
        /// <param name="obj">instance</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.NullOrEmptyCollection"/></exception>
        public static T ThrowIfNullOrEmpty<T>(this T obj, Func<string> errorMessageDelegate) where T : ICollection
        {
            return ThrowIfNullOrEmptyPredicate(obj)
                .ThrowIf(DdnDfErrorCode.NullOrEmptyCollection, errorMessageDelegate, obj);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static bool ThrowIfNullOrEmptyPredicate<T>(T obj) where T : ICollection
        {
            return ReferenceEquals(obj, null) || obj.Count < 1;
        }

        #endregion

        #region ThrowOnMiss Collection

        /// <summary>
        /// Throws exception when provided value is not in the collection. Else collection instance is returned
        /// to performed method chaining.
        /// </summary>
        /// <typeparam name="T">Collection type</typeparam>
        /// <typeparam name="TV">Generic param type of the Collection</typeparam>
        /// <param name="collection">collection instance</param>
        /// <param name="lookUpValue">look up value instance</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotInCollection"/></exception>
        public static T ThrowOnMiss<T, TV>(this T collection, TV lookUpValue) where T : ICollection<TV>
        {
            return ThrowOnMissPredicate(collection, lookUpValue)
                .ThrowIfNot(DdnDfErrorCode.ValueNotInCollection, collection);
        }

        /// <summary>
        /// Throws exception when provided value is not in the collection. Else collection instance is returned
        /// to performed method chaining.
        /// </summary>
        /// <typeparam name="T">Array type</typeparam>
        /// <typeparam name="TV">Generic param type of the Collection</typeparam>
        /// <param name="collection">collection instance</param>
        /// <param name="lookUpValue">look up value instance</param>
        /// <param name="errorMessage">error message of the exception</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotInCollection"/></exception>
        public static T ThrowOnMiss<T, TV>(this T collection, TV lookUpValue, string errorMessage)
            where T : ICollection<TV>
        {
            return ThrowOnMissPredicate(collection, lookUpValue)
                .ThrowIfNot(DdnDfErrorCode.ValueNotInCollection, errorMessage, collection);
        }

        /// <summary>
        /// Throws exception when provided value not ont in the collection. Else collection instance is returned
        /// to performed method chaining.
        /// </summary>
        /// <typeparam name="T">Array type</typeparam>
        /// <typeparam name="TV">Generic param type of the Collection</typeparam>
        /// <param name="collection">collection instance</param>
        /// <param name="lookUpValue">look up value instance</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotInCollection"/></exception>
        public static T ThrowOnMiss<T, TV>(this T collection, TV lookUpValue, Func<string> errorMessageDelegate)
            where T : ICollection<TV>
        {
            return ThrowOnMissPredicate(collection, lookUpValue)
                .ThrowIfNot(DdnDfErrorCode.ValueNotInCollection, errorMessageDelegate, collection);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static bool ThrowOnMissPredicate<T, TV>(T collection, TV lookUpValue) where T : ICollection<TV>
        {
            return collection.Contains(lookUpValue);
        }

        #endregion

        #region ThrowOnMiss Dictionary

        /// <summary>
        /// Throws exception when provided key is not found in dictionary. Else associated value instance is returned
        /// to performed method chaining on the value.
        /// </summary>
        /// <typeparam name="TK">Type of key of the dictionary</typeparam>
        /// <typeparam name="TV">Type of value of the dictionary</typeparam>
        /// <param name="dictionary">dictionary instance</param>
        /// <param name="key">key instance</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.KeyNotFound"/></exception>
        public static TV ThrowOnMiss<TK, TV>(this Dictionary<TK, TV> dictionary, TK key)
        {
            return ThrowOnMissPredicate(dictionary, key, out var value).ThrowIfNot(DdnDfErrorCode.KeyNotFound, value);
        }

        /// <summary>
        /// Throws exception when provided key is not found in dictionary. Else associated value instance is returned
        /// to performed method chaining on the value.
        /// </summary>
        /// <typeparam name="TK">Type of key of the dictionary</typeparam>
        /// <typeparam name="TV">Type of value of the dictionary</typeparam>
        /// <param name="dictionary">dictionary instance</param>
        /// <param name="key">key instance</param>
        /// <param name="errorMessage">error message of the exception</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.KeyNotFound"/></exception>
        public static TV ThrowOnMiss<TK, TV>(this Dictionary<TK, TV> dictionary, TK key, string errorMessage)
        {
            return ThrowOnMissPredicate(dictionary, key, out var value)
                .ThrowIfNot(DdnDfErrorCode.KeyNotFound, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when provided key is not found in dictionary. Else associated value instance is returned
        /// to performed method chaining on the value.
        /// </summary>
        /// <typeparam name="TK">Type of key of the dictionary</typeparam>
        /// <typeparam name="TV">Type of value of the dictionary</typeparam>
        /// <param name="dictionary">dictionary instance</param>
        /// <param name="key">key instance</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.KeyNotFound"/></exception>
        public static TV ThrowOnMiss<TK, TV>(this Dictionary<TK, TV> dictionary, TK key,
            Func<string> errorMessageDelegate)
        {
            return ThrowOnMissPredicate(dictionary, key, out var value)
                .ThrowIfNot(DdnDfErrorCode.KeyNotFound, errorMessageDelegate, value);
        }

        /// <summary>
        /// Throws exception when provided key is not found in dictionary. Else associated value instance is returned
        /// to performed method chaining on the value.
        /// </summary>
        /// <typeparam name="TK">Type of key of the dictionary</typeparam>
        /// <typeparam name="TV">Type of value of the dictionary</typeparam>
        /// <param name="dictionary">dictionary instance</param>
        /// <param name="key">key instance</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.KeyNotFound"/></exception>
        public static TV ThrowOnMiss<TK, TV>(this ConcurrentDictionary<TK, TV> dictionary, TK key)
        {
            return ThrowOnMissPredicate(dictionary, key, out var value).ThrowIfNot(DdnDfErrorCode.KeyNotFound, value);
        }

        /// <summary>
        /// Throws exception when provided key is not found in dictionary. Else associated value instance is returned
        /// to performed method chaining on the value.
        /// </summary>
        /// <typeparam name="TK">Type of key of the dictionary</typeparam>
        /// <typeparam name="TV">Type of value of the dictionary</typeparam>
        /// <param name="dictionary">dictionary instance</param>
        /// <param name="key">key instance</param>
        /// <param name="errorMessage">error message of the exception</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.KeyNotFound"/></exception>
        public static TV ThrowOnMiss<TK, TV>(this ConcurrentDictionary<TK, TV> dictionary, TK key, string errorMessage)
        {
            return ThrowOnMissPredicate(dictionary, key, out var value)
                .ThrowIfNot(DdnDfErrorCode.KeyNotFound, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when provided key is not found in dictionary. Else associated value instance is returned
        /// to performed method chaining on the value.
        /// </summary>
        /// <typeparam name="TK">Type of key of the dictionary</typeparam>
        /// <typeparam name="TV">Type of value of the dictionary</typeparam>
        /// <param name="dictionary">dictionary instance</param>
        /// <param name="key">key instance</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.KeyNotFound"/></exception>
        public static TV ThrowOnMiss<TK, TV>(this ConcurrentDictionary<TK, TV> dictionary, TK key,
            Func<string> errorMessageDelegate)
        {
            return ThrowOnMissPredicate(dictionary, key, out var value)
                .ThrowIfNot(DdnDfErrorCode.KeyNotFound, errorMessageDelegate, value);
        }

        /// <summary>
        /// Throws exception when provided key is not found in dictionary. Else associated value instance is returned
        /// to performed method chaining on the value.
        /// </summary>
        /// <typeparam name="TK">Type of key of the dictionary</typeparam>
        /// <typeparam name="TV">Type of value of the dictionary</typeparam>
        /// <param name="dictionary">dictionary instance</param>
        /// <param name="key">key instance</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.KeyNotFound"/></exception>
        public static TV ThrowOnMiss<TK, TV>(this IDictionary<TK, TV> dictionary, TK key)
        {
            return ThrowOnMissPredicateIDict(dictionary, key, out var value).ThrowIfNot(DdnDfErrorCode.KeyNotFound, value);
        }

        /// <summary>
        /// Throws exception when provided key is not found in dictionary. Else associated value instance is returned
        /// to performed method chaining on the value.
        /// </summary>
        /// <typeparam name="TK">Type of key of the dictionary</typeparam>
        /// <typeparam name="TV">Type of value of the dictionary</typeparam>
        /// <param name="dictionary">dictionary instance</param>
        /// <param name="key">key instance</param>
        /// <param name="errorMessage">error message of the exception</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.KeyNotFound"/></exception>
        public static TV ThrowOnMiss<TK, TV>(this IDictionary<TK, TV> dictionary, TK key, string errorMessage)
        {
            return ThrowOnMissPredicateIDict(dictionary, key, out var value)
                .ThrowIfNot(DdnDfErrorCode.KeyNotFound, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when provided key is not found in dictionary. Else associated value instance is returned
        /// to performed method chaining on the value.
        /// </summary>
        /// <typeparam name="TK">Type of key of the dictionary</typeparam>
        /// <typeparam name="TV">Type of value of the dictionary</typeparam>
        /// <param name="dictionary">dictionary instance</param>
        /// <param name="key">key instance</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.KeyNotFound"/></exception>
        public static TV ThrowOnMiss<TK, TV>(this IDictionary<TK, TV> dictionary, TK key,
            Func<string> errorMessageDelegate)
        {
            return ThrowOnMissPredicateIDict(dictionary, key, out var value)
                .ThrowIfNot(DdnDfErrorCode.KeyNotFound, errorMessageDelegate, value);
        }

        /// <summary>
        /// Throws exception when provided key is not found in dictionary. Else associated value instance is returned
        /// to performed method chaining on the value.
        /// </summary>
        /// <typeparam name="TK">Type of key of the dictionary</typeparam>
        /// <typeparam name="TV">Type of value of the dictionary</typeparam>
        /// <param name="dictionary">dictionary instance</param>
        /// <param name="key">key instance</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.KeyNotFound"/></exception>
        public static TV ThrowOnMiss<TK, TV>(this IReadOnlyDictionary<TK, TV> dictionary, TK key)
        {
            return ThrowOnMissPredicate(dictionary, key, out var value).ThrowIfNot(DdnDfErrorCode.KeyNotFound, value);
        }

        /// <summary>
        /// Throws exception when provided key is not found in dictionary. Else associated value instance is returned
        /// to performed method chaining on the value.
        /// </summary>
        /// <typeparam name="TK">Type of key of the dictionary</typeparam>
        /// <typeparam name="TV">Type of value of the dictionary</typeparam>
        /// <param name="dictionary">dictionary instance</param>
        /// <param name="key">key instance</param>
        /// <param name="errorMessage">error message of the exception</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.KeyNotFound"/></exception>
        public static TV ThrowOnMiss<TK, TV>(this IReadOnlyDictionary<TK, TV> dictionary, TK key, string errorMessage)
        {
            return ThrowOnMissPredicate(dictionary, key, out var value)
                .ThrowIfNot(DdnDfErrorCode.KeyNotFound, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when provided key is not found in dictionary. Else associated value instance is returned
        /// to performed method chaining on the value.
        /// </summary>
        /// <typeparam name="TK">Type of key of the dictionary</typeparam>
        /// <typeparam name="TV">Type of value of the dictionary</typeparam>
        /// <param name="dictionary">dictionary instance</param>
        /// <param name="key">key instance</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.KeyNotFound"/></exception>
        public static TV ThrowOnMiss<TK, TV>(this IReadOnlyDictionary<TK, TV> dictionary, TK key,
            Func<string> errorMessageDelegate)
        {
            return ThrowOnMissPredicate(dictionary, key, out var value)
                .ThrowIfNot(DdnDfErrorCode.KeyNotFound, errorMessageDelegate, value);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static bool ThrowOnMissPredicate<TK, TV>(IReadOnlyDictionary<TK, TV> dictionary, TK key, out TV value)
        {
            return dictionary.TryGetValue(key, out value);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static bool ThrowOnMissPredicateIDict<TK, TV>(IDictionary<TK, TV> dictionary, TK key, out TV value)
        {
            return dictionary.TryGetValue(key, out value);
        }

        #endregion

        #region ThrowIf On Int

        /// <summary>
        /// Throws exception when given value is 0.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueEqual"/></exception>
        public static int ThrowIfZero(this int value)
        {
            return value.ThrowIfEqual(0);
        }

        /// <summary>
        /// Throws exception when given value is 0.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueEqual"/></exception>
        public static int ThrowIfZero(this int value, string errorMessage)
        {
            return value.ThrowIfEqual(0, errorMessage);
        }

        /// <summary>
        /// Throws exception when given value is 0.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueEqual"/></exception>
        public static int ThrowIfZero(this int value, Func<string> errorMessageDelegate)
        {
            return value.ThrowIfEqual(0, errorMessageDelegate);
        }

        /// <summary>
        /// Throws exception when given value is NOT 0.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotEqual"/></exception>
        public static int ThrowIfNotZero(this int value)
        {
            return value.ThrowIfNotEqual(0);
        }

        /// <summary>
        /// Throws exception when given value is NOT 0.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotEqual"/></exception>
        public static int ThrowIfNotZero(this int value, string errorMessage)
        {
            return value.ThrowIfNotEqual(0, errorMessage);
        }

        /// <summary>
        /// Throws exception when given value is NOT 0.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotEqual"/></exception>
        public static int ThrowIfNotZero(this int value, Func<string> errorMessageDelegate)
        {
            return value.ThrowIfNotEqual(0, errorMessageDelegate);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/>==<paramref name="comperand"/>.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueEqual"/></exception>
        public static int ThrowIfEqual(this int value, int comperand)
        {
            return value.ThrowIfEqual(comperand, () => $"{value} == {comperand}");
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/>==<paramref name="comperand"/>.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueEqual"/></exception>
        public static int ThrowIfEqual(this int value, int comperand, string errorMessage)
        {
            return EqualPredicate(value, comperand).ThrowIf(DdnDfErrorCode.ValueEqual, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/>==<paramref name="comperand"/>.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueEqual"/></exception>
        public static int ThrowIfEqual(this int value, int comperand, Func<string> errorMessageDelegate)
        {
            return EqualPredicate(value, comperand).ThrowIf(DdnDfErrorCode.ValueEqual, errorMessageDelegate, value);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/> != <paramref name="comperand"/>.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotEqual"/></exception>
        public static int ThrowIfNotEqual(this int value, int comperand)
        {
            return value.ThrowIfNotEqual(comperand, () => $"{value} != {comperand}");
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/> != <paramref name="comperand"/>.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotEqual"/></exception>
        public static int ThrowIfNotEqual(this int value, int comperand, string errorMessage)
        {
            return EqualPredicate(value, comperand).ThrowIfNot(DdnDfErrorCode.ValueNotEqual, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/> != <paramref name="comperand"/>.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotEqual"/></exception>
        public static int ThrowIfNotEqual(this int value, int comperand, Func<string> errorMessageDelegate)
        {
            return EqualPredicate(value, comperand).ThrowIfNot(DdnDfErrorCode.ValueNotEqual, errorMessageDelegate, value);
        }

        /// <summary>
        /// Throws exception when given value is strictly less than 0 (-1 onwards).
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueLessThanThreshold"/></exception>
        public static int ThrowIfNegative(this int value)
        {
            return value.ThrowIfLess(0);
        }

        /// <summary>
        /// Throws exception when given value is strictly less than 0 (-1 onwards).
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueLessThanThreshold"/></exception>
        public static int ThrowIfNegative(this int value, string errorMessage)
        {
            return value.ThrowIfLess(0, errorMessage);
        }

        /// <summary>
        /// Throws exception when given value is strictly less than 0 (-1 onwards).
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueLessThanThreshold"/></exception>
        public static int ThrowIfNegative(this int value, Func<string> errorMessageDelegate)
        {
            return value.ThrowIfLess(0, errorMessageDelegate);
        }

        /// <summary>
        /// Throws exception when given comparable value is strictly less than given threshold.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value instance to compare</param>
        /// <param name="threshold">Threshold value of comparison</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueLessThanThreshold"/></exception>
        public static int ThrowIfLess(this int value, int threshold)
        {
            return value.ThrowIfLess(threshold, () => $"{value} < {threshold}");
        }

        /// <summary>
        /// Throws exception when given comparable value is strictly less than given threshold.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="threshold">Threshold value of comparison</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueLessThanThreshold"/></exception>
        public static int ThrowIfLess(this int value, int threshold, string errorMessage)
        {
            return LessThanPredicate(value, threshold)
                .ThrowIf(DdnDfErrorCode.ValueLessThanThreshold, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when given comparable value is strictly less than given threshold.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="threshold">Threshold value of comparison</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueLessThanThreshold"/></exception>
        public static int ThrowIfLess(this int value, int threshold, Func<string> errorMessageDelegate)
        {
            return LessThanPredicate(value, threshold)
                .ThrowIf(DdnDfErrorCode.ValueLessThanThreshold, errorMessageDelegate, value);
        }

        /// <summary>
        /// Throws exception when given value is strictly greater than 0 (+1 onwards).
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueGreaterThanThreshold"/></exception>
        public static int ThrowIfPositive(this int value)
        {
            return value.ThrowIfGreater(0);
        }

        /// <summary>
        /// Throws exception when given value is strictly greater than 0 (+1 onwards).
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueGreaterThanThreshold"/></exception>
        public static int ThrowIfPositive(this int value, string errorMessage)
        {
            return value.ThrowIfGreater(0, errorMessage);
        }

        /// <summary>
        /// Throws exception when given value is strictly greater than 0 (+1 onwards).
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueGreaterThanThreshold"/></exception>
        public static int ThrowIfPositive(this int value, Func<string> errorMessageDelegate)
        {
            return value.ThrowIfGreater(0, errorMessageDelegate);
        }

        /// <summary>
        /// Throws exception when given comparable value is strictly greater than given threshold.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="threshold">Threshold value of comparison</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueGreaterThanThreshold"/></exception>
        public static int ThrowIfGreater(this int value, int threshold)
        {
            return value.ThrowIfGreater(threshold, () => $"{value} > {threshold}");
        }

        /// <summary>
        /// Throws exception when given comparable value is strictly greater than given threshold.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="threshold">Threshold value of comparison</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueGreaterThanThreshold"/></exception>
        public static int ThrowIfGreater(this int value, int threshold, string errorMessage)
        {
            return LessThanPredicate(threshold, value)
                .ThrowIf(DdnDfErrorCode.ValueGreaterThanThreshold, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when given comparable value is strictly greater than given threshold.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="threshold">Threshold value of comparison</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueGreaterThanThreshold"/></exception>
        public static int ThrowIfGreater(this int value, int threshold, Func<string> errorMessageDelegate)
        {
            return LessThanPredicate(threshold, value)
                .ThrowIf(DdnDfErrorCode.ValueGreaterThanThreshold, errorMessageDelegate, value);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static bool EqualPredicate(int value, int comperand)
        {
            return value.Equals(comperand);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static bool LessThanPredicate(int value, int threshold)
        {
            return value < threshold;
        }

        #endregion

        #region ThrowIf On Long

        /// <summary>
        /// Throws exception when given value is 0.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueEqual"/></exception>
        public static long ThrowIfZero(this long value)
        {
            return value.ThrowIfEqual(0);
        }

        /// <summary>
        /// Throws exception when given value is 0.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueEqual"/></exception>
        public static long ThrowIfZero(this long value, string errorMessage)
        {
            return value.ThrowIfEqual(0, errorMessage);
        }

        /// <summary>
        /// Throws exception when given value is 0.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueEqual"/></exception>
        public static long ThrowIfZero(this long value, Func<string> errorMessageDelegate)
        {
            return value.ThrowIfEqual(0, errorMessageDelegate);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/>==<paramref name="comperand"/>.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueEqual"/></exception>
        public static long ThrowIfEqual(this long value, long comperand)
        {
            return value.ThrowIfEqual(comperand, () => $"{value} == {comperand}");
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/>==<paramref name="comperand"/>.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueEqual"/></exception>
        public static long ThrowIfEqual(this long value, long comperand, string errorMessage)
        {
            return EqualPredicate(value, comperand).ThrowIf(DdnDfErrorCode.ValueEqual, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/>==<paramref name="comperand"/>.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueEqual"/></exception>
        public static long ThrowIfEqual(this long value, long comperand, Func<string> errorMessageDelegate)
        {
            return EqualPredicate(value, comperand).ThrowIf(DdnDfErrorCode.ValueEqual, errorMessageDelegate, value);
        }

        /// <summary>
        /// Throws exception when given value is NOT 0.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotEqual"/></exception>
        public static long ThrowIfNotZero(this long value)
        {
            return value.ThrowIfNotEqual(0);
        }

        /// <summary>
        /// Throws exception when given value is NOT 0.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotEqual"/></exception>
        public static long ThrowIfNotZero(this long value, string errorMessage)
        {
            return value.ThrowIfNotEqual(0, errorMessage);
        }

        /// <summary>
        /// Throws exception when given value is NOT 0.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotEqual"/></exception>
        public static long ThrowIfNotZero(this long value, Func<string> errorMessageDelegate)
        {
            return value.ThrowIfNotEqual(0, errorMessageDelegate);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/> != <paramref name="comperand"/>.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotEqual"/></exception>
        public static long ThrowIfNotEqual(this long value, long comperand)
        {
            return value.ThrowIfNotEqual(comperand, () => $"{value} != {comperand}");
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/> != <paramref name="comperand"/>.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotEqual"/></exception>
        public static long ThrowIfNotEqual(this long value, long comperand, string errorMessage)
        {
            return EqualPredicate(value, comperand).ThrowIfNot(DdnDfErrorCode.ValueNotEqual, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/> != <paramref name="comperand"/>.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotEqual"/></exception>
        public static long ThrowIfNotEqual(this long value, long comperand, Func<string> errorMessageDelegate)
        {
            return EqualPredicate(value, comperand).ThrowIfNot(DdnDfErrorCode.ValueNotEqual, errorMessageDelegate, value);
        }

        /// <summary>
        /// Throws exception when given value is strictly less than 0 (-1 onwards).
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueLessThanThreshold"/></exception>
        public static long ThrowIfNegative(this long value)
        {
            return value.ThrowIfLess(0);
        }

        /// <summary>
        /// Throws exception when given value is strictly less than 0 (-1 onwards).
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueLessThanThreshold"/></exception>
        public static long ThrowIfNegative(this long value, string errorMessage)
        {
            return value.ThrowIfLess(0, errorMessage);
        }

        /// <summary>
        /// Throws exception when given value is strictly less than 0 (-1 onwards).
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueLessThanThreshold"/></exception>
        public static long ThrowIfNegative(this long value, Func<string> errorMessageDelegate)
        {
            return value.ThrowIfLess(0, errorMessageDelegate);
        }

        /// <summary>
        /// Throws exception when given comparable value is strictly less than given threshold.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value instance to compare</param>
        /// <param name="threshold">Threshold value of comparison</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueLessThanThreshold"/></exception>
        public static long ThrowIfLess(this long value, long threshold)
        {
            return value.ThrowIfLess(threshold, () => $"{value} < {threshold}");
        }

        /// <summary>
        /// Throws exception when given comparable value is strictly less than given threshold.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="threshold">Threshold value of comparison</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueLessThanThreshold"/></exception>
        public static long ThrowIfLess(this long value, long threshold, string errorMessage)
        {
            return LessThanPredicate(value, threshold)
                .ThrowIf(DdnDfErrorCode.ValueLessThanThreshold, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when given comparable value is strictly less than given threshold.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="threshold">Threshold value of comparison</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueLessThanThreshold"/></exception>
        public static long ThrowIfLess(this long value, long threshold, Func<string> errorMessageDelegate)
        {
            return LessThanPredicate(value, threshold)
                .ThrowIf(DdnDfErrorCode.ValueLessThanThreshold, errorMessageDelegate, value);
        }

        /// <summary>
        /// Throws exception when given value is strictly greater than 0 (+1 onwards).
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueGreaterThanThreshold"/></exception>
        public static long ThrowIfPositive(this long value)
        {
            return value.ThrowIfGreater(0);
        }

        /// <summary>
        /// Throws exception when given value is strictly greater than 0 (+1 onwards).
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueGreaterThanThreshold"/></exception>
        public static long ThrowIfPositive(this long value, string errorMessage)
        {
            return value.ThrowIfGreater(0, errorMessage);
        }

        /// <summary>
        /// Throws exception when given value is strictly greater than 0 (+1 onwards).
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueGreaterThanThreshold"/></exception>
        public static long ThrowIfPositive(this long value, Func<string> errorMessageDelegate)
        {
            return value.ThrowIfGreater(0, errorMessageDelegate);
        }

        /// <summary>
        /// Throws exception when given comparable value is strictly greater than given threshold.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="threshold">Threshold value of comparison</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueGreaterThanThreshold"/></exception>
        public static long ThrowIfGreater(this long value, long threshold)
        {
            return value.ThrowIfGreater(threshold, () => $"{value} > {threshold}");
        }

        /// <summary>
        /// Throws exception when given comparable value is strictly greater than given threshold.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="threshold">Threshold value of comparison</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueGreaterThanThreshold"/></exception>
        public static long ThrowIfGreater(this long value, long threshold, string errorMessage)
        {
            return LessThanPredicate(threshold, value)
                .ThrowIf(DdnDfErrorCode.ValueGreaterThanThreshold, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when given comparable value is strictly greater than given threshold.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="threshold">Threshold value of comparison</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueGreaterThanThreshold"/></exception>
        public static long ThrowIfGreater(this long value, long threshold, Func<string> errorMessageDelegate)
        {
            return LessThanPredicate(threshold, value)
                .ThrowIf(DdnDfErrorCode.ValueGreaterThanThreshold, errorMessageDelegate, value);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static bool EqualPredicate(long value, long comperand)
        {
            return value.Equals(comperand);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static bool LessThanPredicate(long value, long threshold)
        {
            return value < threshold;
        }

        #endregion

        #region ThrowIf On Generic Comparer

        /// <summary>
        /// Throws exception when <paramref name="value"/> and <paramref name="comperand"/> are equal.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueEqual"/></exception>
        public static T ThrowIfEqual<T>(this T value, T comperand) where T : IEquatable<T>
        {
            return EqualPredicate(value, comperand).ThrowIf(DdnDfErrorCode.ValueEqual, value);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/> and <paramref name="comperand"/> are equal.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueEqual"/></exception>
        public static T ThrowIfEqual<T>(this T value, T comperand, string errorMessage) where T : IEquatable<T>
        {
            return EqualPredicate(value, comperand).ThrowIf(DdnDfErrorCode.ValueEqual, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/> and <paramref name="comperand"/> are equal.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueEqual"/></exception>
        public static T ThrowIfEqual<T>(this T value, T comperand, Func<string> errorMessageDelegate)
            where T : IEquatable<T>
        {
            return EqualPredicate(value, comperand).ThrowIf(DdnDfErrorCode.ValueEqual, errorMessageDelegate, value);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/> and <paramref name="comperand"/> are equal.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <param name="comparer">comparer instance</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueEqual"/></exception>
        public static T ThrowIfEqual<T>(this T value, T comperand, IEqualityComparer<T> comparer)
        {
            return EqualPredicate(value, comperand, comparer).ThrowIf(DdnDfErrorCode.ValueEqual, value);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/> and <paramref name="comperand"/> are equal.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <param name="comparer">comparer instance</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueEqual"/></exception>
        public static T ThrowIfEqual<T>(this T value, T comperand, IEqualityComparer<T> comparer, string errorMessage)
        {
            return EqualPredicate(value, comperand, comparer).ThrowIf(DdnDfErrorCode.ValueEqual, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/> and <paramref name="comperand"/> are equal.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <param name="comparer">comparer instance</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueEqual"/></exception>
        public static T ThrowIfEqual<T>(this T value, T comperand, IEqualityComparer<T> comparer,
            Func<string> errorMessageDelegate)
        {
            return EqualPredicate(value, comperand, comparer)
                .ThrowIf(DdnDfErrorCode.ValueEqual, errorMessageDelegate, value);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/> and <paramref name="comperand"/> are NOT equal.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotEqual"/></exception>
        public static T ThrowIfNotEqual<T>(this T value, T comperand) where T : IEquatable<T>
        {
            return EqualPredicate(value, comperand).ThrowIfNot(DdnDfErrorCode.ValueNotEqual, value);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/> and <paramref name="comperand"/> are NOT equal.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotEqual"/></exception>
        public static T ThrowIfNotEqual<T>(this T value, T comperand, string errorMessage) where T : IEquatable<T>
        {
            return EqualPredicate(value, comperand).ThrowIfNot(DdnDfErrorCode.ValueNotEqual, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/> and <paramref name="comperand"/> are NOT equal.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotEqual"/></exception>
        public static T ThrowIfNotEqual<T>(this T value, T comperand, Func<string> errorMessageDelegate)
            where T : IEquatable<T>
        {
            return EqualPredicate(value, comperand).ThrowIfNot(DdnDfErrorCode.ValueNotEqual, errorMessageDelegate, value);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/> and <paramref name="comperand"/> are NOT equal.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <param name="comparer">comparer instance</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotEqual"/></exception>
        public static T ThrowIfNotEqual<T>(this T value, T comperand, IEqualityComparer<T> comparer)
        {
            return EqualPredicate(value, comperand, comparer).ThrowIfNot(DdnDfErrorCode.ValueNotEqual, value);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/> and <paramref name="comperand"/> are NOT equal.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <param name="comparer">comparer instance</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotEqual"/></exception>
        public static T ThrowIfNotEqual<T>(this T value, T comperand, IEqualityComparer<T> comparer, string errorMessage)
        {
            return EqualPredicate(value, comperand, comparer).ThrowIfNot(DdnDfErrorCode.ValueNotEqual, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when <paramref name="value"/> and <paramref name="comperand"/> are NOT equal.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="comperand">value to compare to</param>
        /// <param name="comparer">comparer instance</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueNotEqual"/></exception>
        public static T ThrowIfNotEqual<T>(this T value, T comperand, IEqualityComparer<T> comparer,
            Func<string> errorMessageDelegate)
        {
            return EqualPredicate(value, comperand, comparer)
                .ThrowIfNot(DdnDfErrorCode.ValueNotEqual, errorMessageDelegate, value);
        }

        /// <summary>
        /// Throws exception when given comparable value is strictly less than given threshold.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value instance to compare</param>
        /// <param name="threshold">Threshold value of comparison</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueLessThanThreshold"/></exception>
        public static T ThrowIfLess<T>(this T value, T threshold) where T : IComparable<T>
        {
            return LessThanPredicate(value, threshold).ThrowIf(DdnDfErrorCode.ValueLessThanThreshold, value);
        }

        /// <summary>
        /// Throws exception when given comparable value is strictly less than given threshold.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="threshold">Threshold value of comparison</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueLessThanThreshold"/></exception>
        public static T ThrowIfLess<T>(this T value, T threshold, string errorMessage) where T : IComparable<T>
        {
            return LessThanPredicate(value, threshold)
                .ThrowIf(DdnDfErrorCode.ValueLessThanThreshold, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when given comparable value is strictly less than given threshold.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="threshold">Threshold value of comparison</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueLessThanThreshold"/></exception>
        public static T ThrowIfLess<T>(this T value, T threshold, Func<string> errorMessageDelegate)
            where T : IComparable<T>
        {
            return LessThanPredicate(value, threshold)
                .ThrowIf(DdnDfErrorCode.ValueLessThanThreshold, errorMessageDelegate, value);
        }

        /// <summary>
        /// Throws exception when given comparable value is strictly greater than given threshold.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="threshold">Threshold value of comparison</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueGreaterThanThreshold"/></exception>
        public static T ThrowIfGreater<T>(this T value, T threshold) where T : IComparable<T>
        {
            return LessThanPredicate(threshold, value).ThrowIf(DdnDfErrorCode.ValueGreaterThanThreshold, value);
        }

        /// <summary>
        /// Throws exception when given comparable value is strictly greater than given threshold.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="threshold">Threshold value of comparison</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueGreaterThanThreshold"/></exception>
        public static T ThrowIfGreater<T>(this T value, T threshold, string errorMessage) where T : IComparable<T>
        {
            return LessThanPredicate(threshold, value)
                .ThrowIf(DdnDfErrorCode.ValueGreaterThanThreshold, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when given comparable value is strictly greater than given threshold.
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="threshold">Threshold value of comparison</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueGreaterThanThreshold"/></exception>
        public static T ThrowIfGreater<T>(this T value, T threshold, Func<string> errorMessageDelegate)
            where T : IComparable<T>
        {
            return LessThanPredicate(threshold, value)
                .ThrowIf(DdnDfErrorCode.ValueGreaterThanThreshold, errorMessageDelegate, value);
        }

        /// <summary>
        /// Throws exception when given comparable value is out of bound (both bound exclusive, i.e.,
        /// throws when <paramref name="value"/> < LowerOfTwoBound OR <paramref name="value"/> > HigherOfTwoBound).
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="firstBoundExcl">first bound of comparison</param>
        /// <param name="secondBoundExcl">second bound of comparison</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueOutOfBound"/></exception>
        public static T ThrowIfNotBounded<T>(this T value, T firstBoundExcl, T secondBoundExcl) where T : IComparable<T>
        {
            return value.ThrowIfNotBounded(firstBoundExcl, secondBoundExcl,
                () => $"Either {value} < {firstBoundExcl} Or {value} > {secondBoundExcl}");
        }

        /// <summary>
        /// Throws exception when given comparable value is out of bound (both bound exclusive, i.e.,
        /// throws when <paramref name="value"/> < LowerOfTwoBound OR <paramref name="value"/> > HigherOfTwoBound).
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="firstBoundExcl">first bound of comparison</param>
        /// <param name="secondBoundExcl">second bound of comparison</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueOutOfBound"/></exception>
        public static T ThrowIfNotBounded<T>(this T value, T firstBoundExcl, T secondBoundExcl,
            string errorMessage) where T : IComparable<T>
        {
            return OutOfBoundPredicate(value, firstBoundExcl, secondBoundExcl)
                .ThrowIf(DdnDfErrorCode.ValueOutOfBound, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when given comparable value is out of bound (both bound exclusive, i.e.,
        /// throws when <paramref name="value"/> < LowerOfTwoBound OR <paramref name="value"/> > HigherOfTwoBound).
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="firstBoundExcl">first bound of comparison</param>
        /// <param name="secondBoundExcl">second bound of comparison</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueOutOfBound"/></exception>
        public static T ThrowIfNotBounded<T>(this T value, T firstBoundExcl, T secondBoundExcl,
            Func<string> errorMessageDelegate) where T : IComparable<T>
        {
            return OutOfBoundPredicate(value, firstBoundExcl, secondBoundExcl)
                .ThrowIf(DdnDfErrorCode.ValueOutOfBound, errorMessageDelegate, value);
        }

        /// <summary>
        /// Throws exception when given comparable value is within the bounds (both bound inclusive, i.e.,
        /// throws when LowerOfTwoBound <= <paramref name="value"/> <= HigherOfTwoBound).
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="firstBoundExcl">first bound of comparison</param>
        /// <param name="secondBoundExcl">second bound of comparison</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueInBound"/></exception>
        public static T ThrowIfBounded<T>(this T value, T firstBoundExcl, T secondBoundExcl) where T : IComparable<T>
        {
            return value.ThrowIfBounded(firstBoundExcl, secondBoundExcl,
                () => $"{firstBoundExcl} <= {value} <= {secondBoundExcl}");
        }

        /// <summary>
        /// Throws exception when given comparable value is within the bounds (both bound inclusive, i.e.,
        /// throws when LowerOfTwoBound <= <paramref name="value"/> <= HigherOfTwoBound).
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="firstBoundExcl">first bound of comparison</param>
        /// <param name="secondBoundExcl">second bound of comparison</param>
        /// <param name="errorMessage">error message</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueInBound"/></exception>
        public static T ThrowIfBounded<T>(this T value, T firstBoundExcl, T secondBoundExcl,
            string errorMessage) where T : IComparable<T>
        {
            return OutOfBoundPredicate(value, firstBoundExcl, secondBoundExcl)
                .ThrowIfNot(DdnDfErrorCode.ValueInBound, errorMessage, value);
        }

        /// <summary>
        /// Throws exception when given comparable value is within the bounds (both bound inclusive, i.e.,
        /// throws when LowerOfTwoBound <= <paramref name="value"/> <= HigherOfTwoBound).
        /// Else <paramref name="value"/> is returned to performed method chaining.
        /// </summary>
        /// <param name="value">Value to check</param>
        /// <param name="firstBoundExcl">first bound of comparison</param>
        /// <param name="secondBoundExcl">second bound of comparison</param>
        /// <param name="errorMessageDelegate">error message generating delegate</param>
        /// <exception cref="DdnDfException">Error code as <seealso cref="DdnDfErrorCode.ValueInBound"/></exception>
        public static T ThrowIfBounded<T>(this T value, T firstBoundExcl, T secondBoundExcl,
            Func<string> errorMessageDelegate) where T : IComparable<T>
        {
            return OutOfBoundPredicate(value, firstBoundExcl, secondBoundExcl)
                .ThrowIfNot(DdnDfErrorCode.ValueInBound, errorMessageDelegate, value);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static bool EqualPredicate<T>(T value, T comperand) where T : IEquatable<T>
        {
            return value.Equals(comperand);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static bool EqualPredicate<T>(T value, T comperand, IEqualityComparer<T> comparer)
        {
            return comparer.Equals(value, comperand);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static bool LessThanPredicate<T>(T value, T threshold) where T : IComparable<T>
        {
            return value.CompareTo(threshold) < 0;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static bool OutOfBoundPredicate<T>(T value, T lowValue, T highValue) where T : IComparable<T>
        {
            if (highValue.CompareTo(lowValue) < 0)
            {
                return LessThanPredicate(value, highValue) || LessThanPredicate(lowValue, value);
            }
            return LessThanPredicate(value, lowValue) || LessThanPredicate(highValue, value);
        }

        #endregion
    }
}


text:
package org.jscep.transport.response;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.security.Security;
import java.util.EnumSet;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.junit.Assert;
import org.junit.Test;

public class CapabilitiesTest {
    @Test
    public void testPostNotSupported() {
        Capabilities caps = new Capabilities();
        Assert.assertFalse(caps.isPostSupported());
    }

    @Test
    public void testPostSupported() {
        Capabilities caps = new Capabilities(Capability.POST_PKI_OPERATION);
        Assert.assertTrue(caps.isPostSupported());
    }

    @Test
    public void testRenewalNotSupported() {
        Capabilities caps = new Capabilities();
        Assert.assertFalse(caps.isRenewalSupported());
    }

    @Test
    public void testRenewalSupported() {
        Capabilities caps = new Capabilities(Capability.RENEWAL);
        Assert.assertTrue(caps.isRenewalSupported());
    }

    @Test
    public void testNextCANotSupported() {
        Capabilities caps = new Capabilities();
        Assert.assertFalse(caps.isRolloverSupported());
    }

    @Test
    public void testNextCASupported() {
        Capabilities caps = new Capabilities(Capability.GET_NEXT_CA_CERT);
        Assert.assertTrue(caps.isRolloverSupported());
    }

    @Test
    public void testUpdateNotSupported() {
        Capabilities caps = new Capabilities();
        Assert.assertFalse(caps.isUpdateSupported());
    }

    @Test
    public void testUpdateSupported() {
        Capabilities caps = new Capabilities(Capability.UPDATE);
        Assert.assertTrue(caps.isUpdateSupported());
    }

    @Test
    public void testContains() {
        Capabilities caps = new Capabilities(Capability.GET_NEXT_CA_CERT);
        assertTrue(caps.contains(Capability.GET_NEXT_CA_CERT));
    }

    @Test
    public void testScepStandard() {
        Capabilities caps = new Capabilities(Capability.SCEP_STANDARD);
        assertTrue(caps.contains(Capability.AES));
        assertTrue(caps.contains(Capability.POST_PKI_OPERATION));
        assertTrue(caps.contains(Capability.SHA_256));
        assertTrue(caps.isPostSupported());
    }

    @Test
    public void testNoAlgorithmSupportYieldsDefaultCipher() {
        Provider[] providers = removeProviders();
        Capabilities caps = new Capabilities(Capability.TRIPLE_DES);
        assertThat(caps.getStrongestCipher(), is("DES"));

        restoreProviders(providers);
    }

    @Test
    public void testNoAlgorithmSupportYieldsDefaultDigest() {
        Provider[] providers = removeProviders();
        Capabilities caps = new Capabilities(Capability.SHA_512);
        assertThat(caps.getStrongestMessageDigest(), is(nullValue()));

        restoreProviders(providers);
    }

    @Test
    public void testStrongestSignature() throws NoSuchAlgorithmException {
    	Provider[] providers =removeProviders();
        BouncyCastleProvider bouncyCastle = new BouncyCastleProvider();
        Security.addProvider(bouncyCastle);
        assertThat(Security.getProviders().length, is(1));
        final EnumSet<Capability> capsConstructorArg = EnumSet.noneOf(Capability.class);
        for (Capability enumValue : Capability.values()) {
            capsConstructorArg.add(enumValue);
        }

        Capabilities caps = new Capabilities(capsConstructorArg.toArray(new Capability[capsConstructorArg.size()]));
        assertThat(caps.getStrongestMessageDigest().toString(), is(MessageDigest.getInstance("SHA-512").toString()));
        assertThat(caps.getStrongestSignatureAlgorithm(), is("SHA512withRSA"));

        removeProviders();
        restoreProviders(providers);
    }

	private void restoreProviders(Provider[] providers) {
		for (Provider provider : providers) {
            Security.addProvider(provider);
        }
	}

	private Provider[] removeProviders() {
		Provider[] providers = Security.getProviders();
        for (Provider provider : providers) {
            Security.removeProvider(provider.getName());
        }
		return providers;
	}
}

redpajama_set_name: RedPajamaGithub


text:
var default_options = {
  blocked_urls: [],
  enabled: true
};

// Storage helpers

function load_options(callback) {
  chrome.storage.sync.get(default_options, function(options) {
    callback(options);
  });
}

function store_options(options, callback) {
  chrome.storage.sync.set(options, function() {
    chrome.runtime.sendMessage(options);
    if(callback) {
      callback();
    }
  });
}


text:
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (c) 2015, Nordic Semiconductor
  ~ All rights reserved.
  ~
  ~ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  ~
  ~ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  ~
  ~ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
  ~ documentation and/or other materials provided with the distribution.
  ~
  ~ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this
  ~ software without specific prior written permission.
  ~
  ~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ~ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ~ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ~ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  ~ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  ~ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -->

<resources>

	<style name="Widget.IconButton">
		<item name="android:layout_width">wrap_content</item>
		<item name="android:layout_height">wrap_content</item>
		<item name="android:focusable">false</item>
		<item name="android:focusableInTouchMode">false</item>
		<item name="android:clickable">true</item>
		<item name="android:layout_gravity">center_vertical</item>
		<item name="android:background">@null</item>
	</style>

	<style name="Widget.IconButton.Add">
		<item name="android:src">@drawable/ic_action_add</item>
	</style>

	<style name="Widget.IconButton.Clear">
		<item name="android:src">@drawable/ic_action_clear</item>
	</style>

	<style name="Widget.IconButton.Download">
		<item name="android:src">@drawable/ic_action_download</item>
	</style>
</resources>


text:
<?xml version="1.0" encoding="UTF-8"?>
<billStatus>
  <bill>
    <subjects>
      <billSubjects>
        <legislativeSubjects>
          <item>
            <name>Congressional committees</name>
          </item>
          <item>
            <name>House Committee on Appropriations</name>
          </item>
          <item>
            <name>House Committee on Energy and Commerce</name>
          </item>
          <item>
            <name>House Committee on Financial Services</name>
          </item>
          <item>
            <name>House Committee on Ways and Means</name>
          </item>
          <item>
            <name>House of Representatives</name>
          </item>
          <item>
            <name>Members of Congress</name>
          </item>
        </legislativeSubjects>
        <policyArea>
          <name>Congress</name>
        </policyArea>
      </billSubjects>
    </subjects>
    <laws />
    <constitutionalAuthorityStatementText />
    <committeeReports />
    <actions>
      <item>
        <actionDate>2017-01-06</actionDate>
        <text>Motion to reconsider laid on the table Agreed to without objection.</text>
        <sourceSystem>
          2
          <name>House floor actions</name>
        </sourceSystem>
        <actionTime>13:51:30</actionTime>
        <links />
        <actionCode>H38310</actionCode>
        <type>Floor</type>
        <committee />
      </item>
      <item>
        <actionDate>2017-01-06</actionDate>
        <text>On agreeing to the resolution Agreed to without objection. (text: CR H190)</text>
        <sourceSystem>
          2
          <name>House floor actions</name>
        </sourceSystem>
        <actionTime>13:51:26</actionTime>
        <links>
          <link>
            <url>https://www.congress.gov/congressional-record/volume-163/house-section/page/H190</url>
            <name>H190</name>
          </link>
        </links>
        <actionCode>H37100</actionCode>
        <type>Floor</type>
        <committee />
      </item>
      <item>
        <actionDate>2017-01-06</actionDate>
        <text>Passed/agreed to in House: On agreeing to the resolution Agreed to without objection.(text: CR H190)</text>
        <sourceSystem>
          9
          <name>Library of Congress</name>
        </sourceSystem>
        <actionTime>13:51:26</actionTime>
        <links>
          <link>
            <url>https://www.congress.gov/congressional-record/volume-163/house-section/page/H190</url>
            <name>H190</name>
          </link>
        </links>
        <actionCode>8000</actionCode>
        <type>Floor</type>
        <committee />
      </item>
      <item>
        <actionDate>2017-01-06</actionDate>
        <text>Considered as privileged matter. (consideration: CR H190)</text>
        <sourceSystem>
          2
          <name>House floor actions</name>
        </sourceSystem>
        <actionTime>13:51:15</actionTime>
        <links>
          <link>
            <url>https://www.congress.gov/congressional-record/volume-163/house-section/page/H190</url>
            <name>H190</name>
          </link>
        </links>
        <actionCode>H30000</actionCode>
        <type>Floor</type>
        <committee />
      </item>
      <item>
        <actionDate>2017-01-06</actionDate>
        <text>Introduced in House</text>
        <sourceSystem>
          9
          <name>Library of Congress</name>
        </sourceSystem>
        <actionCode>Intro-H</actionCode>
        <type>IntroReferral</type>
        <links />
        <committee />
      </item>
      <item>
        <actionDate>2017-01-06</actionDate>
        <text>Introduced in House</text>
        <sourceSystem>
          9
          <name>Library of Congress</name>
        </sourceSystem>
        <actionCode>1000</actionCode>
        <type>IntroReferral</type>
        <links />
        <committee />
      </item>
      <actionTypeCounts>
        <passageOfAMeasure>1</passageOfAMeasure>
        <motionToReconsiderResults>1</motionToReconsiderResults>
        <considerationByHouse>1</considerationByHouse>
        <introducedInTheHouse>1</introducedInTheHouse>
        <passedAgreedToInHouse>1</passedAgreedToInHouse>
        <introducedInHouse>1</introducedInHouse>
      </actionTypeCounts>
      <actionByCounts>
        <houseOfRepresentatives>6</houseOfRepresentatives>
      </actionByCounts>
    </actions>
    <introducedDate>2017-01-06</introducedDate>
    <createDate>2017-01-07T04:48:24Z</createDate>
    <amendments />
    <committees>
      <billCommittees />
    </committees>
    <relatedBills />
    <billNumber>29</billNumber>
    <calendarNumbers />
    <title>Electing Members to certain standing committees of the House of Representatives.</title>
    <version>1.0.0</version>
    <titles>
      <item>
        <parentTitleType />
        <chamberCode />
        <title>Electing Members to certain standing committees of the House of Representatives.</title>
        <titleType>Official Title as Introduced</titleType>
        <chamberName />
      </item>
      <item>
        <parentTitleType />
        <chamberCode />
        <title>Electing Members to certain standing committees of the House of Representatives.</title>
        <titleType>Display Title</titleType>
        <chamberName />
      </item>
    </titles>
    <notes />
    <summaries>
      <billSummaries>
        <item>
          <versionCode>00</versionCode>
          <lastSummaryUpdateDate>2017-03-15T18:26:16Z</lastSummaryUpdateDate>
          <updateDate>2017-01-06T05:00:00Z</updateDate>
          <name>Introduced in House</name>
          <actionDesc>Introduced in House</actionDesc>
          <text><![CDATA[
Elects specified Members to the following House Committees: (1) Appropriations, (2) Energy and Commerce, (3) Financial Services, and (4) Ways and Means.
]]></text>
          <actionDate>2017-01-06</actionDate>
        </item>
        <item>
          <versionCode>81</versionCode>
          <lastSummaryUpdateDate>2017-03-15T18:26:24Z</lastSummaryUpdateDate>
          <updateDate>2017-01-06T14:18:43Z</updateDate>
          <name>Passed House without amendment</name>
          <actionDesc>Passed House without amendment</actionDesc>
          <text><![CDATA[
(This measure has not been amended since it was introduced. The summary of that version is repeated here.)

Elects specified Members to the following House Committees: (1) Appropriations, (2) Energy and Commerce, (3) Financial Services, and (4) Ways and Means.
]]></text>
          <actionDate>2017-01-06</actionDate>
        </item>
      </billSummaries>
    </summaries>
    <latestAction>
      <actionDate>2017-01-06</actionDate>
      <text>Motion to reconsider laid on the table Agreed to without objection.</text>
      <actionTime>13:51:30</actionTime>
      <links />
    </latestAction>
    <cosponsors />
    <sponsors>
      <item>
        <bioguideId>S001195</bioguideId>
        <identifiers>
          <gpoId />
          <bioguideId>S001195</bioguideId>
          <lisID>2191</lisID>
        </identifiers>
        <middleName />
        <firstName>Jason</firstName>
        <fullName>Rep. Smith, Jason [R-MO-8]</fullName>
        <byRequestType />
        <party>R</party>
        <lastName>Smith</lastName>
        <state>MO</state>
        <district>8</district>
      </item>
    </sponsors>
    <originChamber>House</originChamber>
    <recordedVotes />
    <policyArea>
      <name>Congress</name>
    </policyArea>
    <cboCostEstimates />
    <updateDate>2017-05-03T23:47:30Z</updateDate>
    <congress>115</congress>
    <billType>HRES</billType>
  </bill>
  <dublinCore xmlns:dc="http://purl.org/dc/elements/1.1/">
    <dc:format>text/xml</dc:format>
    <dc:language>EN</dc:language>
    <dc:rights>Pursuant to Title 17 Section 105 of the United States Code, this file is not subject to copyright protection and is in the public domain.</dc:rights>
    <dc:contributor>Congressional Research Service, Library of Congress</dc:contributor>
    <dc:description>This file contains bill summaries and statuses for federal legislation. A bill summary describes the most significant provisions of a piece of legislation and details the effects the legislative text may have on current law and federal programs. Bill summaries are authored by the Congressional Research Service (CRS) of the Library of Congress. As stated in Public Law 91-510 (2 USC 166 (d)(6)), one of the duties of CRS is "to prepare summaries and digests of bills and resolutions of a public general nature introduced in the Senate or House of Representatives". For more information, refer to the User Guide that accompanies this file.</dc:description>
  </dublinCore>
</billStatus>


text:
'use strict';

import * as React from 'react';
import {View, Image, Text, StyleSheet} from 'react-native';

export const RNTesterEmptyBookmarksState = (): React.Node => (
  <View style={styles.emptyContainer}>
    <View style={styles.emptyContainerInner}>
      <Image
        source={require('../assets/empty.png')}
        resizeMode="contain"
        style={styles.emptyImage}
      />
      <View>
        <Text style={styles.heading}>Bookmarks are empty</Text>
        <Text style={styles.subheading}>
          Please tap the{' '}
          <Image
            source={require('../assets/bookmark-outline-gray.png')}
            resizeMode="contain"
            style={styles.bookmarkIcon}
          />{' '}
          icon to bookmark examples.
        </Text>
      </View>
    </View>
  </View>
);

const styles = StyleSheet.create({
  emptyContainer: {
    flex: 1,
    paddingHorizontal: 40,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'white',
  },
  emptyContainerInner: {
    marginTop: -150,
  },
  emptyImage: {
    maxWidth: '100%',
    height: 300,
  },
  heading: {
    fontSize: 24,
    textAlign: 'center',
  },
  subheading: {
    fontSize: 16,
    textAlign: 'center',
  },
  bookmarkIcon: {
    width: 24,
    height: 24,
    transform: [{translateY: 4}],
  },
});