text:
package travel.ithaka.android.horizontalpicker;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

/**
 * Created by adityagohad on 06/06/17.
 */

public class PickerAdapter extends RecyclerView.Adapter<PickerAdapter.TextVH> {

    private Context context;
    private List<String> dataList;
    private RecyclerView recyclerView;

    public PickerAdapter(Context context, List<String> dataList, RecyclerView recyclerView) {
        this.context = context;
        this.dataList = dataList;
        this.recyclerView = recyclerView;
    }

    @Override
    public TextVH onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
        LayoutInflater inflater = LayoutInflater.from(context);
        view = inflater.inflate(R.layout.picker_item_layout, parent, false);
        return new PickerAdapter.TextVH(view);
    }

    @Override
    public void onBindViewHolder(TextVH holder, final int position) {
        TextVH textVH = holder;
        textVH.pickerTxt.setText(dataList.get(position));
        textVH.pickerTxt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (recyclerView != null) {
                    recyclerView.smoothScrollToPosition(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    public void swapData(List<String> newData) {
        dataList = newData;
        notifyDataSetChanged();
    }

    class TextVH extends RecyclerView.ViewHolder {
        TextView pickerTxt;

        public TextVH(View itemView) {
            super(itemView);
            pickerTxt = (TextView) itemView.findViewById(R.id.picker_item);
        }
    }
}


text:
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------
namespace TheS.Text
{
    using Runtime;
    using ServiceModel;
    using System;
    using System.Globalization;
    using System.Runtime;
    using System.Runtime.Serialization; //For SR
    using System.Security;
    using System.Text;

    class Base64Encoding : Encoding
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.SpacingRules", "SA1025:CodeMustNotContainMultipleWhitespaceInARow", Justification = "This alignment is optimal.")]
        static byte[] char2val = new byte[128]
        {
            /*    0-15 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
            /*   16-31 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
            /*   32-47 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,   62, 0xFF, 0xFF, 0xFF,   63,
            /*   48-63 */   52,   53,   54,   55,   56,   57,   58,   59,   60,   61, 0xFF, 0xFF, 0xFF,   64, 0xFF, 0xFF,
            /*   64-79 */ 0xFF,    0,    1,    2,    3,    4,    5,    6,    7,    8,    9,   10,   11,   12,   13,   14,
            /*   80-95 */   15,   16,   17,   18,   19,   20,   21,   22,   23,   24,   25, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
            /*  96-111 */ 0xFF,   26,   27,   28,   29,   30,   31,   32,   33,   34,   35,   36,   37,   38,   39,   40,
            /* 112-127 */   41,   42,   43,   44,   45,   46,   47,   48,   49,   50,   51, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        };

        static string val2char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
        static byte[] val2byte = new byte[]
        {
            (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G', (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N', (byte)'O', (byte)'P',
            (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', (byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z', (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f',
            (byte)'g', (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n', (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', (byte)'v',
            (byte)'w', (byte)'x', (byte)'y', (byte)'z', (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7', (byte)'8', (byte)'9', (byte)'+', (byte)'/'
        };

        public override int GetMaxByteCount(int charCount)
        {
            if (charCount < 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("charCount", "SR.ValueMustBeNonNegative"));
            if ((charCount % 4) != 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(string.Format("SR.XmlInvalidBase64Length, {0}", charCount.ToString(NumberFormatInfo.CurrentInfo))));
            return charCount / 4 * 3;
        }

        bool IsValidLeadBytes(int v1, int v2, int v3, int v4)
        {
            // First two chars of a four char base64 sequence can't be ==, and must be valid
            return ((v1 | v2) < 64) && ((v3 | v4) != 0xFF);
        }

        bool IsValidTailBytes(int v3, int v4)
        {
            // If the third char is = then the fourth char must be =
            return !(v3 == 64 && v4 != 64);
        }

        [Fx.Tag.SecurityNote(Critical = "Contains unsafe code.",
            Safe = "Unsafe code is effectively encapsulated, all inputs are validated.")]
        [SecuritySafeCritical]
        unsafe public override int GetByteCount(char[] chars, int index, int count)
        {
            if (chars == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("chars"));
            if (index < 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("index", "SR.ValueMustBeNonNegative"));
            if (index > chars.Length)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("index", string.Format("SR.OffsetExceedsBufferSize, {0}", chars.Length)));
            if (count < 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("count", "SR.ValueMustBeNonNegative"));
            if (count > chars.Length - index)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("count", string.Format("SR.SizeExceedsRemainingBufferSpace, {0}", chars.Length - index)));

            if (count == 0)
                return 0;
            if ((count % 4) != 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(string.Format("SR.XmlInvalidBase64Length, {0}", count.ToString(NumberFormatInfo.CurrentInfo))));
            fixed (byte* _char2val = char2val)
            {
                fixed (char* _chars = &chars[index])
                {
                    int totalCount = 0;
                    char* pch = _chars;
                    char* pchMax = _chars + count;
                    while (pch < pchMax)
                    {
                        Fx.Assert(pch + 4 <= pchMax, "");
                        char pch0 = pch[0];
                        char pch1 = pch[1];
                        char pch2 = pch[2];
                        char pch3 = pch[3];

                        if ((pch0 | pch1 | pch2 | pch3) >= 128)
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(string.Format("SR.XmlInvalidBase64Sequence, {0}, {1}", new string(pch, 0, 4), index + (int)(pch - _chars))));

                        // xx765432 xx107654 xx321076 xx543210
                        // 76543210 76543210 76543210
                        int v1 = _char2val[pch0];
                        int v2 = _char2val[pch1];
                        int v3 = _char2val[pch2];
                        int v4 = _char2val[pch3];

                        if (!IsValidLeadBytes(v1, v2, v3, v4) || !IsValidTailBytes(v3, v4))
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(string.Format("SR.XmlInvalidBase64Sequence, {0}, {1}", new string(pch, 0, 4), index + (int)(pch - _chars))));

                        int byteCount = (v4 != 64 ? 3 : (v3 != 64 ? 2 : 1));
                        totalCount += byteCount;
                        pch += 4;
                    }
                    return totalCount;
                }
            }
        }

        [Fx.Tag.SecurityNote(Critical = "Contains unsafe code.",
            Safe = "Unsafe code is effectively encapsulated, all inputs are validated.")]
        [SecuritySafeCritical]
        unsafe public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
        {
            if (chars == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("chars"));

            if (charIndex < 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("charIndex", "SR.ValueMustBeNonNegative"));
            if (charIndex > chars.Length)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("charIndex", string.Format("SR.OffsetExceedsBufferSize, {0}", chars.Length)));

            if (charCount < 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("charCount", "SR.ValueMustBeNonNegative"));
            if (charCount > chars.Length - charIndex)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("charCount", string.Format("SR.SizeExceedsRemainingBufferSpace, {0}", chars.Length - charIndex)));

            if (bytes == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("bytes"));
            if (byteIndex < 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("byteIndex", "SR.ValueMustBeNonNegative"));
            if (byteIndex > bytes.Length)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("byteIndex", string.Format("SR.OffsetExceedsBufferSize, {0}", bytes.Length)));

            if (charCount == 0)
                return 0;
            if ((charCount % 4) != 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(string.Format("SR.XmlInvalidBase64Length, {0}", charCount.ToString(NumberFormatInfo.CurrentInfo))));
            fixed (byte* _char2val = char2val)
            {
                fixed (char* _chars = &chars[charIndex])
                {
                    fixed (byte* _bytes = &bytes[byteIndex])
                    {
                        char* pch = _chars;
                        char* pchMax = _chars + charCount;
                        byte* pb = _bytes;
                        byte* pbMax = _bytes + bytes.Length - byteIndex;
                        while (pch < pchMax)
                        {
                            Fx.Assert(pch + 4 <= pchMax, "");
                            char pch0 = pch[0];
                            char pch1 = pch[1];
                            char pch2 = pch[2];
                            char pch3 = pch[3];

                            if ((pch0 | pch1 | pch2 | pch3) >= 128)
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(string.Format("SR.XmlInvalidBase64Sequence, {0}, {1}", new string(pch, 0, 4), charIndex + (int)(pch - _chars))));
                            // xx765432 xx107654 xx321076 xx543210
                            // 76543210 76543210 76543210

                            int v1 = _char2val[pch0];
                            int v2 = _char2val[pch1];
                            int v3 = _char2val[pch2];
                            int v4 = _char2val[pch3];

                            if (!IsValidLeadBytes(v1, v2, v3, v4) || !IsValidTailBytes(v3, v4))
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(string.Format("SR.XmlInvalidBase64Sequence, {0}, {1}", new string(pch, 0, 4), charIndex + (int)(pch - _chars))));

                            int byteCount = (v4 != 64 ? 3 : (v3 != 64 ? 2 : 1));
                            if (pb + byteCount > pbMax)
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException("SR.XmlArrayTooSmall", "bytes"));

                            pb[0] = (byte)((v1 << 2) | ((v2 >> 4) & 0x03));
                            if (byteCount > 1)
                            {
                                pb[1] = (byte)((v2 << 4) | ((v3 >> 2) & 0x0F));
                                if (byteCount > 2)
                                {
                                    pb[2] = (byte)((v3 << 6) | ((v4 >> 0) & 0x3F));
                                }
                            }
                            pb += byteCount;
                            pch += 4;
                        }
                        return (int)(pb - _bytes);
                    }
                }
            }
        }

        [Fx.Tag.SecurityNote(Critical = "Contains unsafe code.",
            Safe = "Unsafe code is effectively encapsulated, all inputs are validated.")]
        [SecuritySafeCritical]
        unsafe public virtual int GetBytes(byte[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
        {
            if (chars == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("chars"));
            if (charIndex < 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("charIndex", "SR.ValueMustBeNonNegative"));
            if (charIndex > chars.Length)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("charIndex", string.Format("SR.OffsetExceedsBufferSize, {0}", chars.Length)));

            if (charCount < 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("charCount", "SR.ValueMustBeNonNegative"));
            if (charCount > chars.Length - charIndex)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("charCount", string.Format("SR.SizeExceedsRemainingBufferSpace, {0}", chars.Length - charIndex)));

            if (bytes == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("bytes"));
            if (byteIndex < 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("byteIndex", "SR.ValueMustBeNonNegative"));
            if (byteIndex > bytes.Length)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("byteIndex", string.Format("SR.OffsetExceedsBufferSize, {0}", bytes.Length)));

            if (charCount == 0)
                return 0;
            if ((charCount % 4) != 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(string.Format("SR.XmlInvalidBase64Length, {0}", charCount.ToString(NumberFormatInfo.CurrentInfo))));
            fixed (byte* _char2val = char2val)
            {
                fixed (byte* _chars = &chars[charIndex])
                {
                    fixed (byte* _bytes = &bytes[byteIndex])
                    {
                        byte* pch = _chars;
                        byte* pchMax = _chars + charCount;
                        byte* pb = _bytes;
                        byte* pbMax = _bytes + bytes.Length - byteIndex;
                        while (pch < pchMax)
                        {
                            Fx.Assert(pch + 4 <= pchMax, "");
                            byte pch0 = pch[0];
                            byte pch1 = pch[1];
                            byte pch2 = pch[2];
                            byte pch3 = pch[3];
                            if ((pch0 | pch1 | pch2 | pch3) >= 128)
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(string.Format("SR.XmlInvalidBase64Sequence, {0} {1}", new string((sbyte*)pch, 0, 4), charIndex + (int)(pch - _chars))));
                            // xx765432 xx107654 xx321076 xx543210
                            // 76543210 76543210 76543210

                            int v1 = _char2val[pch0];
                            int v2 = _char2val[pch1];
                            int v3 = _char2val[pch2];
                            int v4 = _char2val[pch3];

                            if (!IsValidLeadBytes(v1, v2, v3, v4) || !IsValidTailBytes(v3, v4))
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(string.Format("SR.XmlInvalidBase64Sequence, {0}, {1}", new string((sbyte*)pch, 0, 4), charIndex + (int)(pch - _chars))));

                            int byteCount = (v4 != 64 ? 3 : (v3 != 64 ? 2 : 1));
                            if (pb + byteCount > pbMax)
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException("SR.XmlArrayTooSmall", "bytes"));

                            pb[0] = (byte)((v1 << 2) | ((v2 >> 4) & 0x03));
                            if (byteCount > 1)
                            {
                                pb[1] = (byte)((v2 << 4) | ((v3 >> 2) & 0x0F));
                                if (byteCount > 2)
                                {
                                    pb[2] = (byte)((v3 << 6) | ((v4 >> 0) & 0x3F));
                                }
                            }
                            pb += byteCount;
                            pch += 4;
                        }
                        return (int)(pb - _bytes);
                    }
                }
            }
        }
