text:
//---------------------------------------------------------------------------
//
// File TextSchema.cs
//
// Copyright (C) Microsoft Corporation.  All rights reserved.
//
// Description: A static class providing information about text content schema
//
//---------------------------------------------------------------------------

namespace System.Windows.Documents
{
    using MS.Internal;
    using System.Collections.Generic;
    using System.Windows.Controls; // TextBox, TextBlock
    using System.Windows.Media; // Brush

    /// <summary>
    /// Provides an information about text structure schema.
    /// The schema is used in editing operations for maintaining
    /// content integrity.
    /// </summary>
    /// <remarks>
    /// Currently this class is totally private and hard-coded
    /// for some particular text structure.
    /// The intention is to make this mechanism public -
    /// as part of Text OM, so that custom backing store implementation
    /// could provide its own schemas.
    /// But we need to experiment with this approach first to make
    /// sure that it is feasible.
    /// </remarks>
    internal static class TextSchema
    {
        // ...............................................................
        //
        // Constructors
        //
        // ...............................................................

        static TextSchema()
        {
            // Initialize TextElement inheritable properties
            DependencyProperty[] textElementPropertyList = new DependencyProperty[]
                {
                    FrameworkElement.LanguageProperty,
                    FrameworkElement.FlowDirectionProperty,
                    NumberSubstitution.CultureSourceProperty,
                    NumberSubstitution.SubstitutionProperty,
                    NumberSubstitution.CultureOverrideProperty,
                    TextElement.FontFamilyProperty,
                    TextElement.FontStyleProperty,
                    TextElement.FontWeightProperty,
                    TextElement.FontStretchProperty,
                    TextElement.FontSizeProperty,
                    TextElement.ForegroundProperty,
                };

            _inheritableTextElementProperties = new DependencyProperty[textElementPropertyList.Length + Typography.TypographyPropertiesList.Length];
            Array.Copy(textElementPropertyList, 0, _inheritableTextElementProperties, 0, textElementPropertyList.Length);
            Array.Copy(Typography.TypographyPropertiesList, 0, _inheritableTextElementProperties, textElementPropertyList.Length, Typography.TypographyPropertiesList.Length);

            // Initialize Block/FlowDocument inheritable properties
            DependencyProperty[] blockPropertyList = new DependencyProperty[]
                {
                    Block.TextAlignmentProperty,
                    Block.LineHeightProperty,
                    Block.IsHyphenationEnabledProperty,
                };

            _inheritableBlockProperties = new DependencyProperty[blockPropertyList.Length + _inheritableTextElementProperties.Length];
            Array.Copy(blockPropertyList, 0, _inheritableBlockProperties, 0, blockPropertyList.Length);
            Array.Copy(_inheritableTextElementProperties, 0, _inheritableBlockProperties, blockPropertyList.Length, _inheritableTextElementProperties.Length);

            //
            // Initialize TableCell related inheritable properties.
            //
            DependencyProperty[] tableCellPropertyList = new DependencyProperty[]
                {
                    Block.TextAlignmentProperty
                };
            _inheritableTableCellProperties = new DependencyProperty[tableCellPropertyList.Length + _inheritableTextElementProperties.Length];
            Array.Copy(tableCellPropertyList, _inheritableTableCellProperties, tableCellPropertyList.Length);
            Array.Copy(_inheritableTextElementProperties, 0, _inheritableTableCellProperties, tableCellPropertyList.Length, _inheritableTextElementProperties.Length);
        }

        // ...............................................................
        //
        // Element Content Model
        //
        // ...............................................................

        internal static bool IsInTextContent(ITextPointer position)
        {
            return IsValidChild(position, typeof(string));
        }

#if UNUSED
        internal static bool IsValidChild(TextElement parent, TextElement child)
        {
            return ValidateChild(parent, child, false /* throwIfIllegalChild */, false /* throwIfIllegalHyperlinkDescendent */);
        }
#endif

        internal static bool ValidateChild(TextElement parent, TextElement child, bool throwIfIllegalChild, bool throwIfIllegalHyperlinkDescendent)
        {
            // Disallow nested hyperlink elements.
            if (TextSchema.HasHyperlinkAncestor(parent) &&
                TextSchema.HasIllegalHyperlinkDescendant(child, throwIfIllegalHyperlinkDescendent))
            {
                return false;
            }

            bool isValidChild = IsValidChild(parent.GetType(), child.GetType());

            if (!isValidChild && throwIfIllegalChild)
            {
                throw new InvalidOperationException(SR.Get(SRID.TextSchema_ChildTypeIsInvalid, parent.GetType().Name, child.GetType().Name));
            }

            return isValidChild;
        }

        internal static bool IsValidChild(TextElement parent, Type childType)
        {
            return ValidateChild(parent, childType, false /* throwIfIllegalChild */, false /* throwIfIllegalHyperlinkDescendent */);
        }

        internal static bool ValidateChild(TextElement parent, Type childType, bool throwIfIllegalChild, bool throwIfIllegalHyperlinkDescendent)
        {
            // Disallow nested hyperlink elements.
            if (TextSchema.HasHyperlinkAncestor(parent))
            {
                if (typeof(Hyperlink).IsAssignableFrom(childType) ||
                    typeof(AnchoredBlock).IsAssignableFrom(childType))
                {
                    if (throwIfIllegalHyperlinkDescendent)
                    {
                        throw new InvalidOperationException(SR.Get(SRID.TextSchema_IllegalHyperlinkChild, childType));
                    }
                    return false;
                }
            }

            bool isValidChild = IsValidChild(parent.GetType(), childType);

            if (!isValidChild && throwIfIllegalChild)
            {
                throw new InvalidOperationException(SR.Get(SRID.TextSchema_ChildTypeIsInvalid, parent.GetType().Name, childType.Name));
            }

            return isValidChild;
        }

        internal static bool IsValidChild(TextPointer position, Type childType)
        {
            return ValidateChild(position, childType, false /* throwIfIllegalChild */, false /* throwIfIllegalHyperlinkDescendent */);
        }

        internal static bool ValidateChild(TextPointer position, Type childType, bool throwIfIllegalChild, bool throwIfIllegalHyperlinkDescendent)
        {
            DependencyObject parent = position.Parent;

            if (parent == null)
            {
                TextElement leftElement = position.GetAdjacentElementFromOuterPosition(LogicalDirection.Backward);
                TextElement rightElement = position.GetAdjacentElementFromOuterPosition(LogicalDirection.Forward);
                return (leftElement == null || IsValidSibling(leftElement.GetType(), childType)) &&
                    (rightElement == null || IsValidSibling(rightElement.GetType(), childType));
            }

            if (parent is TextElement)
            {
                return ValidateChild((TextElement)parent, childType, throwIfIllegalChild, throwIfIllegalHyperlinkDescendent);
            }

            bool isValidChild = IsValidChild(parent.GetType(), childType);

            if (!isValidChild && throwIfIllegalChild)
            {
                throw new InvalidOperationException(SR.Get(SRID.TextSchema_ChildTypeIsInvalid, parent.GetType().Name, childType.Name));
            }

            return isValidChild;
        }

        internal static bool IsValidSibling(Type siblingType, Type newType)
        {
            if (typeof(Inline).IsAssignableFrom(newType))
            {
                return typeof(Inline).IsAssignableFrom(siblingType);
            }
            else if (typeof(Block).IsAssignableFrom(newType))
            {
                return typeof(Block).IsAssignableFrom(siblingType);
            }
            else if (typeof(TableRowGroup).IsAssignableFrom(newType))
            {
                return typeof(TableRowGroup).IsAssignableFrom(siblingType);
            }
            else if (typeof(TableRow).IsAssignableFrom(newType))
            {
                return typeof(TableRow).IsAssignableFrom(siblingType);
            }
            else if (typeof(TableCell).IsAssignableFrom(newType))
            {
                return typeof(TableCell).IsAssignableFrom(siblingType);
            }
            else if (typeof(ListItem).IsAssignableFrom(newType))
            {
                return typeof(ListItem).IsAssignableFrom(siblingType);
            }
            else
            {
                Invariant.Assert(false, "unexpected value for newType");
                return false;
            }
        }

