1 //---------------------------------------------------------------------
2 // <copyright file="Literal.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
11 using System.Collections.Generic;
13 using System.Globalization;
14 using System.Collections.ObjectModel;
15 using System.Diagnostics;
17 namespace System.Data.Common.Utils.Boolean
20 /// Represents a literal in a normal form expression of the form:
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;
36 /// Initialize a new literal.
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);
45 _isTermPositive = isTermPositive;
49 /// Gets literal term.
51 internal TermExpr<T_Identifier> Term
57 /// Gets sign of term.
59 internal bool IsTermPositive
61 get { return _isTermPositive; }
65 /// Creates a negated version of this literal.
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 : "!",
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();