#if NO
        public override Encoder GetEncoder()
        {
            return new BufferedEncoder(this, 4);
        }

        public override Decoder GetDecoder()
        {
            return new BufferedDecoder(this, 3);
        }
#endif
        public override int GetMaxCharCount(int byteCount)
        {
            if (byteCount < 0 || byteCount > int.MaxValue / 4 * 3 - 2)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("byteCount", string.Format("SR.ValueMustBeInRange, {0}, {1}", 0, int.MaxValue / 4 * 3 - 2)));
            return ((byteCount + 2) / 3) * 4;
        }

        public override int GetCharCount(byte[] bytes, int index, int count)
        {
            return GetMaxCharCount(count);
        }

        [Fx.Tag.SecurityNote(Critical = "Contains unsafe code.",
            Safe = "Unsafe code is effectively encapsulated, all inputs are validated.")]
        [SecuritySafeCritical]
        unsafe public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
        {
            if (bytes == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("bytes"));
            if (byteIndex < 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("byteIndex", "SR.ValueMustBeNonNegative"));
            if (byteIndex > bytes.Length)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("byteIndex", string.Format("SR.OffsetExceedsBufferSize, {0}", bytes.Length)));
            if (byteCount < 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("byteCount", "SR.ValueMustBeNonNegative"));
            if (byteCount > bytes.Length - byteIndex)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("byteCount", string.Format("SR.SizeExceedsRemainingBufferSpace, {0}", bytes.Length - byteIndex)));

            int charCount = GetCharCount(bytes, byteIndex, byteCount);
            if (chars == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("chars"));
            if (charIndex < 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("charIndex", "SR.ValueMustBeNonNegative"));
            if (charIndex > chars.Length)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("charIndex", string.Format("SR.OffsetExceedsBufferSize, {0}", chars.Length)));
            if (charCount < 0 || charCount > chars.Length - charIndex)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException("SR.XmlArrayTooSmall", "chars"));

            // We've computed exactly how many chars there are and verified that
            // there's enough space in the char buffer, so we can proceed without
            // checking the charCount.

            if (byteCount > 0)
            {
                fixed (char* _val2char = val2char)
                {
                    fixed (byte* _bytes = &bytes[byteIndex])
                    {
                        fixed (char* _chars = &chars[charIndex])
                        {
                            byte* pb = _bytes;
                            byte* pbMax = pb + byteCount - 3;
                            char* pch = _chars;

                            // Convert chunks of 3 bytes to 4 chars
                            while (pb <= pbMax)
                            {
                                // 76543210 76543210 76543210
                                // xx765432 xx107654 xx321076 xx543210

                                // Inspect the code carefully before you change this
                                pch[0] = _val2char[(pb[0] >> 2)];
                                pch[1] = _val2char[((pb[0] & 0x03) << 4) | (pb[1] >> 4)];
                                pch[2] = _val2char[((pb[1] & 0x0F) << 2) | (pb[2] >> 6)];
                                pch[3] = _val2char[pb[2] & 0x3F];

                                pb += 3;
                                pch += 4;
                            }

                            // Handle 1 or 2 trailing bytes
                            if (pb - pbMax == 2)
                            {
                                // 1 trailing byte
                                // 76543210 xxxxxxxx xxxxxxxx
                                // xx765432 xx10xxxx xxxxxxxx xxxxxxxx
                                pch[0] = _val2char[(pb[0] >> 2)];
                                pch[1] = _val2char[((pb[0] & 0x03) << 4)];
                                pch[2] = '=';
                                pch[3] = '=';
                            }
                            else if (pb - pbMax == 1)
                            {
                                // 2 trailing bytes
                                // 76543210 76543210 xxxxxxxx
                                // xx765432 xx107654 xx3210xx xxxxxxxx
                                pch[0] = _val2char[(pb[0] >> 2)];
                                pch[1] = _val2char[((pb[0] & 0x03) << 4) | (pb[1] >> 4)];
                                pch[2] = _val2char[((pb[1] & 0x0F) << 2)];
                                pch[3] = '=';
                            }
                            else
                            {
                                // 0 trailing bytes
                                Fx.Assert(pb - pbMax == 3, "");
                            }
                        }
                    }
                }
            }

            return charCount;
        }

        [Fx.Tag.SecurityNote(Critical = "Contains unsafe code.",
            Safe = "Unsafe code is effectively encapsulated, all inputs are validated.")]
        [SecuritySafeCritical]
        unsafe public int GetChars(byte[] bytes, int byteIndex, int byteCount, byte[] chars, int charIndex)
        {
            if (bytes == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("bytes"));
            if (byteIndex < 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("byteIndex", "SR.ValueMustBeNonNegative"));
            if (byteIndex > bytes.Length)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("byteIndex", string.Format("SR.OffsetExceedsBufferSize, {0}", bytes.Length)));
            if (byteCount < 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("byteCount", "SR.ValueMustBeNonNegative"));
            if (byteCount > bytes.Length - byteIndex)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("byteCount", string.Format("SR.SizeExceedsRemainingBufferSpace, {0}", bytes.Length - byteIndex)));

            int charCount = GetCharCount(bytes, byteIndex, byteCount);
            if (chars == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("chars"));
            if (charIndex < 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("charIndex", "SR.ValueMustBeNonNegative"));
            if (charIndex > chars.Length)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("charIndex", string.Format("SR.OffsetExceedsBufferSize, {0}", chars.Length)));

            if (charCount < 0 || charCount > chars.Length - charIndex)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException("SR.XmlArrayTooSmall", "chars"));

            // We've computed exactly how many chars there are and verified that
            // there's enough space in the char buffer, so we can proceed without
            // checking the charCount.

            if (byteCount > 0)
            {
                fixed (byte* _val2byte = val2byte)
                {
                    fixed (byte* _bytes = &bytes[byteIndex])
                    {
                        fixed (byte* _chars = &chars[charIndex])
                        {
                            byte* pb = _bytes;
                            byte* pbMax = pb + byteCount - 3;
                            byte* pch = _chars;

                            // Convert chunks of 3 bytes to 4 chars
                            while (pb <= pbMax)
                            {
                                // 76543210 76543210 76543210
                                // xx765432 xx107654 xx321076 xx543210

                                // Inspect the code carefully before you change this
                                pch[0] = _val2byte[(pb[0] >> 2)];
                                pch[1] = _val2byte[((pb[0] & 0x03) << 4) | (pb[1] >> 4)];
                                pch[2] = _val2byte[((pb[1] & 0x0F) << 2) | (pb[2] >> 6)];
                                pch[3] = _val2byte[pb[2] & 0x3F];

                                pb += 3;
                                pch += 4;
                            }

                            // Handle 1 or 2 trailing bytes
                            if (pb - pbMax == 2)
                            {
                                // 1 trailing byte
                                // 76543210 xxxxxxxx xxxxxxxx
                                // xx765432 xx10xxxx xxxxxxxx xxxxxxxx
                                pch[0] = _val2byte[(pb[0] >> 2)];
                                pch[1] = _val2byte[((pb[0] & 0x03) << 4)];
                                pch[2] = (byte)'=';
                                pch[3] = (byte)'=';
                            }
                            else if (pb - pbMax == 1)
                            {
                                // 2 trailing bytes
                                // 76543210 76543210 xxxxxxxx
                                // xx765432 xx107654 xx3210xx xxxxxxxx
                                pch[0] = _val2byte[(pb[0] >> 2)];
                                pch[1] = _val2byte[((pb[0] & 0x03) << 4) | (pb[1] >> 4)];
                                pch[2] = _val2byte[((pb[1] & 0x0F) << 2)];
                                pch[3] = (byte)'=';
                            }
                            else
                            {
                                // 0 trailing bytes
                                Fx.Assert(pb - pbMax == 3, "");
                            }
                        }
                    }
                }
            }

            return charCount;
        }
    }
}