        internal static bool IsValidChild(ITextPointer position, Type childType)
        {
            // Disallow nested hyperlink elements.
            if (typeof(TextElement).IsAssignableFrom(position.ParentType) &&
                TextPointerBase.IsInHyperlinkScope(position))
            {
                if (typeof(Hyperlink).IsAssignableFrom(childType) ||
                    typeof(AnchoredBlock).IsAssignableFrom(childType))
                {
                    return false;
                }
            }

            return IsValidChild(position.ParentType, childType);
        }

        internal static bool IsValidChildOfContainer(Type parentType, Type childType)
        {
            Invariant.Assert(!typeof(TextElement).IsAssignableFrom(parentType));
            return IsValidChild(parentType, childType);
        }

        // Walks parents of this TextElement until it finds a hyperlink ancestor.
        internal static bool HasHyperlinkAncestor(TextElement element)
        {
            Inline ancestor = element as Inline;

            while (ancestor != null && !(ancestor is Hyperlink))
            {
                ancestor = ancestor.Parent as Inline;
            }

            return ancestor != null;
        }

        /// <summary>
        /// Returns true indicatinng that a type can be skipped for pointer normalization -
        /// it is formattinng tag not producing a caret stop position.
        /// </summary>
        /// <param name="elementType"></param>
        /// <returns></returns>
        internal static bool IsFormattingType(Type elementType)
        {
            return
                typeof(Run).IsAssignableFrom(elementType) ||
                typeof(Span).IsAssignableFrom(elementType);
        }

        /// <summary>
        /// Determine if the given type is "known"-- that is, is part of the framework as
        /// opposed to a custom, user-defined type.
        /// </summary>
        internal static bool IsKnownType(Type elementType)
        {
            return elementType.Module == typeof(System.Windows.Documents.TextElement).Module || // presentationframework
                elementType.Module == typeof(System.Windows.UIElement).Module; // presentationcore
        }

        internal static bool IsNonFormattingInline(Type elementType)
        {
            return typeof(Inline).IsAssignableFrom(elementType) && !IsFormattingType(elementType);
        }

        internal static bool IsMergeableInline(Type elementType)
        {
            return IsFormattingType(elementType) && !IsNonMergeableInline(elementType);
        }

