Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Common / Utils / Boolean / Literal.cs
blob90f18519cfaa9d5d20c70ec37f2532116fcd9d8e
1 //---------------------------------------------------------------------
2 // <copyright file="Literal.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 //
6 // @owner Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
10 using System;
11 using System.Collections.Generic;
12 using System.Text;
13 using System.Globalization;
14 using System.Collections.ObjectModel;
15 using System.Diagnostics;
17 namespace System.Data.Common.Utils.Boolean
19 /// <summary>
20 /// Represents a literal in a normal form expression of the form:
21 ///
22 /// Term
23 ///
24 /// or
25 ///
26 /// !Term
27 /// </summary>
28 /// <typeparam name="T_Identifier"></typeparam>
29 internal sealed class Literal<T_Identifier> : NormalFormNode<T_Identifier>,
30 IEquatable<Literal<T_Identifier>>
32 private readonly TermExpr<T_Identifier> _term;
33 private readonly bool _isTermPositive;
35 /// <summary>
36 /// Initialize a new literal.
37 /// </summary>
38 /// <param name="term">Term</param>
39 /// <param name="isTermPositive">Sign of term</param>
40 internal Literal(TermExpr<T_Identifier> term, bool isTermPositive)
41 : base(isTermPositive ? (BoolExpr<T_Identifier>)term : (BoolExpr<T_Identifier>)new NotExpr<T_Identifier>(term))
43 Debug.Assert(null != term);
44 _term = term;
45 _isTermPositive = isTermPositive;
48 /// <summary>
49 /// Gets literal term.
50 /// </summary>
51 internal TermExpr<T_Identifier> Term
53 get { return _term; }
56 /// <summary>
57 /// Gets sign of term.
58 /// </summary>
59 internal bool IsTermPositive
61 get { return _isTermPositive; }
64 /// <summary>
65 /// Creates a negated version of this literal.
66 /// </summary>
67 /// <returns>!this</returns>
68 internal Literal<T_Identifier> MakeNegated()
70 return IdentifierService<T_Identifier>.Instance.NegateLiteral(this);
73 public override string ToString()
75 return StringUtil.FormatInvariant("{0}{1}",
76 _isTermPositive ? String.Empty : "!",
77 _term);
80 public override bool Equals(object obj)
82 Debug.Fail("use typed Equals");
83 return Equals(obj as Literal<T_Identifier>);
86 public bool Equals(Literal<T_Identifier> other)
88 return null != other &&
89 other._isTermPositive == _isTermPositive &&
90 other._term.Equals(_term);
93 public override int GetHashCode()
95 return _term.GetHashCode();