redpajama_set_name: RedPajamaGithub


text:
using System.Threading.Tasks;
using GitReleaseManager.Core.Commands;
using GitReleaseManager.Core.Options;
using NSubstitute;
using NUnit.Framework;
using Serilog;
using Shouldly;

namespace GitReleaseManager.Core.Tests.Commands
{
    [TestFixture]
    public class PublishCommandTests
    {
        private IVcsService _vcsService;
        private ILogger _logger;
        private PublishCommand _command;

        [SetUp]
        public void Setup()
        {
            _vcsService = Substitute.For<IVcsService>();
            _logger = Substitute.For<ILogger>();
            _command = new PublishCommand(_vcsService, _logger);
        }

        [Test]
        public async Task Should_Execute_Command()
        {
            var options = new PublishSubOptions
            {
                RepositoryOwner = "owner",
                RepositoryName = "repository",
                TagName = "0.1.0",
            };

            _vcsService.PublishReleaseAsync(options.RepositoryOwner, options.RepositoryName, options.TagName)
                .Returns(Task.CompletedTask);

            var result = await _command.Execute(options).ConfigureAwait(false);
            result.ShouldBe(0);

            await _vcsService.Received(1).PublishReleaseAsync(options.RepositoryOwner, options.RepositoryName, options.TagName).ConfigureAwait(false);
            _logger.Received(1).Information(Arg.Any<string>(), options.TagName);
        }
    }
}


text:
from __future__ import unicode_literals

from django.db import models
from django.utils import timezone
from morango.models import UUIDField

from kolibri.core.auth.models import AbstractFacilityDataModel
from kolibri.core.auth.models import FacilityUser
from kolibri.core.auth.permissions.general import IsOwn

class Bookmark(AbstractFacilityDataModel):

    content_id = UUIDField(blank=True, null=True)
    channel_id = UUIDField(blank=True, null=True)
    contentnode_id = UUIDField()
    user = models.ForeignKey(FacilityUser, blank=False)
    created = models.DateTimeField(default=timezone.now, db_index=True)

    morango_model_name = "bookmark"

    permissions = IsOwn()

    def infer_dataset(self, *args, **kwargs):
        return self.cached_related_dataset_lookup("user")

    def calculate_partition(self):
        return "{dataset_id}:user-rw:{user_id}".format(
            dataset_id=self.dataset_id, user_id=self.user.id
        )

    class Meta:
        # Ensures that we do not save duplicates, otherwise raises a
        # django.db.utils.IntegrityError
        unique_together = (
            "user",
            "contentnode_id",
        )


text:
/*
Create a class called Rational for performing arithematic with rational
numbers.

Use integer variables to represent the private instance variables of your
class numerator and denominator.

Write a constructor method that enables an object of this class to be
initialized when it is declared

Provide a no argument constructor with default values in case no initializers
are provided

Write methods for :
	addition
	subtraction
	multipy
	division
	printing in the form of a/b

Write a program to exercise the above stated class.
*/

class Rational
{
	int n,d;

	//default explicit constructor
	Rational()
	{
		n = d = 1;
	}

	//parametrized constructor
	Rational(int a, int b)
	{
		n=a;
		d=b;
	}

	public int GCF(int a, int b)
	{
		if (b == 0) return a;
		return (GCF(b, a % b));
	}

	public Rational addition(Rational second)
	{
		Rational answer = new Rational();
		int gcf = GCF(d, second.d);
		answer.d = (d*second.d)/gcf;
		answer.n = (n*second.d + second.n*d)/gcf;
		return answer;
	}

	public Rational subtraction(Rational second)
	{
		Rational answer = new Rational();
		int gcf = GCF(d, second.d);
		answer.d = (d*second.d)/gcf;
		answer.n = (n*second.d - second.n*d)/gcf;
		return answer;
	}

	public Rational division(Rational second)
	{
		Rational answer = new Rational();
		answer.d = (d*second.n);
		answer.n = (n*second.d);
		return answer;
	}

	public Rational multiplication(Rational second)
	{
		Rational answer = new Rational();
		answer.d = (d*second.d);
		answer.n = (n*second.n);
		return answer;
	}

	public void print()
	{
		System.out.println(n + "/" + d);
	}
}

class Worker
{
	public static void main(String args[])
	{
		Rational a = new Rational(4,6);
		Rational b = new Rational(1,6);

		Rational c = a.subtraction(b);
		c.print();

		Rational d = a.division(b);
		d.print();

		Rational e = a.multiplication(b);
		e.print();
	}
}


text:
using namespace foundation;
using namespace std;

namespace renderer
{

struct ScenePicker::Impl
{
    const Project&      m_project;
    const TraceContext& m_trace_context;
    TextureStore        m_texture_store;
    TextureCache        m_texture_cache;
    Intersector         m_intersector;

    explicit Impl(const Project& project)
      : m_project(project)
      , m_trace_context(m_project.get_trace_context())
      , m_texture_store(m_trace_context.get_scene())
      , m_texture_cache(m_texture_store)
      , m_intersector(m_trace_context, m_texture_cache)
    {
    }
};

ScenePicker::ScenePicker(const Project& project)
  : impl(new Impl(project))
{
}

ScenePicker::~ScenePicker()
{
    delete impl;
}

ScenePicker::PickingResult ScenePicker::pick(const Vector2d& ndc) const
{
    PickingResult result;

    result.m_hit = false;
    result.m_primitive_type = ShadingPoint::PrimitiveNone;
    result.m_distance = numeric_limits<double>::max();

    result.m_bary = Vector2f(0.0);
    result.m_uv = Vector2f(0.0);
    result.m_duvdx = Vector2f(0.0);
    result.m_duvdy = Vector2f(0.0);
    result.m_point = Vector3d(0.0);
    result.m_dpdu = Vector3d(0.0);
    result.m_dpdv = Vector3d(0.0);
    result.m_dndu = Vector3d(0.0);
    result.m_dndv = Vector3d(0.0);
    result.m_dpdx = Vector3d(0.0);
    result.m_dpdy = Vector3d(0.0);
    result.m_geometric_normal = Vector3d(0.0);
    result.m_original_shading_normal = Vector3d(0.0);
    result.m_side = ObjectInstance::FrontSide;

    result.m_camera = impl->m_project.get_uncached_active_camera();
    result.m_assembly_instance = nullptr;
    result.m_assembly = nullptr;
    result.m_object_instance = nullptr;
    result.m_object = nullptr;
    result.m_material = nullptr;
    result.m_surface_shader = nullptr;
    result.m_bsdf = nullptr;
    result.m_bssrdf = nullptr;
    result.m_edf = nullptr;

    if (result.m_camera == nullptr)
        return result;

    SamplingContext::RNGType rng;
    SamplingContext sampling_context(rng, SamplingContext::QMCMode);

    const CanvasProperties& c = impl->m_project.get_frame()->image().properties();
    const Vector2d ndc_dx(1.0 / (4.0 * c.m_canvas_width), 0.0);
    const Vector2d ndc_dy(0.0, -1.0 / (4.0 * c.m_canvas_height));

    ShadingRay ray;
    result.m_camera->spawn_ray(
        sampling_context,
        Dual2d(ndc, ndc_dx, ndc_dy),
        ray);

    ShadingPoint shading_point;
    impl->m_intersector.trace(ray, shading_point);

    result.m_hit = shading_point.hit_surface();

    if (!result.m_hit)
        return result;

    result.m_primitive_type = shading_point.get_primitive_type();
    result.m_distance = shading_point.get_distance() * norm(ray.m_dir);

    result.m_bary = shading_point.get_bary();
    result.m_uv = shading_point.get_uv(0);
    result.m_duvdx = shading_point.get_duvdx(0);
    result.m_duvdy = shading_point.get_duvdy(0);
    result.m_point = shading_point.get_point();
    result.m_dpdu = shading_point.get_dpdu(0);
    result.m_dpdv = shading_point.get_dpdv(0);
    result.m_dndu = shading_point.get_dndu(0);
    result.m_dndv = shading_point.get_dndv(0);
    result.m_dpdx = shading_point.get_dpdx();
    result.m_dpdy = shading_point.get_dpdy();
    result.m_geometric_normal = shading_point.get_geometric_normal();
    result.m_original_shading_normal = shading_point.get_original_shading_normal();
    result.m_side = shading_point.get_side();

    result.m_assembly_instance = &shading_point.get_assembly_instance();
    result.m_assembly_instance_transform = shading_point.get_assembly_instance_transform();
    result.m_assembly = &shading_point.get_assembly();
    result.m_object_instance = &shading_point.get_object_instance();
    result.m_object = &shading_point.get_object();

    const size_t pa_index = shading_point.get_primitive_attribute_index();

    if (pa_index != Triangle::None)
    {
        const char* material_name =
            result.m_object_instance->get_material_name(pa_index, shading_point.get_side());

        if (material_name)
        {
            result.m_material =
                InputBinder::find_entity<Material>(
                    material_name,
                    result.m_object_instance->get_parent());
        }
    }

    if (result.m_material)
    {
        const Entity* parent = result.m_material->get_parent();

        const char* ss_name = result.m_material->get_surface_shader_name();
        result.m_surface_shader = ss_name ? InputBinder::find_entity<SurfaceShader>(ss_name, parent) : nullptr;

        const char* bsdf_name = result.m_material->get_bsdf_name();
        result.m_bsdf = bsdf_name ? InputBinder::find_entity<BSDF>(bsdf_name, parent) : nullptr;

        const char* bssrdf_name = result.m_material->get_bssrdf_name();
        result.m_bssrdf = bssrdf_name ? InputBinder::find_entity<BSSRDF>(bssrdf_name, parent) : nullptr;

        const char* edf = result.m_material->get_edf_name();
        result.m_edf = edf ? InputBinder::find_entity<EDF>(edf, parent) : nullptr;
    }

    return result;
}

}   // namespace renderer