        internal static bool IsNonMergeableInline(Type elementType)
        {
            TextElementEditingBehaviorAttribute att = (TextElementEditingBehaviorAttribute)Attribute.GetCustomAttribute(elementType, typeof(TextElementEditingBehaviorAttribute));
            if (att != null && att.IsMergeable == false)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Returns true for a type which allows paragraph merging
        /// across its boundary.
        /// Hard-structured elements like Table, Floater, Figure
        /// does not allow paragraph merging.
        /// </summary>
        internal static bool AllowsParagraphMerging(Type elementType)
        {
            return
                typeof(Paragraph).IsAssignableFrom(elementType) ||
                typeof(ListItem).IsAssignableFrom(elementType) ||
                typeof(List).IsAssignableFrom(elementType) ||
                typeof(Section).IsAssignableFrom(elementType);
        }

        /// <summary>
        /// Classifies the elementType as a generalized Paragraph -
        /// a block behaving similar to paragraph in regards of
        /// margins, indentations, bullets, and other paragraph properties.
        /// </summary>
        /// <param name="elementType">
        /// Element type to check
        /// </param>
        /// <returns>
        /// true if the element can be treated as a paragraph
        /// </returns>
        internal static bool IsParagraphOrBlockUIContainer(Type elementType)
        {
            return
                typeof(Paragraph).IsAssignableFrom(elementType) ||
                typeof(BlockUIContainer).IsAssignableFrom(elementType);
        }

        // Identifies any block element
        internal static bool IsBlock(Type type)
        {
            return ( //
                typeof(Block).IsAssignableFrom(type));
        }

        internal static bool IsBreak(Type type)
        {
            return ( //
                typeof(LineBreak).IsAssignableFrom(type));
        }

        // ...............................................................
        //
        // Formatting Properties
        //
        // ...............................................................

        // Helper for defining whether text decoration value is non-empty collection
        internal static bool HasTextDecorations(object value)
        {
            return (value is TextDecorationCollection) && ((TextDecorationCollection)value).Count > 0;
        }

        // From a given element type returns one of statically known
        // reduceElement parameter: True value of this parameter indicates that
        // serialization goes into XamlPackage, so all elements
        // can be preserved as is; otherwise some of them must be
        // reduced into simpler representations (such as InlineUIContainer -> Run
        // and BlockUIContainer -> Paragraph).
        internal static Type GetStandardElementType(Type type, bool reduceElement)
        {
            // Run-derived elements
            // --------------------
            if (typeof(Run).IsAssignableFrom(type))
            {
                // Must be after all elements derived from Run
                return typeof(Run);
            }

            // Span-derived elements
            // ---------------------
            else if (typeof(Hyperlink).IsAssignableFrom(type))
            {
                return typeof(Hyperlink);
            }
            else if (typeof(Span).IsAssignableFrom(type))
            {
                // Must be after all other standard Span-derived elements such as Hyperlink, Bold, etc.
                return typeof(Span);
            }

            // Other Inline elements
            // ---------------------
            else if (typeof(InlineUIContainer).IsAssignableFrom(type))
            {
                return reduceElement ? typeof(Run) : typeof(InlineUIContainer);
            }
            else if (typeof(LineBreak).IsAssignableFrom(type))
            {
                return typeof(LineBreak);
            }
            else if (typeof(Floater).IsAssignableFrom(type))
            {
                return typeof(Floater);
            }
            else if (typeof(Figure).IsAssignableFrom(type))
            {
                return typeof(Figure);
            }

            // Block-derived elements
            // ----------------------
            else if (typeof(Paragraph).IsAssignableFrom(type))
            {
                return typeof(Paragraph);
            }
            else if (typeof(Section).IsAssignableFrom(type))
            {
                return typeof(Section);
            }
            else if (typeof(List).IsAssignableFrom(type))
            {
                return typeof(List);
            }
            else if (typeof(Table).IsAssignableFrom(type))
            {
                return typeof(Table);
            }
            else if (typeof(BlockUIContainer).IsAssignableFrom(type))
            {
                return reduceElement ? typeof(Paragraph) : typeof(BlockUIContainer);
            }

            // Other TextElements
            // ------------------
            else if (typeof(ListItem).IsAssignableFrom(type))
            {
                return typeof(ListItem);
            }
            else if (typeof(TableColumn).IsAssignableFrom(type))
            {
                return typeof(TableColumn);
            }
            else if (typeof(TableRowGroup).IsAssignableFrom(type))
            {
                return typeof(TableRowGroup);
            }
            else if (typeof(TableRow).IsAssignableFrom(type))
            {
                return typeof(TableRow);
            }
            else if (typeof(TableCell).IsAssignableFrom(type))
            {
                return typeof(TableCell);
            }

            // To make compiler happy in cases of Invariant.Assert - return something
            Invariant.Assert(false, "We do not expect any unknown elements derived directly from TextElement, Block or Inline. Schema must have been checking for that");
            return null;
        }

        // Returns a list of inheritable properties applicable to a particular type
        internal static DependencyProperty[] GetInheritableProperties(Type type)
        {
            if (typeof(TableCell).IsAssignableFrom(type))
            {
                return _inheritableTableCellProperties;
            }

            if (typeof(Block).IsAssignableFrom(type) || typeof(FlowDocument).IsAssignableFrom(type))
            {
                return _inheritableBlockProperties;
            }

            Invariant.Assert(typeof(TextElement).IsAssignableFrom(type) || typeof(TableColumn).IsAssignableFrom(type),
                "type must be one of TextElement, FlowDocument or TableColumn");

            return _inheritableTextElementProperties;
        }

        // Returns a list of noninheritable properties applicable to a particular type
        // They are safe to be transferred from outer scope to inner scope when the outer one
        // is removed (e.g. TextRangeEdit.RemoveUnnecessarySpans(...)).
        internal static DependencyProperty[] GetNoninheritableProperties(Type type)
        {
            // Run-derived elements
            // --------------------
            if (typeof(Run).IsAssignableFrom(type))
            {
                // Must be after all elements derived from Run
                return _inlineProperties;
            }

            // Span-derived elements
            // ---------------------
            else if (typeof(Hyperlink).IsAssignableFrom(type))
            {
                return _hyperlinkProperties;
            }
            else if (typeof(Span).IsAssignableFrom(type))
            {
                // Must be after all other standard Span-derived elements such as Hyperlink, Bold, etc.
                return _inlineProperties;
            }

            // Other Inline elements
            // ---------------------
            else if (typeof(InlineUIContainer).IsAssignableFrom(type))
            {
                return _inlineProperties;
            }
            else if (typeof(LineBreak).IsAssignableFrom(type))
            {
                return _emptyPropertyList;
            }
            else if (typeof(Floater).IsAssignableFrom(type))
            {
                return _floaterProperties;
            }
            else if (typeof(Figure).IsAssignableFrom(type))
            {
                return _figureProperties;
            }

            // Block-derived elements
            // ----------------------
            else if (typeof(Paragraph).IsAssignableFrom(type))
            {
                return _paragraphProperties;
            }
            else if (typeof(Section).IsAssignableFrom(type))
            {
                return _blockProperties;
            }
            else if (typeof(List).IsAssignableFrom(type))
            {
                return _listProperties;
            }
            else if (typeof(Table).IsAssignableFrom(type))
            {
                return _tableProperties;
            }
            else if (typeof(BlockUIContainer).IsAssignableFrom(type))
            {
                return _blockProperties;
            }

            // Other TextElements
            // ------------------
            else if (typeof(ListItem).IsAssignableFrom(type))
            {
                return _listItemProperties;
            }
            else if (typeof(TableColumn).IsAssignableFrom(type))
            {
                return _tableColumnProperties;
            }
            else if (typeof(TableRowGroup).IsAssignableFrom(type))
            {
                return _tableRowGroupProperties;
            }
            else if (typeof(TableRow).IsAssignableFrom(type))
            {
                return _tableRowProperties;
            }
            else if (typeof(TableCell).IsAssignableFrom(type))
            {
                return _tableCellProperties;
            }

            Invariant.Assert(false, "We do not expect any unknown elements derived directly from TextElement. Schema must have been checking for that");
            return _emptyPropertyList; // to make compiler happy
        }

        // Compares two values for equality
        /// <summary>
        /// Property comparison helper.
        /// Compares property values for equivalence from serialization
        /// standpoint. In editing we consider properties equal
        /// if they have the same serialized representation.
        /// Differences coming from current dynamic state changes
        /// should not affect comparison if they are not going to be
        /// visible after serialization.
        /// Instantiation dirrefences are also insignificant.
        /// </summary>
        /// <param name="value1">
        /// </param>
        /// <param name="value2">
        /// </param>
        /// <returns>
        /// True if two values have the same serialized representation
        /// </returns>
        internal static bool ValuesAreEqual(object value1, object value2)
        {
            if ((object)value1 == (object)value2) // this check includes two nulls
            {
                return true;
            }

            // Comparing null with empty collections
            if (value1 == null)
            {
                if (value2 is TextDecorationCollection)
                {
                    TextDecorationCollection decorations2 = (TextDecorationCollection)value2;
                    return decorations2.Count == 0;
                }
                else if (value2 is TextEffectCollection)
                {
                    TextEffectCollection effects2 = (TextEffectCollection)value2;
                    return effects2.Count == 0;
                }
                return false;
            }
            else if (value2 == null)
            {
                if (value1 is TextDecorationCollection)
                {
                    TextDecorationCollection decorations1 = (TextDecorationCollection)value1;
                    return decorations1.Count == 0;
                }
                else if (value1 is TextEffectCollection)
                {
                    TextEffectCollection effects1 = (TextEffectCollection)value1;
                    return effects1.Count == 0;
                }
                return false;
            }

            // Must be of exactly the same types (really ?)
            //
            if (value1.GetType() != value2.GetType())
            {
                return false;
            }

            // Special cases for known types: TextDecorations, FontFamily, Brush
            if (value1 is TextDecorationCollection)
            {
                TextDecorationCollection decorations1 = (TextDecorationCollection)value1;
                TextDecorationCollection decorations2 = (TextDecorationCollection)value2;
                return decorations1.ValueEquals(decorations2);
            }
            else if (value1 is FontFamily)
            {
                FontFamily fontFamily1 = (FontFamily)value1;
                FontFamily fontFamily2 = (FontFamily)value2;
                return fontFamily1.Equals(fontFamily2);
            }
            else if (value1 is Brush)
            {
                return AreBrushesEqual((Brush)value1, (Brush)value2);
            }
            else
            {
                string string1 = value1.ToString();
                string string2 = value2.ToString();
                return string1 == string2;
            }
        }

        /// <summary>
        /// Tests whether it is the paragraph property or not.
        /// Used to decide should the property be applied to character runs or to paragraphs
        /// in TextRange.ApplyProperty()
        /// </summary>
        internal static bool IsParagraphProperty(DependencyProperty formattingProperty)
        {
            // Check inheritable paragraph properties
            for (int i = 0; i < _inheritableBlockProperties.Length; i++)
            {
                if (formattingProperty == _inheritableBlockProperties[i])
                {
                    return true;
                }
            }

            // Check non-inheritable paragraph properties
            for (int i = 0; i < _paragraphProperties.Length; i++)
            {
                if (formattingProperty == _paragraphProperties[i])
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// Returns true if this property is applicable to inline character formatting element
        /// </summary>
        internal static bool IsCharacterProperty(DependencyProperty formattingProperty)
        {
            // Check inheritable inline properties
            for (int i = 0; i < _inheritableTextElementProperties.Length; i++)
            {
                if (formattingProperty == _inheritableTextElementProperties[i])
                {
                    return true;
                }
            }

            // Check non-inheritable Inline properties
            for (int i = 0; i < _inlineProperties.Length; i++)
            {
                if (formattingProperty == _inlineProperties[i])
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// Returns true if this property is a character property NOT affecting formatting.
        /// </summary>
        internal static bool IsNonFormattingCharacterProperty(DependencyProperty property)
        {
            for (int i = 0; i < _nonFormattingCharacterProperties.Length; i++)
            {
                if (property == _nonFormattingCharacterProperties[i])
                {
                    return true;
                }
            }

            return false;
        }

        internal static DependencyProperty[] GetNonFormattingCharacterProperties()
        {
            return _nonFormattingCharacterProperties;
        }

        /// <summary>
        /// Returns true if this property is a structural property of inline element.
        /// </summary>
        /// <remarks>
        /// A structural character property is more strict for its scope than other (non-structural) inline properties (such as fontweight).
        /// While the associativity rule holds true for non-structural properties when there values are equal,
        ///     (FontWeight)A (FontWeight)B == (FontWeight) AB
        /// this does not hold true for structual properties even when there values may be equal,
        ///     (FlowDirection)A (FlowDirection)B != (FlowDirection)A B
        /// Hence, these properties require special logic in setting, merging, splitting rules for inline elements.
        /// </remarks>
        internal static bool IsStructuralCharacterProperty(DependencyProperty formattingProperty)
        {
            int i;

            for (i = 0; i < _structuralCharacterProperties.Length; i++)
            {
                if (formattingProperty == _structuralCharacterProperties[i])
                    break;
            }

            return (i < _structuralCharacterProperties.Length);
        }

        // Returns true if a property value can be incremented or decremented
        internal static bool IsPropertyIncremental(DependencyProperty property)
        {
            if (property == null)
            {
                return false;
            }

            Type propertyType = property.PropertyType;

            return
                typeof(double).IsAssignableFrom(propertyType) ||
                typeof(long).IsAssignableFrom(propertyType) ||
                typeof(int).IsAssignableFrom(propertyType) ||
                typeof(Thickness).IsAssignableFrom(propertyType);
        }

        // Set of properties affecting editing behavior that must be transferred
        // from hosting UI elements (like RichTextBox) to FlowDocument to ensure appropriate
        // editing behavior.
        // This is especially important for FlowDocuments with FormattingDefaults="Standalone".
        internal static DependencyProperty[] BehavioralProperties
        {
            get
            {
                return _behavioralPropertyList;
            }
        }

        internal static DependencyProperty[] ImageProperties
        {
            get
            {
                return _imagePropertyList;
            }
        }

        // List of structural properties.
        internal static DependencyProperty[] StructuralCharacterProperties
        {
            get
            {
                return _structuralCharacterProperties;
            }
        }

        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        #region Private Methods

        private static bool IsValidChild(Type parentType, Type childType)
        {
            // Text Content
            if (parentType == null || //
                typeof(Run).IsAssignableFrom(parentType) ||
                typeof(TextBox).IsAssignableFrom(parentType) ||
                typeof(PasswordBox).IsAssignableFrom(parentType))
            {
                // NOTE: Even though we use TextBlock or FlowDocumentView for TextBox's render scope,
                // a parent for position will be directly TextBlock or PasswordBox, thus allowing
                // text content. Otherwise neither TextBlock nor FlowDocumentView allow direct text content -
                // only through Run.
                return childType == typeof(string);
            }
            // TextBlock allowed children
            else if (typeof(TextBlock).IsAssignableFrom(parentType))
            {
                return typeof(Inline).IsAssignableFrom(childType) &&
                    !typeof(AnchoredBlock).IsAssignableFrom(childType);
            }
            // Hyperlink allowed children
            else if (typeof(Hyperlink).IsAssignableFrom(parentType))
            {
                return typeof(Inline).IsAssignableFrom(childType) &&
                    !typeof(Hyperlink).IsAssignableFrom(childType) &&
                    !typeof(AnchoredBlock).IsAssignableFrom(childType);
            }
            // Inline items
            else if (typeof(Span).IsAssignableFrom(parentType) ||
                typeof(Paragraph).IsAssignableFrom(parentType) ||
                typeof(AccessText).IsAssignableFrom(parentType))
            {
                return typeof(Inline).IsAssignableFrom(childType);
            }
            // Inline UIElements
            else if (typeof(InlineUIContainer).IsAssignableFrom(parentType))
            {
                return typeof(UIElement).IsAssignableFrom(childType);
            }
            // List Content
            else if (typeof(List).IsAssignableFrom(parentType))
            {
                return typeof(ListItem).IsAssignableFrom(childType);
            }
            // Table Content
            else if (typeof(Table).IsAssignableFrom(parentType))
            {
                return typeof(TableRowGroup).IsAssignableFrom(childType);
            }
            else if (typeof(TableRowGroup).IsAssignableFrom(parentType))
            {
                return typeof(TableRow).IsAssignableFrom(childType);
            }
            else if (typeof(TableRow).IsAssignableFrom(parentType))
            {
                return typeof(TableCell).IsAssignableFrom(childType);
            }
            // Block Content
            //
            else if (
                typeof(Section).IsAssignableFrom(parentType) ||
                typeof(ListItem).IsAssignableFrom(parentType) ||
                typeof(TableCell).IsAssignableFrom(parentType) ||
                typeof(Floater).IsAssignableFrom(parentType) ||
                typeof(Figure).IsAssignableFrom(parentType) ||
                typeof(FlowDocument).IsAssignableFrom(parentType))
            {
                return typeof(Block).IsAssignableFrom(childType);
            }
            // Block UIElements
            else if (typeof(BlockUIContainer).IsAssignableFrom(parentType))
            {
                return typeof(UIElement).IsAssignableFrom(childType);
            }
            else
            {
                return false;
            }
        }

        // Returns true if passed textelement has any Hyperlink or AnchoredBlock descendant.
        // It this context, the element or one of its ancestors is a Hyperlink.
        private static bool HasIllegalHyperlinkDescendant(TextElement element, bool throwIfIllegalDescendent)
        {
            TextPointer start = element.ElementStart;
            TextPointer end = element.ElementEnd;

            while (start.CompareTo(end) < 0)
            {
                TextPointerContext forwardContext = start.GetPointerContext(LogicalDirection.Forward);
                if (forwardContext == TextPointerContext.ElementStart)
                {
                    TextElement nextElement = (TextElement)start.GetAdjacentElement(LogicalDirection.Forward);

                    if (nextElement is Hyperlink ||
                        nextElement is AnchoredBlock)
                    {
                        if (throwIfIllegalDescendent)
                        {
                            throw new InvalidOperationException(SR.Get(SRID.TextSchema_IllegalHyperlinkChild, nextElement.GetType()));
                        }
                        return true;
                    }
                }

                start = start.GetNextContextPosition(LogicalDirection.Forward);
            }
            return false;
        }

        private static bool AreBrushesEqual(Brush brush1, Brush brush2)
        {
            SolidColorBrush solidBrush1 = brush1 as SolidColorBrush;
            if (solidBrush1 != null)
            {
                return solidBrush1.Color.Equals(((SolidColorBrush)brush2).Color);
            }
            else
            {
                // When the brush is not serializable to string, we consider values equal only is they are equal as objects
                string string1 = DPTypeDescriptorContext.GetStringValue(TextElement.BackgroundProperty, brush1);
                string string2 = DPTypeDescriptorContext.GetStringValue(TextElement.BackgroundProperty, brush2);
                return string1 != null && string2 != null ? string1 == string2 : false;
            }
        }

        #endregion Private Methods

        //------------------------------------------------------
        //
        //  Private Fields
        //
        //------------------------------------------------------

        #region Private Fields

        // List of all inheritable properties applicable to TextElement types
        private static readonly DependencyProperty[] _inheritableTextElementProperties;

        // Block element adds a few inhertiable properties that dont apply to other TextElement types,
        // this list includes inheritable properties applicable to Block and also root FlowDocument types.
        private static readonly DependencyProperty[] _inheritableBlockProperties;

        // TableCell element adds inheritable TextAlignmentProperty that doesn't apply to other TextElement types.
        private static readonly DependencyProperty[] _inheritableTableCellProperties;

        // List of all non-inheritable properties applicable to Hyperlink element
        private static readonly DependencyProperty[] _hyperlinkProperties = new DependencyProperty[]
            {
                Hyperlink.NavigateUriProperty,
                Hyperlink.TargetNameProperty,
                Hyperlink.CommandProperty,
                Hyperlink.CommandParameterProperty,
                Hyperlink.CommandTargetProperty,

                // Inherits Inline Properties
                Inline.BaselineAlignmentProperty,
                Inline.TextDecorationsProperty,

                // Inherits TextElement properties
                TextElement.BackgroundProperty,
                //TextElement.TextEffectsProperty, -- the property is not supported in text editor

                // Inherits FrameworkContentElement properties
                FrameworkContentElement.ToolTipProperty,
            };

        // List of all non-inheritable properties applicable to Inline element
        private static readonly DependencyProperty[] _inlineProperties = new DependencyProperty[]
            {
                Inline.BaselineAlignmentProperty,
                Inline.TextDecorationsProperty,

                // Inherits TextElement properties
                TextElement.BackgroundProperty,
                //TextElement.TextEffectsProperty, -- the property is not supported in text editor
            };

        // List of all non-inheritable properties applicable to Paragraph element
        private static readonly DependencyProperty[] _paragraphProperties = new DependencyProperty[]
            {
                Paragraph.MinWidowLinesProperty,
                Paragraph.MinOrphanLinesProperty,
                Paragraph.TextIndentProperty,
                Paragraph.KeepWithNextProperty,
                Paragraph.KeepTogetherProperty,
                Paragraph.TextDecorationsProperty,

                // Inherits Block properties
                Block.MarginProperty,
                Block.PaddingProperty,
                Block.BorderThicknessProperty,
                Block.BorderBrushProperty,

                // Inherits TextElement properties
                TextElement.BackgroundProperty,
                //TextElement.TextEffectsProperty, -- the property is not supported in text editor
            };

        // List of all non-inheritable properties applicable to List element
        private static readonly DependencyProperty[] _listProperties = new DependencyProperty[]
            {
                List.MarkerStyleProperty,
                List.MarkerOffsetProperty,
                List.StartIndexProperty,

                // Inherits Block properties
                Block.MarginProperty,
                Block.PaddingProperty,
                Block.BorderThicknessProperty,
                Block.BorderBrushProperty,

                // Inherits TextElement properties
                TextElement.BackgroundProperty,
                //TextElement.TextEffectsProperty, -- the property is not supported in text editor
            };

        // List of all non-inheritable properties applicable to ListItem element
        private static readonly DependencyProperty[] _listItemProperties = new DependencyProperty[]
            {
                // Adds owner to Block properties
                ListItem.MarginProperty,
                ListItem.PaddingProperty,
                ListItem.BorderThicknessProperty,
                ListItem.BorderBrushProperty,

                // Inherits TextElement properties
                TextElement.BackgroundProperty,
                //TextElement.TextEffectsProperty, -- the property is not supported in text editor
            };

        // List of all non-inheritable properties applicable to Table element
        private static readonly DependencyProperty[] _tableProperties = new DependencyProperty[]
            {
                Table.CellSpacingProperty,

                // Inherits Block properties
                Block.MarginProperty,
                Block.PaddingProperty,
                Block.BorderThicknessProperty,
                Block.BorderBrushProperty,

                // Inherits TextElement properties
                TextElement.BackgroundProperty,
                //TextElement.TextEffectsProperty, -- the property is not supported in text editor
            };

        // List of all non-inheritable properties applicable to TableColumn element
        private static readonly DependencyProperty[] _tableColumnProperties = new DependencyProperty[]
            {
                TableColumn.WidthProperty,
                TableColumn.BackgroundProperty,
            };

        // List of all non-inheritable properties applicable to TableRowGroup element
        private static readonly DependencyProperty[] _tableRowGroupProperties = new DependencyProperty[]
            {
                // Inherits TextElement properties
                TextElement.BackgroundProperty,
                //TextElement.TextEffectsProperty, -- the property is not supported in text editor
            };

        // List of all non-inheritable properties applicable to TableRow element
        private static readonly DependencyProperty[] _tableRowProperties = new DependencyProperty[]
            {
                // Inherits TextElement properties
                TextElement.BackgroundProperty,
                //TextElement.TextEffectsProperty, -- the property is not supported in text editor
            };

        // List of all non-inheritable properties applicable to TableCell element
        private static readonly DependencyProperty[] _tableCellProperties = new DependencyProperty[]
            {
                TableCell.ColumnSpanProperty,
                TableCell.RowSpanProperty,

                // Adds ownership to Block properties
                TableCell.PaddingProperty,
                TableCell.BorderThicknessProperty,
                TableCell.BorderBrushProperty,

                // Inherits TextElement properties
                TextElement.BackgroundProperty,
                //TextElement.TextEffectsProperty, -- the property is not supported in text editor
            };

        // List of all non-inheritable properties applicable to Floater element
        private static readonly DependencyProperty[] _floaterProperties = new DependencyProperty[]
            {
                Floater.HorizontalAlignmentProperty,
                Floater.WidthProperty,

                // Adds ownership to Block properties
                Floater.MarginProperty,
                Floater.PaddingProperty,
                Floater.BorderThicknessProperty,
                Floater.BorderBrushProperty,

                // Inherits TextElement properties
                TextElement.BackgroundProperty,
                //TextElement.TextEffectsProperty, -- the property is not supported in text editor
            };

        // List of all non-inheritable properties applicable to Figure element
        private static readonly DependencyProperty[] _figureProperties = new DependencyProperty[]
            {
                Figure.HorizontalAnchorProperty,
                Figure.VerticalAnchorProperty,
                Figure.HorizontalOffsetProperty,
                Figure.VerticalOffsetProperty,
                Figure.CanDelayPlacementProperty,
                Figure.WrapDirectionProperty,
                Figure.WidthProperty,
                Figure.HeightProperty,

                // Adds ownership to Block properties
                Figure.MarginProperty,
                Figure.PaddingProperty,
                Figure.BorderThicknessProperty,
                Figure.BorderBrushProperty,

                // Inherits TextElement properties
                TextElement.BackgroundProperty,
                //TextElement.TextEffectsProperty, -- the property is not supported in text editor
            };

        // List of all non-inheritable properties applicable to Block element
        private static readonly DependencyProperty[] _blockProperties = new DependencyProperty[]
            {
                Block.MarginProperty,
                Block.PaddingProperty,
                Block.BorderThicknessProperty,
                Block.BorderBrushProperty,
                Block.BreakPageBeforeProperty,
                Block.BreakColumnBeforeProperty,
                Block.ClearFloatersProperty,
                Block.IsHyphenationEnabledProperty,

                // Inherits TextElement properties
                TextElement.BackgroundProperty,
                //TextElement.TextEffectsProperty, -- the property is not supported in text editor
            };

        // List of all non-inheritable properties applicable to TextElement element
        private static readonly DependencyProperty[] _textElementPropertyList = new DependencyProperty[]
            {
                TextElement.BackgroundProperty,
                //TextElement.TextEffectsProperty, -- the property is not supported in text editor
            };

        // List of all non-inheritable properties applicable to TextElement element
        private static readonly DependencyProperty[] _imagePropertyList = new DependencyProperty[]
            {
                Image.SourceProperty,
                Image.StretchProperty,
                Image.StretchDirectionProperty,

                // Inherits FrameworkElement properties
                //FrameworkElement.StyleProperty,
                //FrameworkElement.OverridesDefaultStyleProperty,
                //FrameworkElement.DataContextProperty,
                FrameworkElement.LanguageProperty,
                //FrameworkElement.NameProperty,
                //FrameworkElement.TagProperty,
                //FrameworkElement.InputScopeProperty,
                FrameworkElement.LayoutTransformProperty,
                FrameworkElement.WidthProperty,
                FrameworkElement.MinWidthProperty,
                FrameworkElement.MaxWidthProperty,
                FrameworkElement.HeightProperty,
                FrameworkElement.MinHeightProperty,
                FrameworkElement.MaxHeightProperty,
                //FrameworkElement.FlowDirectionProperty,
                FrameworkElement.MarginProperty,
                FrameworkElement.HorizontalAlignmentProperty,
                FrameworkElement.VerticalAlignmentProperty,
                //FrameworkElement.FocusVisualStyleProperty,
                FrameworkElement.CursorProperty,
                FrameworkElement.ForceCursorProperty,
                //FrameworkElement.FocusableProperty,
                FrameworkElement.ToolTipProperty,
                //FrameworkElement.ContextMenuProperty,

                // Inherits UIElement properties
                //UIElement.AllowDropProperty,
                UIElement.RenderTransformProperty,
                UIElement.RenderTransformOriginProperty,
                UIElement.OpacityProperty,
                UIElement.OpacityMaskProperty,
                UIElement.BitmapEffectProperty,
                UIElement.BitmapEffectInputProperty,
                UIElement.VisibilityProperty,
                UIElement.ClipToBoundsProperty,
                UIElement.ClipProperty,
                UIElement.SnapsToDevicePixelsProperty,
            };

        // Behavioral property list
        private static readonly DependencyProperty[] _behavioralPropertyList = new DependencyProperty[]
            {
                UIElement.AllowDropProperty,
            };

        // Empty property list
        private static readonly DependencyProperty[] _emptyPropertyList = new DependencyProperty[] { };

        // Structural property list.
        // NB: Existing code depends on these being inheritable properties.
        private static readonly DependencyProperty[] _structuralCharacterProperties = new DependencyProperty[]
            {
                Inline.FlowDirectionProperty,
            };

        // List of inline properties (both inheritable or non-inheritable) that are "content" properties, not "formatting" properties.
        private static readonly DependencyProperty[] _nonFormattingCharacterProperties = new DependencyProperty[]
            {
                FrameworkElement.FlowDirectionProperty,
                FrameworkElement.LanguageProperty,
                Run.TextProperty,
            };

        #endregion Private Fields
    }
}


text:
from channels.routing import route
from . import consumers

channel_routing = {
    # This makes Django serve static files from settings.STATIC_URL, similar
    # to django.views.static.serve. This isn't ideal (not exactly production
    # quality) but it works for a minimal example.
    #'http.request': StaticFilesConsumer(),

    # Wire up websocket channels to our consumers:
    'websocket.connect': consumers.ws_connect,
    'websocket.receive': consumers.ws_receive,
    'websocket.disconnect': consumers.ws_disconnect,
}

redpajama_set_name: RedPajamaGithub


text:
<?php

/**
 * This code was generated by
 * \ / _    _  _|   _  _
 * | (_)\/(_)(_|\/| |(/_  v1.0.0
 * /       /
 */

namespace Twilio\Rest\Conversations\V1\Service\Conversation;

use Twilio\Deserialize;
use Twilio\Exceptions\TwilioException;
use Twilio\InstanceResource;
use Twilio\Options;
use Twilio\Rest\Conversations\V1\Service\Conversation\Message\DeliveryReceiptList;
use Twilio\Values;
use Twilio\Version;

/**
 * @property string $accountSid
 * @property string $chatServiceSid
 * @property string $conversationSid
 * @property string $sid
 * @property int $index
 * @property string $author
 * @property string $body
 * @property array[] $media
 * @property string $attributes
 * @property string $participantSid
 * @property \DateTime $dateCreated
 * @property \DateTime $dateUpdated
 * @property array $delivery
 * @property string $url
 * @property array $links
 */
class MessageInstance extends InstanceResource {
    protected $_deliveryReceipts;

    /**
     * Initialize the MessageInstance
     *
     * @param Version $version Version that contains the resource
     * @param mixed[] $payload The response payload
     * @param string $chatServiceSid The SID of the Conversation Service that the
     *                               resource is associated with.
     * @param string $conversationSid The unique ID of the Conversation for this
     *                                message.
     * @param string $sid A 34 character string that uniquely identifies this
     *                    resource.
     */
    public function __construct(Version $version, array $payload, string $chatServiceSid, string $conversationSid, string $sid = null) {
        parent::__construct($version);

        // Marshaled Properties
        $this->properties = [
            'accountSid' => Values::array_get($payload, 'account_sid'),
            'chatServiceSid' => Values::array_get($payload, 'chat_service_sid'),
            'conversationSid' => Values::array_get($payload, 'conversation_sid'),
            'sid' => Values::array_get($payload, 'sid'),
            'index' => Values::array_get($payload, 'index'),
            'author' => Values::array_get($payload, 'author'),
            'body' => Values::array_get($payload, 'body'),
            'media' => Values::array_get($payload, 'media'),
            'attributes' => Values::array_get($payload, 'attributes'),
            'participantSid' => Values::array_get($payload, 'participant_sid'),
            'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')),
            'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')),
            'delivery' => Values::array_get($payload, 'delivery'),
            'url' => Values::array_get($payload, 'url'),
            'links' => Values::array_get($payload, 'links'),
        ];

        $this->solution = [
            'chatServiceSid' => $chatServiceSid,
            'conversationSid' => $conversationSid,
            'sid' => $sid ?: $this->properties['sid'],
        ];
    }

