private static StringContainsNonLiteralState Merge(StringContainsNonLiteralState value1, StringContainsNonLiteralState value2)
 {
     // + U Y M N
     // U U Y M N
     // Y Y Y M M
     // M M M M M
     // N N N M N
     if (value1 == StringContainsNonLiteralState.Maybe || value2 == StringContainsNonLiteralState.Maybe)
     {
         return(StringContainsNonLiteralState.Maybe);
     }
     else if (value1 == StringContainsNonLiteralState.Undefined)
     {
         return(value2);
     }
     else if (value2 == StringContainsNonLiteralState.Undefined)
     {
         return(value1);
     }
     else if (value1 != value2)
     {
         // One of the values must be 'Yes' and other value must be 'No'.
         return(StringContainsNonLiteralState.Maybe);
     }
     else
     {
         return(value1);
     }
 }
        /// <summary>
        /// Performs the union of this state and the other state
        /// and returns a new <see cref="StringContentAbstractValue"/> with the result.
        /// </summary>
        public StringContentAbstractValue Merge(StringContentAbstractValue otherState)
        {
            if (otherState == null)
            {
                throw new ArgumentNullException(nameof(otherState));
            }

            ImmutableHashSet <string>     mergedLiteralValues   = LiteralValues.Union(otherState.LiteralValues);
            StringContainsNonLiteralState mergedNonLiteralState = Merge(NonLiteralState, otherState.NonLiteralState);

            return(Create(mergedLiteralValues, mergedNonLiteralState));
        }
        /// <summary>
        /// Performs the union of this state and the other state for a Binary add operation
        /// and returns a new <see cref="StringContentAbstractValue"/> with the result.
        /// </summary>
        public StringContentAbstractValue MergeBinaryAdd(StringContentAbstractValue otherState)
        {
            if (otherState == null)
            {
                throw new ArgumentNullException(nameof(otherState));
            }

            // Merge Literals
            var builder = ImmutableHashSet.CreateBuilder <string>();

            foreach (var leftLiteral in LiteralValues)
            {
                foreach (var rightLiteral in otherState.LiteralValues)
                {
                    builder.Add(leftLiteral + rightLiteral);
                }
            }

            ImmutableHashSet <string>     mergedLiteralValues   = builder.ToImmutable();
            StringContainsNonLiteralState mergedNonLiteralState = Merge(NonLiteralState, otherState.NonLiteralState);

            return(new StringContentAbstractValue(mergedLiteralValues, mergedNonLiteralState));
        }
        private static StringContainsNonLiteralState Merge(StringContainsNonLiteralState value1, StringContainsNonLiteralState value2)
        {
            // + U I M N
            // U U U M N
            // I U I M N
            // M M M M M
            // N N N M N
            if (value1 == StringContainsNonLiteralState.Maybe || value2 == StringContainsNonLiteralState.Maybe)
            {
                return(StringContainsNonLiteralState.Maybe);
            }
            else if (value1 == StringContainsNonLiteralState.Invalid || value1 == StringContainsNonLiteralState.Undefined)
            {
                return(value2);
            }
            else if (value2 == StringContainsNonLiteralState.Invalid || value2 == StringContainsNonLiteralState.Undefined)
            {
                return(value1);
            }

            Debug.Assert(value1 == StringContainsNonLiteralState.No);
            Debug.Assert(value2 == StringContainsNonLiteralState.No);
            return(StringContainsNonLiteralState.No);
        }
        private static StringContentAbstractValue Create(ImmutableHashSet <string> literalValues, StringContainsNonLiteralState nonLiteralState)
        {
            if (literalValues.IsEmpty)
            {
                switch (nonLiteralState)
                {
                case StringContainsNonLiteralState.Undefined:
                    return(UndefinedState);

                case StringContainsNonLiteralState.Yes:
                    return(ContainsNonLiteralState);

                case StringContainsNonLiteralState.No:
                    return(DoesNotContainNonLiteralState);

                default:
                    return(MayBeContainsNonLiteralState);
                }
            }

            return(new StringContentAbstractValue(literalValues, nonLiteralState));
        }
 private StringContentAbstractValue(ImmutableHashSet <string> literalValues, StringContainsNonLiteralState nonLiteralState)
 {
     LiteralValues   = literalValues;
     NonLiteralState = nonLiteralState;
 }