text:
class Dbt
  class TinyTdsDbConfig < AbstractDbConfig
    include Dbt::SqlServerConfig

    attr_writer :timeout

    def timeout
      @timeout || (60 * 5)
    end
  end

  class TinyTdsDbDriver < Dbt::BaseDbDriver
    include Dbt::Dialect::SqlServer

    def convert_value_for_fixture(value)
      value.is_a?(Time) ? "#{value.strftime('%d %b %Y %H:%M:%S')}" : value
    end

    def open(config, use_control_database)
      raise 'Can not open database connection. Connection already open.' if open?

      database = use_control_database ? 'msdb' : config.catalog_name

      require 'tiny_tds'

      @connection =
        TinyTds::Client.new(:host => config.host,
                            :port => config.port,
                            :appname => config.appname,
                            :database => database,
                            :timeout => config.timeout,
                            :username => config.username,
                            :password => config.password)
      # Configure the connection so it is more ANSI-like
      [
        'SET CURSOR_CLOSE_ON_COMMIT ON',
        'SET ANSI_NULLS ON',
        'SET ANSI_PADDING ON',
        'SET ANSI_WARNINGS ON',
        'SET ARITHABORT ON',
        'SET CONCAT_NULL_YIELDS_NULL ON',
        'SET QUOTED_IDENTIFIER ON',
        'SET NUMERIC_ROUNDABORT OFF'
      ].each do |sql|
        execute(sql, false)
      end
    end

    def execute(sql, execute_in_control_database = false)
      raise 'Can not execute statement when database connection is not open.' unless open?
      current_database = nil
      if execute_in_control_database
        current_database = self.current_database
        select_database(nil)
      end
      success = false
      begin
        @connection.execute(sql).do
        success = true
      ensure
        puts "Failed SQL: #{sql}" unless success
        select_database(current_database) if execute_in_control_database
      end
    end

    def query(sql)
      rs = @connection.execute(sql)

      results = []

      rs.each(:cache_rows => false) do |row|
        # Each row is now an array of values ordered by #fields.
        # Rows are yielded and forgotten about, freeing memory.
        results << row
      end
      rs.cancel
      results
    end

    def close
      if open?
        @connection.close rescue Exception
        @connection = nil
      end
    end

    protected

    def open?
      !@connection.nil?
    end
  end
end


text:
using System;
using Microsoft.AspNet.Http;
using System.Text.RegularExpressions;

namespace Offbeat.Middleware {
	public class DomainMappingRule : IRedirectRule {
		private string sourceDomain;

		private string destinationDomain;

		private bool permanentRedirect;

		private DomainMatchType matchType = DomainMatchType.StartsWith;

		internal DomainMappingRule(string sourceDomain, DomainMatchType matchType = DomainMatchType.StartsWith ) {
			this.sourceDomain = sourceDomain;
			this.permanentRedirect = true;
			this.matchType = matchType;
		}

		public DomainMappingRule ThenRedirectTo(string domain) {
			if (Regex.IsMatch(domain, "^https?://") == false) {
				destinationDomain = $"http://{domain}";
			}
			else {
				destinationDomain = domain;
			}
			return this;
		}

		public DomainMappingRule Temporary() {
			this.permanentRedirect = false;
			return this;
		}

		public bool Evaluate(HttpContext context) {
			if (MatchDomain(context) &&
				!context.Response.HasStarted) {

				var destinationUri = new Uri(destinationDomain);
				var originalpath = new Uri(context.Request.Path.Value, UriKind.Relative);
				var destinationUriAndPath = new Uri(destinationUri, originalpath);

				context.Response.Headers.Add("Location",
					new Microsoft.Extensions.Primitives.StringValues(
						destinationUriAndPath.ToString()));

				context.Response.StatusCode = permanentRedirect ? 301 : 302;

				return true;
			}
			return false;
		}

		private bool MatchDomain(HttpContext context) {
			if ( matchType == DomainMatchType.StartsWith ) {
				return context.Request.Host.ToString().StartsWith(sourceDomain, StringComparison.CurrentCultureIgnoreCase);
			}
			else if ( matchType == DomainMatchType.Exact) {
				return context.Request.Host.ToString().Equals(sourceDomain, StringComparison.CurrentCultureIgnoreCase);
			}

			throw new NotImplementedException();
		}
	}

	internal enum DomainMatchType {
		StartsWith,
		Exact
	}
}


text:
module HomeHelper

  def financial_class(financial_status)
    case financial_status
    when 'pending' then 'label-warning'
    when 'paid' then 'label-success'
    end
  end

  def fulfillment_class(fulfillment_status)
    case fulfillment_status
    when 'partial' then 'label-warning'
    when 'fulfilled' then 'label-success'
    end
  end

end


text:
<?php
namespace hash\password_hash_003;
/**Test PASSWORD_ARGON2I with options. */
$password = "rasmuslerdorf";
$memory_cost = 512;
$time_cost = 4;
$threads = 1;

$options = [
    'threads' => $threads,
    'time_cost' => $time_cost,
    'memory_cost' => $memory_cost,
];

$hashAllModifieded = @password_hash( $password, PASSWORD_ARGON2I, $options);
$hash = @password_hash( $password, PASSWORD_ARGON2I);

echo 'Verify hash with cost : ' . password_verify( $password, $hashAllModifieded) . "\n";
echo 'Verify hash without cost : ' . password_verify( $password, $hash) . "\n";


text:
require 'rubygems'
require 'webster'

@webster = Webster.new
10001.times { print @webster.random_word << " " }


text:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<title>JPype - Roadmap</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="style.css" rel="stylesheet" type="text/css" />

Home

Documentation

Roadmap

Download

Sourceforge Project

Links:

        Python

        Java

        Jython/JPython

Similar Projects :

        JEP

        JPE

Important Message Here. This template is free at www.r7designer.com!

		-->

Roadmap -

Following is a plan (as up to date as I can keep it) of the steps leading to the 1.0 release. For each release, there is a list of planned features. Also, I explain some of the ideas I ahve for this technology post 1.0.

0.1

Call any Java method.

Access any Java field.

Instantiate any Java class.

Provide wrapper classes.

Setup/shutdown JVM, along eith startup parameters like classpath, etc ...

0.2

Install via distutil

Add Object wrapper.

Support array types and Wrapper.

Allow access to interface constants thourgh a subclass' class or instance.

Support for Java Threading primitives.

Support for Java synchronized keyword.

0.3

Support Java dynamic proxies, so a python program can receive callback through any java interface.

Special support for listener classes to make them easier to use in Python.

0.4

Complete rebuild for modularity and easier movement forward.

0.5

Allow Java code to launch a Python instance. Needed for Java-hosted environments like Servlets.

Allow pre-generation of java proxy to Python classes.

	  ...

1.0

Allow subclassing of Java classes in Python.

Allow a python class to extends a java class and implement one or more Java interface.

Miscellaneous

	  Features in this list may make it in any release, and will be moved in that releases list once it has been decided.

Provide a Java Collection and wrapper.

Make Java classes more python-like. I.e. support __bases__, etc ...

Make Java instances more python-like, i.e. support __str__, __cmp__, __class__, etc ...

Support other platforms : MacOS X, etc ...

Beyond 1.0

After 1.0 will be released, a rewrite is planned. The goal of this re-write is to cleanly separate the JNI/Java interfacing logic from the Python code that uses it.

Once we got that, if there is interest, new hosting-code can be written to that other environments can use Java libraies. Logical candidates include Perl and Ruby and Parrot.

      You are looking at a Free Dreamweaver Template created by:

      http://www.r7designer.com


text:
""" xmpp request handler. """

## jsb imports

from jsb.utils.generic import fromenc, toenc
from jsb.lib.version import getversion
from jsb.utils.lazydict import LazyDict
from jsb.utils.exception import handle_exception
from jsb.lib.plugins import plugs
from jsb.lib.boot import boot, plugin_packages

## gaelib imports

from jsb.lib.gae.xmpp.bot import XMPPBot
from jsb.lib.gae.xmpp.event import XMPPEvent
from jsb.lib.gae.utils.auth import checkuser

## google imports

from google.appengine.api import xmpp
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import users as gusers
from google.appengine.ext import db
from google.appengine.ext.webapp import xmpp_handlers

## basic imports

import wsgiref.handlers
import sys
import time
import types
import logging

## boot

logging.info(getversion('GAE XMPP'))

boot()

## defines

bot = XMPPBot()

## functions

def xmppbox(response):
    response.out.write("""
          <form action="/_ah/xmpp/message/chat/" method="post">

enter command: <input type="commit" name="body">
          </form>
          """)

## classes

class XMPPHandler(webapp.RequestHandler):

    """ relay incoming messages to the bot. """

    def post(self):
        try:
            logging.info("XMPP incoming: %s" % self.request.remote_addr)

            if not self.request.POST.has_key('from'):
                logging.debug('no from in POST: %s' % str(self.request.POST))
                return

            if not self.request.POST.has_key('to'):
                logging.debug('no to in POST: %s' % str(self.request.POST))
                return

            event = XMPPEvent(bot=bot).parse(self.request, self.response)
            bot.doevent(event)

        except Exception, ex:
            handle_exception()
            #self.send_error(500)

application = webapp.WSGIApplication([('/_ah/xmpp/message/chat/', XMPPHandler), ],
                                      debug=True)

def main():
    global application
    global bot
    run_wsgi_app(application)

if __name__ == "__main__":
    main()