    /**
     * Generate an instance context for the instance, the context is capable of
     * performing various actions.  All instance actions are proxied to the context
     *
     * @return MessageContext Context for this MessageInstance
     */
    protected function proxy(): MessageContext {
        if (!$this->context) {
            $this->context = new MessageContext(
                $this->version,
                $this->solution['chatServiceSid'],
                $this->solution['conversationSid'],
                $this->solution['sid']
            );
        }

        return $this->context;
    }

    /**
     * Update the MessageInstance
     *
     * @param array|Options $options Optional Arguments
     * @return MessageInstance Updated MessageInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function update(array $options = []): MessageInstance {
        return $this->proxy()->update($options);
    }

    /**
     * Delete the MessageInstance
     *
     * @param array|Options $options Optional Arguments
     * @return bool True if delete succeeds, false otherwise
     * @throws TwilioException When an HTTP error occurs.
     */
    public function delete(array $options = []): bool {
        return $this->proxy()->delete($options);
    }

    /**
     * Fetch the MessageInstance
     *
     * @return MessageInstance Fetched MessageInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function fetch(): MessageInstance {
        return $this->proxy()->fetch();
    }

    /**
     * Access the deliveryReceipts
     */
    protected function getDeliveryReceipts(): DeliveryReceiptList {
        return $this->proxy()->deliveryReceipts;
    }