text:
layout: post
title:  Getting Started
categories: XAP97
weight: 100
parent: programmers-guide.html
---

{% summary %}This section will describe steps to setup your development environment to work with XAP{% endsummary %}
{% children %}


text:
//-----------------------------------------------------
//
// Author: Daeren
// Site: 666.io
//
//-----------------------------------------------------

/*jshint expr: true*/

"use strict";

//-----------------------------------------------------

const rChai     = require("chai");

const expect    = rChai.expect;

const rBot      = require("./../index");

//-----------------------------------------------------

const objBot            = rBot(process.env.TELEGRAM_BOT_TOKEN);
const objSrvOptions     = {
    "certDir":   "/www/site",

    "key":       "/3_site.xx.key",
    "cert":      "/2_site.xx.crt",
    "ca":       [
        "/AddTrustExternalCARoot.crt",
        "/COMODORSAAddTrustCA.crt",
        "/COMODORSADomainValidationSecureServerCA.crt"
    ],

    "host":     "site.xx"
};

//------------------]>

objBot
    .api
    .setWebhook({"url": "https://site.xx/botX"})

    .then(isOk => {
        expect(isOk).to.be.a("boolean");

        if(!isOk) {
            throw new Error("Oops...problems with webhook...");
        }

        objBot
            .http(objSrvOptions, cbMsg)
            .on("/start", cbCmdStart);
    }, function(error) {
        expect(error).to.be.an.instanceof(Error);

        console.error(error);
    });

//------------------]>

function cbMsg(bot) {
    const cmd = bot.command;

    if(cmd) {
        expect(cmd).to.be.a("object");

        expect(cmd).to.have.property("name");
        expect(cmd).to.have.property("text");
        expect(cmd).to.have.property("cmd");
    }

    //----------]>

    tCheckBaseBotFields(bot);

    //----------]>

    let commands = {
        "help": x => bot.answer().text(x).send()
    };

    let cmdFunc,
        cmdParams = bot.parseCmd(bot.message.text);

    if(cmdParams) {
        (cmdFunc = commands[cmdParams.name]) ? cmdFunc(cmdParams) : console.log(cmdParams);
    }

    //--------------]>

    bot.answer().text("Hell Word!").send();
}

function cbCmdStart(bot, params) {
    tCheckBaseBotFields(bot);

    expect(params).to.be.an("object");

    //----------]>

    bot.answer().text("CMD: /start").send();
}

//-------------]>

function tCheckBaseBotFields(bot) {
    expect(bot).to.be.a("object");
    expect(bot).to.have.property("message").that.is.an("object");

    //----------]>

    const msg = bot.message;

    expect(msg).to.have.property("message_id");
    expect(msg).to.have.property("from").that.is.an("object");
    expect(msg).to.have.property("chat").that.is.an("object");
    expect(msg).to.have.property("date");

    expect(bot).to.have.property("isGroup").that.is.an("boolean");
    expect(bot).to.have.property("isReply").that.is.an("boolean");

    expect(bot).to.have.property("cid").that.equal(msg.chat.id);
    expect(bot).to.have.property("mid").that.equal(msg.message_id);

    //----------]>

    expect(bot).to.have.property("answer").that.is.an("function");
}


text:
@interface SKFormTextField ()

@end

@implementation SKFormTextField {
    BOOL hasSetuped;
}

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];

    if (self) {
        [self initVars];
        [self setup];
    }

    return self;
}

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];

    if (self) {
        [self initVars];
        [self setup];
    }

    return self;
}

- (void)drawRect:(CGRect)rect {
    // Update UI elements
    [self updateUI];
}

- (void)initVars {
    // Initialize default values
    self.textFieldState = SKFormTextFieldStateDefault;
    self.mode = SKFormTextFieldModeWrite;
    self.lineNormalColor = [[UIColor blackColor] colorWithAlphaComponent:0.12];
    self.lineActiveColor = ACTIVE_COLOR;
    self.lineValidColor = [[UIColor blackColor] colorWithAlphaComponent:0.12];
    self.lineErrorColor = ERROR_COLOR;
    self.descriptionNormalColor = NORMAL_COLOR;
    self.descriptionActiveColor = NORMAL_COLOR;
    self.descriptionValidColor = VALID_COLOR;
    self.descriptionErrorColor = ERROR_COLOR;
    self.placeholderText = @"";
    self.descriptionText = @"";
    self.errorMessageText = @"";
    self.textViewHeight = DEFAULT_TEXT_FIELD_HEIGHT;
}