    /**
     * Magic getter to access properties
     *
     * @param string $name Property to access
     * @return mixed The requested property
     * @throws TwilioException For unknown properties
     */
    public function __get(string $name) {
        if (\array_key_exists($name, $this->properties)) {
            return $this->properties[$name];
        }

        if (\property_exists($this, '_' . $name)) {
            $method = 'get' . \ucfirst($name);
            return $this->$method();
        }

        throw new TwilioException('Unknown property: ' . $name);
    }

    /**
     * Provide a friendly representation
     *
     * @return string Machine friendly representation
     */
    public function __toString(): string {
        $context = [];
        foreach ($this->solution as $key => $value) {
            $context[] = "$key=$value";
        }
        return '[Twilio.Conversations.V1.MessageInstance ' . \implode(' ', $context) . ']';
    }
}


text:
using System.Linq;
using Abp.Zero.SampleApp.EntityFramework;
using Abp.Zero.SampleApp.MultiTenancy;
using Abp.Zero.SampleApp.Users;

namespace Abp.Zero.SampleApp.Tests.Users
{
    public class UserLoginHelper
    {
        public static void CreateTestUsers(AppDbContext context)
        {
            var defaultTenant = context.Tenants.Single(t => t.TenancyName == Tenant.DefaultTenantName);

            CreateTestUsers(context,
                new User
                {
                    UserName = "userOwner",
                    Name = "Owner",
                    Surname = "One",
                    EmailAddress = "owner@aspnetboilerplate.com",
                    IsEmailConfirmed = true,
                    Password = "AM4OLBpptxBYmM79lGOX9egzZk3vIQU3d/gFCJzaBjAPXzYIK3tQ2N7X4fcrHtElTw==" //123qwe
                });

            CreateTestUsers(context,
                new User
                {
                    TenantId = defaultTenant.Id, //A user of tenant1
                    UserName = "user1",
                    Name = "User",
                    Surname = "One",
                    EmailAddress = "user-one@aspnetboilerplate.com",
                    IsEmailConfirmed = false,
                    Password = "AM4OLBpptxBYmM79lGOX9egzZk3vIQU3d/gFCJzaBjAPXzYIK3tQ2N7X4fcrHtElTw==" //123qwe
                });
        }