- (void)setup {
    // Check if view has already been setuped
    if (!hasSetuped) {
        // Create and add views to main view
        if (!self.leftButton) {
            self.leftButton = [UIButton new];
            self.leftButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
            if (self.leftButtonImage) {
                [self.leftButton setImage:self.leftButtonImage forState:UIControlStateNormal];
            }
            [self addSubview:self.leftButton];
        }
        if (!self.textField) {
            self.textField = [UITextField new];

            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldDidBeginEditing:) name:UITextFieldTextDidBeginEditingNotification object:nil];
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldDidEndEditing:) name:UITextFieldTextDidEndEditingNotification object:nil];

            self.textField.font = [UIFont fontWithName:@"Roboto-Regular" size:14];
            self.textField.placeholder = self.placeholderText;
            [self addSubview:self.textField];
        }
        if (!self.datePicker) {
            self.dateFormatter = [NSDateFormatter new];
            [self.dateFormatter setDateFormat:@"dd/MM/yyyy"];
        }
        if (!self.datePicker) {
            self.datePicker = [UIDatePicker new];
            self.datePicker.backgroundColor = [UIColor whiteColor];
            [self.datePicker addTarget:self action:@selector(datePickerDidChange:) forControlEvents:UIControlEventValueChanged];
            self.datePicker.datePickerMode = UIDatePickerModeDate;
        }
        if (!self.textView) {
            self.textView = [SKTextView new];

            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textViewDidBeginEditing:) name:UITextViewTextDidBeginEditingNotification object:nil];
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textViewDidEndEditing:) name:UITextViewTextDidEndEditingNotification object:nil];

            self.textView.font = [UIFont fontWithName:@"Roboto-Regular" size:14];
            self.textView.placeholderText = self.placeholderText;
            [self addSubview:self.textView];
            self.textView.hidden = YES;
        }
        if (!self.rightButton) {
            self.rightButton = [UIButton new];
            self.rightButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
            if (self.rightButtonImage) {
                [self.rightButton setImage:self.rightButtonImage forState:UIControlStateNormal];
            }
            [self addSubview:self.rightButton];
        }
        if (!self.line) {
            self.line = [UIView new];
            self.line.backgroundColor = self.lineNormalColor;
            [self addSubview:self.line];
        }
        if (!self.leftDescriptionIcon) {
            self.leftDescriptionIcon = [UIImageView new];
            self.leftDescriptionIcon.contentMode = UIViewContentModeScaleAspectFit;
            if (self.leftIconImage) {
                self.leftDescriptionIcon.image = self.leftIconImage;
            }
            [self addSubview:self.leftDescriptionIcon];
        }
        if (!self.descriptionLabel) {
            self.descriptionLabel = [UILabel new];
            self.descriptionLabel.font = [UIFont fontWithName:@"Roboto-Regular" size:12];
            self.descriptionLabel.textColor = self.descriptionNormalColor;
            self.descriptionLabel.numberOfLines = 0;
            self.descriptionLabel.preferredMaxLayoutWidth = self.descriptionLabel.frame.size.width;
            self.descriptionLabel.lineBreakMode = NSLineBreakByWordWrapping;
            self.descriptionLabel.text = self.descriptionText;
            [self addSubview:self.descriptionLabel];
        }
        if (!self.rightDescriptionIcon) {
            self.rightDescriptionIcon = [UIImageView new];
            self.rightDescriptionIcon.contentMode = UIViewContentModeScaleAspectFit;
            if (self.rightIconImage) {
                self.rightDescriptionIcon.image = self.rightIconImage;
            }
            [self addSubview:self.rightDescriptionIcon];
        }

        // Add constraints

        // left button
        self.leftButton.translatesAutoresizingMaskIntoConstraints = NO;
        self.leftButtonHeightConstraint =
        [NSLayoutConstraint constraintWithItem:self.leftButton
                                     attribute:NSLayoutAttributeHeight
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:nil
                                     attribute:NSLayoutAttributeNotAnAttribute
                                    multiplier:1.0
                                      constant:24];
        self.leftButtonWidthConstraint =
        [NSLayoutConstraint constraintWithItem:self.leftButton
                                     attribute:NSLayoutAttributeWidth
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:nil
                                     attribute:NSLayoutAttributeNotAnAttribute
                                    multiplier:1.0
                                      constant:24];
        NSLayoutConstraint *leftButtonLeftConstaint =
        [NSLayoutConstraint constraintWithItem:self.leftButton
                                     attribute:NSLayoutAttributeLeft
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self
                                     attribute:NSLayoutAttributeLeft
                                    multiplier:1.0
                                      constant:0];
        NSLayoutConstraint *leftButtonVerticalCenterConstaint =
        [NSLayoutConstraint constraintWithItem:self.leftButton
                                     attribute:NSLayoutAttributeCenterY
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.textField
                                     attribute:NSLayoutAttributeCenterY
                                    multiplier:1.0
                                      constant:0];
        [self addConstraints:@[self.leftButtonHeightConstraint, self.leftButtonWidthConstraint, leftButtonLeftConstaint, leftButtonVerticalCenterConstaint]];

        // text field
        self.textField.translatesAutoresizingMaskIntoConstraints = NO;
        self.textFieldHeightConstraint =
        [NSLayoutConstraint constraintWithItem:self.textField
                                     attribute:NSLayoutAttributeHeight
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:nil
                                     attribute:NSLayoutAttributeNotAnAttribute
                                    multiplier:1.0
                                      constant:self.textViewHeight];
        NSLayoutConstraint *textFieldTopConstaint =
        [NSLayoutConstraint constraintWithItem:self.textField
                                     attribute:NSLayoutAttributeTop
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self
                                     attribute:NSLayoutAttributeTop
                                    multiplier:1.0
                                      constant:0];
        NSLayoutConstraint *textFieldBottomConstaint =
        [NSLayoutConstraint constraintWithItem:self.textField
                                     attribute:NSLayoutAttributeBottom
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.line
                                     attribute:NSLayoutAttributeTop
                                    multiplier:1.0
                                      constant:0];
        self.textFieldLeftConstraint =
        [NSLayoutConstraint constraintWithItem:self.textField
                                     attribute:NSLayoutAttributeLeft
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.leftButton
                                     attribute:NSLayoutAttributeRight
                                    multiplier:1.0
                                      constant:8];
        self.textFieldRightConstraint =
        [NSLayoutConstraint constraintWithItem:self.textField
                                     attribute:NSLayoutAttributeRight
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.rightButton
                                     attribute:NSLayoutAttributeLeft
                                    multiplier:1.0
                                      constant:-8];
        [self addConstraints:@[self.textFieldHeightConstraint, textFieldTopConstaint, textFieldBottomConstaint, self.textFieldLeftConstraint, self.textFieldRightConstraint]];

        // textView
        self.textView.translatesAutoresizingMaskIntoConstraints = NO;
        NSLayoutConstraint *textViewTopConstraint =
        [NSLayoutConstraint constraintWithItem:self.textView
                                     attribute:NSLayoutAttributeTop
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.textField
                                     attribute:NSLayoutAttributeTop
                                    multiplier:1.0
                                      constant:0];
        NSLayoutConstraint *textViewLeftConstraint =
        [NSLayoutConstraint constraintWithItem:self.textView
                                     attribute:NSLayoutAttributeLeft
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.textField
                                     attribute:NSLayoutAttributeLeft
                                    multiplier:1.0
                                      constant:0];
        NSLayoutConstraint *textViewBottomConstraint =
        [NSLayoutConstraint constraintWithItem:self.textView
                                     attribute:NSLayoutAttributeBottom
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.textField
                                     attribute:NSLayoutAttributeBottom
                                    multiplier:1.0
                                      constant:0];
        NSLayoutConstraint *textViewRightConstraint =
        [NSLayoutConstraint constraintWithItem:self.textView
                                     attribute:NSLayoutAttributeRight
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.textField
                                     attribute:NSLayoutAttributeRight
                                    multiplier:1.0
                                      constant:0];
        [self addConstraints:@[textViewTopConstraint, textViewLeftConstraint, textViewBottomConstraint, textViewRightConstraint]];

        // right button
        self.rightButton.translatesAutoresizingMaskIntoConstraints = NO;
        self.rightButtonHeightConstraint =
        [NSLayoutConstraint constraintWithItem:self.rightButton
                                     attribute:NSLayoutAttributeHeight
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:nil
                                     attribute:NSLayoutAttributeNotAnAttribute
                                    multiplier:1.0
                                      constant:24];
        self.rightButtonWidthConstraint =
        [NSLayoutConstraint constraintWithItem:self.rightButton
                                     attribute:NSLayoutAttributeWidth
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:nil
                                     attribute:NSLayoutAttributeNotAnAttribute
                                    multiplier:1.0
                                      constant:24];
        NSLayoutConstraint *rightButtonLeftConstaint =
        [NSLayoutConstraint constraintWithItem:self.rightButton
                                     attribute:NSLayoutAttributeRight
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self
                                     attribute:NSLayoutAttributeRight
                                    multiplier:1.0
                                      constant:0];
        NSLayoutConstraint *rightButtonVerticalCenterConstaint =
        [NSLayoutConstraint constraintWithItem:self.rightButton
                                     attribute:NSLayoutAttributeCenterY
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.textField
                                     attribute:NSLayoutAttributeCenterY
                                    multiplier:1.0
                                      constant:0];
        [self addConstraints:@[self.rightButtonHeightConstraint, self.rightButtonWidthConstraint, rightButtonLeftConstaint, rightButtonVerticalCenterConstaint]];

        // line
        self.line.translatesAutoresizingMaskIntoConstraints = NO;
        NSLayoutConstraint *lineLeftConstraint =
        [NSLayoutConstraint constraintWithItem:self.line
                                     attribute:NSLayoutAttributeLeft
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self
                                     attribute:NSLayoutAttributeLeft
                                    multiplier:1.0
                                      constant:0];
        NSLayoutConstraint *lineRightConstraint =
        [NSLayoutConstraint constraintWithItem:self.line
                                     attribute:NSLayoutAttributeRight
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self
                                     attribute:NSLayoutAttributeRight
                                    multiplier:1.0
                                      constant:0];
        self.lineHeightConstraint =
        [NSLayoutConstraint constraintWithItem:self.line
                                     attribute:NSLayoutAttributeHeight
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:nil
                                     attribute:NSLayoutAttributeNotAnAttribute
                                    multiplier:1.0
                                      constant:1];
        [self addConstraints:@[lineLeftConstraint, lineRightConstraint, self.lineHeightConstraint]];

        // left icon
        self.leftDescriptionIcon.translatesAutoresizingMaskIntoConstraints = NO;
        self.leftImageHeightConstraint =
        [NSLayoutConstraint constraintWithItem:self.leftDescriptionIcon
                                     attribute:NSLayoutAttributeHeight
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:nil
                                     attribute:NSLayoutAttributeNotAnAttribute
                                    multiplier:1.0
                                      constant:18];
        self.leftImageWidthConstraint =
        [NSLayoutConstraint constraintWithItem:self.leftDescriptionIcon
                                     attribute:NSLayoutAttributeWidth
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:nil
                                     attribute:NSLayoutAttributeNotAnAttribute
                                    multiplier:1.0
                                      constant:18];
        NSLayoutConstraint *leftDescriptionIconLeftConstaint =
        [NSLayoutConstraint constraintWithItem:self.leftDescriptionIcon
                                     attribute:NSLayoutAttributeLeft
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self
                                     attribute:NSLayoutAttributeLeft
                                    multiplier:1.0
                                      constant:0];
        NSLayoutConstraint *leftDescriptionIconVerticalCenterConstaint =
        [NSLayoutConstraint constraintWithItem:self.leftDescriptionIcon
                                     attribute:NSLayoutAttributeCenterY
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.descriptionLabel
                                     attribute:NSLayoutAttributeCenterY
                                    multiplier:1.0
                                      constant:0];
        [self addConstraints:@[self.leftImageHeightConstraint, self.leftImageWidthConstraint, leftDescriptionIconLeftConstaint, leftDescriptionIconVerticalCenterConstaint]];

        // description label
        self.descriptionLabel.translatesAutoresizingMaskIntoConstraints = NO;
        self.descriptionToLineConstraint =
        [NSLayoutConstraint constraintWithItem:self.descriptionLabel
                                     attribute:NSLayoutAttributeTop
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.line
                                     attribute:NSLayoutAttributeBottom
                                    multiplier:1.0
                                      constant:4];
        NSLayoutConstraint *descriptionLabelBottomConstaint =
        [NSLayoutConstraint constraintWithItem:self.descriptionLabel
                                     attribute:NSLayoutAttributeBottom
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self
                                     attribute:NSLayoutAttributeBottom
                                    multiplier:1.0
                                      constant:0];
        self.descriptionLabelLeftConstraint =
        [NSLayoutConstraint constraintWithItem:self.descriptionLabel
                                     attribute:NSLayoutAttributeLeft
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.leftDescriptionIcon
                                     attribute:NSLayoutAttributeRight
                                    multiplier:1.0
                                      constant:8];
        self.descriptionLabelRightConstraint =
        [NSLayoutConstraint constraintWithItem:self.descriptionLabel
                                     attribute:NSLayoutAttributeRight
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.rightDescriptionIcon
                                     attribute:NSLayoutAttributeLeft
                                    multiplier:1.0
                                      constant:-8];
        [self addConstraints:@[self.descriptionToLineConstraint, descriptionLabelBottomConstaint, self.descriptionLabelLeftConstraint, self.descriptionLabelRightConstraint]];

        // right icon
        self.rightDescriptionIcon.translatesAutoresizingMaskIntoConstraints = NO;
        self.rightImageHeightConstraint =
        [NSLayoutConstraint constraintWithItem:self.rightDescriptionIcon
                                     attribute:NSLayoutAttributeHeight
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:nil
                                     attribute:NSLayoutAttributeNotAnAttribute
                                    multiplier:1.0
                                      constant:18];
        self.rightImageWidthConstraint =
        [NSLayoutConstraint constraintWithItem:self.rightDescriptionIcon
                                     attribute:NSLayoutAttributeWidth
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:nil
                                     attribute:NSLayoutAttributeNotAnAttribute
                                    multiplier:1.0
                                      constant:18];
        NSLayoutConstraint *rightDescriptionIconLeftConstaint =
        [NSLayoutConstraint constraintWithItem:self.rightDescriptionIcon
                                     attribute:NSLayoutAttributeRight
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self
                                     attribute:NSLayoutAttributeRight
                                    multiplier:1.0
                                      constant:0];
        NSLayoutConstraint *rightDescriptionIconVerticalCenterConstaint =
        [NSLayoutConstraint constraintWithItem:self.rightDescriptionIcon
                                     attribute:NSLayoutAttributeCenterY
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.descriptionLabel
                                     attribute:NSLayoutAttributeCenterY
                                    multiplier:1.0
                                      constant:0];
        [self addConstraints:@[self.rightImageHeightConstraint, self.rightImageWidthConstraint, rightDescriptionIconLeftConstaint, rightDescriptionIconVerticalCenterConstaint]];

        hasSetuped = YES;
    }
}