        private static void CreateTestUsers(AppDbContext context, User user)
        {
            user.SetNormalizedNames();

            context.Users.Add(user);
        }
    }
}


text:
package wallettemplate;

import com.google.leafcoin.core.AbstractWalletEventListener;
import com.google.leafcoin.core.DownloadListener;
import com.google.leafcoin.core.Utils;
import com.google.leafcoin.core.Wallet;
import javafx.animation.*;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.util.Duration;
import wallettemplate.controls.ClickableBitcoinAddress;

import java.math.BigInteger;
import java.util.Date;

import static wallettemplate.Main.bitcoin;
import static wallettemplate.utils.GuiUtils.checkGuiThread;

/**
 * Gets created auto-magically by FXMLLoader via reflection. The widget fields are set to the GUI controls they're named
 * after. This class handles all the updates and event handling for the main UI.
 */
public class Controller {
    public ProgressBar syncProgress;
    public VBox syncBox;
    public HBox controlsBox;
    public Label balance;
    public Button sendMoneyOutBtn;
    public ClickableBitcoinAddress addressControl;

    // Called by FXMLLoader.
    public void initialize() {
        syncProgress.setProgress(-1);
        addressControl.setOpacity(0.0);
    }

    public void onBitcoinSetup() {
        bitcoin.wallet().addEventListener(new BalanceUpdater());
        addressControl.setAddress(bitcoin.wallet().getKeys().get(0).toAddress(Main.params).toString());
        refreshBalanceLabel();
    }

    public void sendMoneyOut(ActionEvent event) {
        // Hide this UI and show the send money UI. This UI won't be clickable until the user dismisses send_money.
        Main.instance.overlayUI("send_money.fxml");
    }

    public class ProgressBarUpdater extends DownloadListener {
        @Override
        protected void progress(double pct, int blocksSoFar, Date date) {
            super.progress(pct, blocksSoFar, date);
            Platform.runLater(() -> syncProgress.setProgress(pct / 100.0));
        }

        @Override
        protected void doneDownload() {
            super.doneDownload();
            Platform.runLater(Controller.this::readyToGoAnimation);
        }
    }

    public void readyToGoAnimation() {
        // Sync progress bar slides out ...
        TranslateTransition leave = new TranslateTransition(Duration.millis(600), syncBox);
        leave.setByY(80.0);
        // Buttons slide in and clickable address appears simultaneously.
        TranslateTransition arrive = new TranslateTransition(Duration.millis(600), controlsBox);
        arrive.setToY(0.0);
        FadeTransition reveal = new FadeTransition(Duration.millis(500), addressControl);
        reveal.setToValue(1.0);
        ParallelTransition group = new ParallelTransition(arrive, reveal);
        // Slide out happens then slide in/fade happens.
        SequentialTransition both = new SequentialTransition(leave, group);
        both.setCycleCount(1);
        both.setInterpolator(Interpolator.EASE_BOTH);
        both.play();
    }

    public ProgressBarUpdater progressBarUpdater() {
        return new ProgressBarUpdater();
    }

    public class BalanceUpdater extends AbstractWalletEventListener {
        @Override
        public void onWalletChanged(Wallet wallet) {
            checkGuiThread();
            refreshBalanceLabel();
        }
    }

    public void refreshBalanceLabel() {
        final BigInteger amount = bitcoin.wallet().getBalance(Wallet.BalanceType.ESTIMATED);
        balance.setText(Utils.bitcoinValueToFriendlyString(amount));
    }
}


text:
class IllegalStateError(Exception):
  """Raised when a class is used in an incorrect state."""

def positional(max_positional_arguments):
  """A decorator to declare that only the first N arguments my be positional.

  This decorator makes it easy to support Python 3 style key-word only
  parameters.  For example, in Python 3 it is possible to write:

    def fn(pos1, *, kwonly1=None, kwonly1=None):
      ...

  All named parameters after * must be a keyword:

    fn(10, 'kw1', 'kw2')  # Raises exception.
    fn(10, kwonly1='kw1')  # Ok.

  Borrowed from ProtoRPC:

  http://code.google.com/p/google-protorpc/source/browse/python/protorpc/util.py#50

  Args:
    max_positional_arguments: Maximum number of positional arguments.  All
      parameters after the this index must be keyword only.

  Returns:
    A decorator that prevents using arguments after max_positional_args from
    being used as positional parameters.

  Raises:
    TypeError if a key-word only argument is provided as a positional parameter.
  """
  def positional_decorator(callable):
    def positional_wrapper(*args, **kwargs):
      if len(args) > max_positional_arguments:
        raise TypeError('Call to %s accepts only %d parameters' %
                        (callable.__name__, max_positional_arguments))
      return callable(*args, **kwargs)
    positional_wrapper.__name__ = callable.__name__
    return positional_wrapper
  return positional_decorator

class SourceOrdered:
  """Base class that remembers order its instances are created.

  Example:

    class Person(SourceOrdered):
      ...

    daniel = Person()
    tamy = Person()

    assert daniel.source_order < tamy.source_order
  """

  __next_source_order = 0

  def __init__(self):
    self.__source_order = self.__next_source_order
    SourceOrdered.__next_source_order += 1

  @property
  def source_order(self):
    return self.__source_order

  def __str__(self):
    return str(self.__source_order)

  __repr__ = __str__


text:
package org.codehaus.mojo.unix.io.fs;

import org.codehaus.mojo.unix.io.*;
import org.codehaus.mojo.unix.util.*;
import org.joda.time.*;

import java.io.*;

/**
 * Move the write methods into WrFs<F extends Fs> extends Fs<F>
 */
public interface Fs<F extends Fs>
    extends Closeable
{
    boolean exists();

    boolean isFile();

    boolean isDirectory();

    LocalDateTime lastModified();

    long size();

    F resolve( RelativePath relativePath );

    /**
     * The logical root of this file system. For local file system, it is the File it was created from, for archive
     * file system types it's the archive's File path.
     */
    File basedir();

    /**
     * The path inside the file system.
     */
    RelativePath relativePath();

    /**
     * For local files, File.getAbsolutePath. For archive files it's the archives path + "!" + relativePath
     */
    String absolutePath();

    InputStream inputStream()
        throws IOException;

    Iterable<F> find( IncludeExcludeFilter filter )
        throws IOException;

    void mkdir()
        throws IOException;

    void copyFrom( Fs<?> from )
        throws IOException;

    void copyFrom( Fs from, InputStream is )
        throws IOException;
}


text:
/* global require, process, console, exports */

var fs = require('fs'),
    path = require('path'),
    less = require('less');

var LessCompiler = function(config) {
  if(!config ){
    throw new Error('You must pass a config object to process-less');
  }

  var parser = new less.Parser({
    paths: [ config.src ]
  });

  return function processLess( req, res, next ){

    if(process.env.NODE_ENV === 'production') {
      return next();
    }

    var filename = req.url.match(/\/?(\S+).css$/);
    if( filename.length === 2 ){
      filename = filename[1];
    } else {
      return next();
    }

    var lessPath = path.resolve( config.src +'/'+ filename +'.less');

    fs.readFile(lessPath, 'utf-8', function( err, data ){
      if( err ) {
        console.log(err);
        res.writeHead(404);
        res.end();
      }

      parser.parse( data, function(err, css ){
        res.writeHead(200, {'Content-Type': 'text/css'});
        var errorMsg;
        if( err ){
          errorMsg = '/*\n';
          for(var i in err) {
            if( err.hasOwnProperty(i) ){
              errorMsg += ( i +': '+ err[i] + '\n' );
            }
          }
          errorMsg += '*/\n';
          console.log('\n====\n'+ errorMsg +'\n====\n');
        }
        res.end( errorMsg || css.toCSS() );
      });
    });
  };
}

exports.LessCompiler = LessCompiler;


text:
/* @flow */
/**
 * Checks for the status of a response. By default, fetch only reject when the
 * request completely fails to be made, not on server responses.
 */
export function valid( response: Object ): Promise<Object> {
    if ( response.status >= 200 && response.status < 300 ) {
        return Promise.resolve( response );
    }
    return Promise.reject( new Error( response.statusText ));
}

/**
 * Checks for the status of a response. By default, fetch only reject when the
 * request completely fails to be made, not on server responses.
 * Here on anything else then >200 and <300, we extract the json and reject the original promise
 */
export function validJson( response: Object ): Promise<Object> {
    if ( response.status >= 200 && response.status < 300 ) {
        return response.json();
    }

    return new Promise(( resolve: Function, reject: Function ) => {
        reject( response );
    });
}

/**
 * Tries to parse the JSON payload.
 */
export function json( response: Object ): Object {
    return response.json();
}


text:
<!DOCTYPE html>