- (void)updateUI {
    if (self.textFieldState == SKFormTextFieldStateDefault) {
        self.line.backgroundColor = self.lineNormalColor;
    } else if (self.textFieldState == SKFormTextFieldStateActive) {
        self.line.backgroundColor = self.lineActiveColor;
    }

    self.textField.placeholder = self.placeholderText;
    self.textView.placeholderText = self.placeholderText;

    if (self.leftButtonImage) {
        [self.leftButton setImage:self.leftButtonImage forState:UIControlStateNormal];
    }
    if (self.rightButtonImage) {
        [self.rightButton setImage:self.rightButtonImage forState:UIControlStateNormal];
    }

    if (self.leftIconImage) {
        self.leftDescriptionIcon.image = self.leftIconImage;
    }
    if (self.rightIconImage) {
        self.rightDescriptionIcon.image = self.rightIconImage;
    }

    if (self.leftButtonHidden) {
        [self hideButtonAtSide:SKFormTextFieldSideLeft];
    } else {
        [self showButtonAtSide:SKFormTextFieldSideLeft];
    }
    if (self.rightButtonHidden) {
        [self hideButtonAtSide:SKFormTextFieldSideRight];
    } else {
        [self showButtonAtSide:SKFormTextFieldSideRight];
    }
    if (self.leftIconHidden) {
        [self hideDescriptionIconAtSide:SKFormTextFieldSideLeft];
    } else {
        [self showDescriptionIconAtSide:SKFormTextFieldSideLeft];
    }
    if (self.rightIconHidden) {
        [self hideDescriptionIconAtSide:SKFormTextFieldSideRight];
    } else {
        [self showDescriptionIconAtSide:SKFormTextFieldSideRight];
    }

    self.textFieldHeightConstraint.constant = self.textViewHeight;

    [self checkTextFieldState];

    if (self.mode == SKFormTextFieldModeRead) {
        if (self.type == SKFormTextFieldTypeTextField) {
            self.textField.userInteractionEnabled = false;
        } else if (self.type == SKFormTextFieldTypeTextFieldDate) {
            self.textField.userInteractionEnabled = false;
        } else if (self.type == SKFormTextFieldTypeTextView) {
            self.textView.userInteractionEnabled = false;
        }

        if (!self.doNotHideLineWhenRead) {
            self.lineHeightConstraint.constant = 0;
        }

        self.line.hidden = !self.doNotHideLineWhenRead;
    } else {
        if (self.type == SKFormTextFieldTypeTextField) {
            self.textField.userInteractionEnabled = true;
        } else if (self.type == SKFormTextFieldTypeTextFieldDate) {
            self.textField.userInteractionEnabled = true;
        } else if (self.type == SKFormTextFieldTypeTextView) {
            self.textView.userInteractionEnabled = true;
        }
    }

    [self setNeedsUpdateConstraints];
}

- (void)prepareForInterfaceBuilder {
    [super prepareForInterfaceBuilder];

    [self updateUI];
}

- (void)checkTextFieldState {
    if (self.textFieldState == SKFormTextFieldStateActive) {
        // set description text to normal
        self.descriptionLabel.textColor = self.descriptionActiveColor;
        self.descriptionLabel.text = self.descriptionText;

        // set line to active state
        self.line.backgroundColor = self.lineActiveColor;
        self.lineHeightConstraint.constant = (self.hideLine ? 0 : 2);

        // reduce margin between line and description to prevent description text from hiding
        self.descriptionToLineConstraint.constant = (self.hideLine ? 0 : 3);

        // show normal icon if available
        if (self.rightDescriptionIcon) {
            self.rightDescriptionIcon.image = self.rightIconImage;
            if (!self.rightIconHidden) {
                [self showDescriptionIconAtSide:SKFormTextFieldSideRight];
            } else {
                [self hideDescriptionIconAtSide:SKFormTextFieldSideRight];
            }
        }
    } else if (self.textFieldState == SKFormTextFieldStateValid) {
        // set description text to normal
        self.descriptionLabel.textColor = self.descriptionValidColor;
        self.descriptionLabel.text = self.descriptionText;

        // set line to normal state
        self.line.backgroundColor = self.lineNormalColor;
        self.lineHeightConstraint.constant = (self.hideLine ? 0 : 1);

        // reduce margin between line and description to prevent description text from hiding
        self.descriptionToLineConstraint.constant = (self.hideLine ? 0 : 4);

        // show normal icon if available
        if (self.rightDescriptionIcon) {
            self.rightDescriptionIcon.image = self.rightIconImage;
            if (!self.rightIconHidden) {
                [self showDescriptionIconAtSide:SKFormTextFieldSideRight];
            } else {
                [self hideDescriptionIconAtSide:SKFormTextFieldSideRight];
            }
        }
    } else if (self.textFieldState == SKFormTextFieldStateInvalid) {
        // set error message
        self.descriptionLabel.textColor = self.descriptionErrorColor;
        self.descriptionLabel.text = self.errorMessageText;

        // set line to normal state
        self.line.backgroundColor = self.lineErrorColor;
        self.lineHeightConstraint.constant = (self.hideLine ? 0 : 2);

        // reduce margin between line and description to prevent description text from hiding
        self.descriptionToLineConstraint.constant = (self.hideLine ? 0 : 3);

        // show error icon
        if (self.errorImage) {
            self.rightDescriptionIcon.image = self.errorImage;
            [self showDescriptionIconAtSide:SKFormTextFieldSideRight];
        } else {
            [self hideDescriptionIconAtSide:SKFormTextFieldSideRight];
        }
    } else {
        // set description text to normal
        self.descriptionLabel.textColor = self.descriptionNormalColor;
        self.descriptionLabel.text = self.descriptionText;

        // set line to normal state
        self.line.backgroundColor = self.lineNormalColor;
        self.lineHeightConstraint.constant = (self.hideLine ? 0 : 1);

        // reduce margin between line and description to prevent description text from hiding
        self.descriptionToLineConstraint.constant = (self.hideLine ? 0 : 4);

        // show normal icon if available
        if (self.rightDescriptionIcon) {
            self.rightDescriptionIcon.image = self.rightIconImage;
            if (!self.rightIconHidden) {
                [self showDescriptionIconAtSide:SKFormTextFieldSideRight];
            } else {
                [self hideDescriptionIconAtSide:SKFormTextFieldSideRight];
            }
        }
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];

    self.descriptionLabel.preferredMaxLayoutWidth = self.descriptionLabel.frame.size.width;
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidBeginEditingNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidEndEditingNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextViewTextDidBeginEditingNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextViewTextDidEndEditingNotification object:nil];
}

#pragma mark - Methods
#pragma mark -

- (void)setType:(SKFormTextFieldType)type animated:(BOOL)animated {
    self.type = type;

    if (animated) {
        if (type == SKFormTextFieldTypeTextField) {
            self.textView.hidden = YES;
            self.textField.hidden = NO;
            self.textField.inputView = nil;
        } else if (type == SKFormTextFieldTypeTextFieldDate) {
            self.textView.hidden = YES;
            self.textField.hidden = NO;
            self.textField.inputView = self.datePicker;
        } else if (type == SKFormTextFieldTypeTextView) {
            self.textField.hidden = YES;
            self.textView.hidden = NO;
        }

        [UIView animateWithDuration:0.345 delay:0 usingSpringWithDamping:1.0 initialSpringVelocity:0.5 options:0 animations:^{
            [self layoutIfNeeded];
        } completion:nil];
    } else {
        if (type == SKFormTextFieldTypeTextField) {
            self.textView.hidden = YES;
            self.textField.hidden = NO;
        } else if (type == SKFormTextFieldTypeTextFieldDate) {
            self.textView.hidden = YES;
            self.textField.hidden = NO;
            self.textField.inputView = self.datePicker;
        } else if (type == SKFormTextFieldTypeTextView) {
            self.textField.hidden = YES;
            self.textView.hidden = NO;
        }
    }
}

- (void)showButtonAtSide:(SKFormTextFieldSide)side {
    if (side == SKFormTextFieldSideBoth) {
        self.leftButton.hidden = NO;
        self.rightButton.hidden = NO;

        self.textFieldLeftConstraint.constant = 8;
        self.leftButtonWidthConstraint.constant = 24;
        self.leftButtonHeightConstraint.constant = 24;

        self.textFieldRightConstraint.constant = -8;
        self.rightButtonWidthConstraint.constant = 24;
        self.rightButtonHeightConstraint.constant = 24;
    } else if (side == SKFormTextFieldSideLeft) {
        self.leftButton.hidden = NO;

        self.textFieldLeftConstraint.constant = 8;
        self.leftButtonWidthConstraint.constant = 24;
        self.leftButtonHeightConstraint.constant = 24;
    } else if (side == SKFormTextFieldSideRight) {
        self.rightButton.hidden = NO;

        self.textFieldRightConstraint.constant = -8;
        self.rightButtonWidthConstraint.constant = 24;
        self.rightButtonHeightConstraint.constant = 24;
    }
}

- (void)hideButtonAtSide:(SKFormTextFieldSide)side {
    if (side == SKFormTextFieldSideBoth) {
        self.leftButton.hidden = YES;
        self.rightButton.hidden = YES;

        self.textFieldLeftConstraint.constant = 0;
        self.leftButtonWidthConstraint.constant = 0;
        self.leftButtonHeightConstraint.constant = 0;

        self.textFieldRightConstraint.constant = 0;
        self.rightButtonWidthConstraint.constant = 0;
        self.rightButtonHeightConstraint.constant = 0;
    } else if (side == SKFormTextFieldSideLeft) {
        self.leftButton.hidden = YES;

        self.textFieldLeftConstraint.constant = 0;
        self.leftButtonWidthConstraint.constant = 0;
        self.leftButtonHeightConstraint.constant = 0;
    } else if (side == SKFormTextFieldSideRight) {
        self.rightButton.hidden = YES;

        self.textFieldRightConstraint.constant = 0;
        self.rightButtonWidthConstraint.constant = 0;
        self.rightButtonHeightConstraint.constant = 0;
    }
}