  {% include head.html %}

    {% include nav-main.html %}

{% img '{{assets["github-corner-right.svg"].logical_path}}' alt:'Fork me on GitHub' %}

          {% include nav-documentation.html %}

          {% contentblock header %}

      {% contentblock body %}

    {% include footer.html %}


text:
ACCEPTED

#### According to
Index Fungorum

#### Published in
null

#### Original name
Diaporthe mitis Sacc.

### Remarks
null


text:
import React, { Component } from 'react';
import { Link, Route, Redirect, Switch } from 'react-router-dom';
import feathersApp from './feathers';
import update from 'immutability-helper';

import Main from './components/Main';
import Spinner from 'react-spinner-material';
import Navigation from './components/Navigation';
import PrivateRoute from './components/PrivateRoute';
import Home from './components/Home';
import NoMatch from './components/NoMatch';
import Login from './components/Login';
import Register from './components/Register';
import EntryForm from './components/entries/entry_form';
import EntryList from './components/EntryList';
import CreateReport from './components/reports/CreateReport';

const style = {
    display: 'flex',
    alignItems: 'stretch',
    flexDirection: 'column'
};

class App extends Component {
    constructor(props) {
        super(props);
        this.state = {
            loading: false,
        }
        this.renderView = this.renderView.bind(this);
        this.authenticate = this.authenticate.bind(this);
    }

    componentWillMount() {
        console.log(this.authenticate().then(user => console.log(user)));
        this.authenticate().then(user => {
            const newState = update(this.state, {
                user: {$set: user},
            });
            this.setState(newState);
        });
    }

    authenticate(options) {
        const newState = update(this.state, {
            loading: { $set: true }
        });
        this.setState(newState);
        return feathersApp.authenticate(options ? options : {}).then(response => {
            return feathersApp.passport.verifyJWT(response.accessToken);
        }).then(payload => {
            return feathersApp.service('users').get(payload.userId);
        }).then(user => {
            feathersApp.set('user', user);
            return user;
        }).catch(error => {
            console.log('Error:', error.message);
            return {};
        });
    }

    renderView() {
        const { user } = this.state;
        const LoginComponent = () => <Login authenticate={this.authenticate}/>
        return (

                    <Navigation user={user}/>

                    <Switch>
                        <PrivateRoute path='/' exact component={Home} user={user} />
                        <Route path="/login" exact component={LoginComponent} />
                        <Route path="/register" exact component={Register} />
                        <PrivateRoute path='/entries' exact component={EntryList} user={user} />
                        <PrivateRoute path="/entries/new" exact component={EntryForm} user={user} />
                        <PrivateRoute path="/reports/new" exact component={CreateReport} user={user} />
                        <Route path="*" component={NoMatch} />
                    </Switch>

       );
    }

    render() {
        return (
            this.state.user ?
            this.renderView() :

Loading...

        )
    }
}

export default App;


text: docker run -d -v $PWD:/app -w /app tsavo/hippo:latest mvn install exec:exec


text:
package me.nithanim.cultures.formats.lib.internal;

interface ArchiveFile {
    void readMetas();

    int getUnknown();
    int getFileCount();
    FileMeta[] getFileMetas();
}


text:
package net.uchoice.exf.core.config.parser.rule;

import net.uchoice.exf.client.exception.ErrorMessage;
import net.uchoice.exf.core.config.exception.VariableConfigException;
import net.uchoice.exf.core.runtime.resolver.PropVariableResolver;
import net.uchoice.exf.model.variable.Variable;
import net.uchoice.exf.model.variable.VariableMode;
import net.uchoice.exf.model.variable.VariableSpec;
import org.apache.commons.digester3.AbstractObjectCreationFactory;
import org.apache.commons.lang.StringUtils;
import org.xml.sax.Attributes;

public class ActionFiledCreatingFactory extends AbstractObjectCreationFactory<Variable> {

    @Override
    public Variable createObject(Attributes attributes) throws Exception {
        Variable variable = new Variable();
        String name = null;
        String value = null;
        int len = attributes.getLength();
        for (int i = 0; i < len; i++) {
            String qname = attributes.getQName(i);
            if (qname.equals("name")) {
                name = attributes.getValue(i);
            }
            if (qname.equals("value")) {
                value = attributes.getValue(i);
            }
        }
        if (StringUtils.isBlank(name) || StringUtils.isBlank(value)) {
            throw new VariableConfigException(
                ErrorMessage.code("S-EXF-01-01-008", name, VariableMode.PROP.name(), value));
        }
        VariableSpec variableSpec = new VariableSpec();
        variableSpec.setMode(VariableMode.PROP);
        variableSpec.setName(name);
        variable.setValue(value);
        variable.setVariableSpec(variableSpec);
        variable.setResolver(PropVariableResolver.get());
        return variable;
    }
}


text:
var Rainbow = function() {
	this.service = null; //服务名
	this.method = null; //方法名
	this.dbname = null;
	this.rows = []; //多条记录容器,相当于java中List<Map>
	this.attr = Object();//单条记录属性相当java中,Map

	Rainbow.prototype.setService = function(name) {
		this.service = name;
	};
	Rainbow.prototype.getService = function() {
		return this.service;
	};

	Rainbow.prototype.setMethod = function(name) {
		this.method = name;
	};

	Rainbow.prototype.getDbname = function() {
		return this.dbname;
	};

	Rainbow.prototype.setDbname = function(name) {
		this.dbname = name;
	};
	Rainbow.prototype.getMethod = function() {
		return this.method;
	};

	Rainbow.prototype.setRows = function(rows) {
		if(rows instanceof Array){
			this.rows = rows;
		}
	};
	Rainbow.prototype.getRows = function() {
		return this.rows;
	};
	Rainbow.prototype.addRows = function(row) {
		if(row != null){
			this.rows.push(row);
		}
	};
	Rainbow.prototype.set = function(key, value) {
		this.attr[key] = value;
	};
	Rainbow.prototype.setParam = function(key, value) {
		this[key] = value;
	};
	Rainbow.prototype.removeParam = function(key) {
		delete this.attr[key];
	};

	Rainbow.prototype.setAttr = function(data){
		if(data != null && typeof(data) == "object"){
			for(var key in data){
				this.attr[key] = data[key];
			}
		}

	};

	Rainbow.prototype.getAttr = function(){
		return this.attr;

	};

};