- (void)showDescriptionIconAtSide:(SKFormTextFieldSide)side {
    if (side == SKFormTextFieldSideBoth) {
        self.leftDescriptionIcon.hidden = NO;
        self.rightDescriptionIcon.hidden = NO;

        self.descriptionLabelLeftConstraint.constant = 8;
        self.leftImageWidthConstraint.constant = 18;
        self.leftImageHeightConstraint.constant = 18;

        self.descriptionLabelRightConstraint.constant = -8;
        self.rightImageWidthConstraint.constant = 18;
        self.rightImageHeightConstraint.constant = 18;
    } else if (side == SKFormTextFieldSideLeft) {
        self.leftDescriptionIcon.hidden = NO;

        self.descriptionLabelLeftConstraint.constant = 8;
        self.leftImageWidthConstraint.constant = 18;
        self.leftImageHeightConstraint.constant = 18;
    } else if (side == SKFormTextFieldSideRight) {
        self.rightDescriptionIcon.hidden = NO;

        self.descriptionLabelRightConstraint.constant = -8;
        self.rightImageWidthConstraint.constant = 18;
        self.rightImageHeightConstraint.constant = 18;
    }
}

- (void)hideDescriptionIconAtSide:(SKFormTextFieldSide)side {
    if (side == SKFormTextFieldSideBoth) {
        self.leftDescriptionIcon.hidden = YES;
        self.rightDescriptionIcon.hidden = YES;

        self.descriptionLabelLeftConstraint.constant = 0;
        self.leftImageWidthConstraint.constant = 0;
        self.leftImageHeightConstraint.constant = 0;

        self.descriptionLabelRightConstraint.constant = 0;
        self.rightImageWidthConstraint.constant = 0;
        self.rightImageHeightConstraint.constant = 0;
    } else if (side == SKFormTextFieldSideLeft) {
        self.leftDescriptionIcon.hidden = YES;

        self.descriptionLabelLeftConstraint.constant = 0;
        self.leftImageWidthConstraint.constant = 0;
        self.leftImageHeightConstraint.constant = 0;
    } else if (side == SKFormTextFieldSideRight) {
        self.rightDescriptionIcon.hidden = YES;

        self.descriptionLabelRightConstraint.constant = 0;
        self.rightImageWidthConstraint.constant = 0;
        self.rightImageHeightConstraint.constant = 0;
    }
}

- (BOOL)isEmpty {
    return !self.textField.text || self.textField.text.length == 0;
}

- (void)datePickerDidChange:(UIDatePicker *)datePicker {
    self.textField.text = [self.dateFormatter stringFromDate:datePicker.date];
}

#pragma mark - Protocols
#pragma mark -

- (BOOL)textFieldIsValid {
    if ([self.dataSource respondsToSelector:@selector(textFieldIsValid:)]) {
        if (self.required && (!self.textField.text || self.textField.text.length == 0)) {
            return NO;
        }
        return [self.dataSource textFieldIsValid:self];
    }
    if (self.required && (!self.textField.text || self.textField.text.length == 0)) {
        return NO;
    }

    return YES;
}

- (void)configureTextFieldForCurrentState {
    if ([self.dataSource respondsToSelector:@selector(configureTextField:forState:)]) {
        [self.dataSource configureTextField:self forState:self.textFieldState];
    }

    [self checkTextFieldState];
}

#pragma mark - UITextFieldDelegate Observers
#pragma mark -

- (void)textFieldDidBeginEditing:(NSNotification *)notification {
    if ([self.delegate respondsToSelector:@selector(textFieldDidBeginUpdates:)]) {
        [self.delegate textFieldDidBeginUpdates:self];
    }

    UITextField *textField = [notification object];

    if (self.textField == textField) {
        self.textFieldState = SKFormTextFieldStateActive;
        [self configureTextFieldForCurrentState];
    }

    if ([self.delegate respondsToSelector:@selector(textFieldDidEndUpdates:)]) {
        [self.delegate textFieldDidEndUpdates:self];
    }
}

- (void)textFieldDidEndEditing:(NSNotification *)notification {
    if ([self.delegate respondsToSelector:@selector(textFieldDidBeginUpdates:)]) {
        [self.delegate textFieldDidBeginUpdates:self];
    }

    UITextField *textField = [notification object];

    if (self.textField == textField) {
        self.textFieldState = [self textFieldIsValid] ? SKFormTextFieldStateValid : SKFormTextFieldStateInvalid;
        [self configureTextFieldForCurrentState];

        if (self.textFieldDidEndEditingBlock) {
            self.textFieldDidEndEditingBlock(textField.text);
        }
    }

    if ([self.delegate respondsToSelector:@selector(textFieldDidEndUpdates:)]) {
        [self.delegate textFieldDidEndUpdates:self];
    }
}

#pragma mark - UITextViewDelegate Observers
#pragma mark -

- (void)textViewDidBeginEditing:(NSNotification *)notification {
    if ([self.delegate respondsToSelector:@selector(textFieldDidBeginUpdates:)]) {
        [self.delegate textFieldDidBeginUpdates:self];
    }

    UITextView *textView = [notification object];

    if (self.textView == textView) {
        self.textFieldState = SKFormTextFieldStateActive;
        [self configureTextFieldForCurrentState];
    }

    if ([self.delegate respondsToSelector:@selector(textFieldDidEndUpdates:)]) {
        [self.delegate textFieldDidEndUpdates:self];
    }
}

- (void)textViewDidEndEditing:(NSNotification *)notification {
    if ([self.delegate respondsToSelector:@selector(textFieldDidBeginUpdates:)]) {
        [self.delegate textFieldDidBeginUpdates:self];
    }

    UITextView *textView = [notification object];

    if (self.textView == textView) {
        self.textFieldState = [self textFieldIsValid] ? SKFormTextFieldStateValid : SKFormTextFieldStateInvalid;
        [self configureTextFieldForCurrentState];

        if (self.textViewDidEndEditingBlock) {
            self.textViewDidEndEditingBlock(textView.text);
        }
    }

    if ([self.delegate respondsToSelector:@selector(textFieldDidEndUpdates:)]) {
        [self.delegate textFieldDidEndUpdates:self];
    }
}

#pragma mark - Getters/Setters

- (void)setLineNormalColor:(UIColor *)lineNormalColor {
    _lineNormalColor = lineNormalColor;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setLineActiveColor:(UIColor *)lineActiveColor {
    _lineActiveColor = lineActiveColor;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setLineValidColor:(UIColor *)lineValidColor {
    _lineValidColor = lineValidColor;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setLineErrorColor:(UIColor *)lineErrorColor {
    _lineErrorColor = lineErrorColor;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setDescriptionNormalColor:(UIColor *)descriptionNormalColor {
    _descriptionNormalColor = descriptionNormalColor;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setDescriptionActiveColor:(UIColor *)descriptionActiveColor {
    _descriptionActiveColor = descriptionActiveColor;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setDescriptionValidColor:(UIColor *)descriptionValidColor {
    _descriptionValidColor = descriptionValidColor;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setDescriptionErrorColor:(UIColor *)descriptionErrorColor {
    _descriptionErrorColor = descriptionErrorColor;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setPlaceholderText:(NSString *)placeholderText {
    _placeholderText = placeholderText;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setDescriptionText:(NSString *)descriptionText {
    _descriptionText = descriptionText;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setErrorMessageText:(NSString *)errorMessageText {
    _errorMessageText = errorMessageText;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setLeftButtonImage:(UIImage *)leftButtonImage {
    _leftButtonImage = leftButtonImage;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setRightButtonImage:(UIImage *)rightButtonImage {
    _rightButtonImage = rightButtonImage;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setLeftIconImage:(UIImage *)leftIconImage {
    _leftIconImage = leftIconImage;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setRightIconImage:(UIImage *)rightIconImage {
    _rightIconImage = rightIconImage;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setErrorImage:(UIImage *)errorImage {
    _errorImage = errorImage;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setLeftButtonHidden:(BOOL)leftButtonHidden {
    _leftButtonHidden = leftButtonHidden;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setRightButtonHidden:(BOOL)rightButtonHidden {
    _rightButtonHidden = rightButtonHidden;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setLeftIconHidden:(BOOL)leftIconHidden {
    _leftIconHidden = leftIconHidden;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setRightIconHidden:(BOOL)rightIconHidden {
    _rightIconHidden = rightIconHidden;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setTextViewHeight:(CGFloat)textViewHeight {
    _textViewHeight = textViewHeight;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setTextFieldState:(SKFormTextFieldState)textFieldState {
    _textFieldState = textFieldState;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setType:(SKFormTextFieldType)type {
    _type = type;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setMode:(SKFormTextFieldMode)mode {
    _mode = mode;

    if (hasSetuped) {
        [self updateUI];
    }
}

- (void)setDoNotHideLineWhenRead:(BOOL)doNotHideLineWhenRead {
    _doNotHideLineWhenRead = doNotHideLineWhenRead;

    if (hasSetuped) {
        [self updateUI];
    }
}

@end


text:
package org.camelcookbook.examples.testing.advicewith;

import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
import org.apache.camel.test.spring.UseAdviceWith;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;

/**
 * Test class that uses Camel's built-in AOP functionality to override the fixed endpoints.
 */
@RunWith(CamelSpringJUnit4ClassRunner.class)
@ContextConfiguration({"/META-INF/spring/fixedEndpoints-context.xml"})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@UseAdviceWith(true)
public class FixedEndpointEnhancedSpringTest {

    @Autowired
    private ModelCamelContext context;

    @Test
    public void testOverriddenEndpoints() throws Exception {
        context.getRouteDefinition("modifyPayloadBetweenQueues")
            .adviceWith(context, new AdviceWithRouteBuilder() {
                @Override
                public void configure() throws Exception {
                    replaceFromWith("direct:in");

                    interceptSendToEndpoint("activemq:out")
                        .skipSendToOriginalEndpoint()
                        .to("mock:out");
                }
            });
        context.start();

        MockEndpoint out = context.getEndpoint("mock:out", MockEndpoint.class);
        out.setExpectedMessageCount(1);
        out.message(0).body().isEqualTo("Modified: Cheese");

        ProducerTemplate template = context.createProducerTemplate();
        template.sendBody("direct:in", "Cheese");

        out.assertIsSatisfied();
    }
}