Exemple #1
0
        /// <summary>
        /// Determines semantic equality of this instance with another
        /// </summary>
        public override BL SemanticEquals(IAny other)
        {
            if (other == null)
            {
                return(null);
            }
            else if (this.IsNull && other.IsNull)
            {
                return new BL()
                       {
                           NullFlavor = NullFlavorUtil.GetCommonParent(this.NullFlavor, other.NullFlavor)
                       }
            }
            ;
            else if (this.IsNull ^ other.IsNull)
            {
                return new BL()
                       {
                           NullFlavor = DataTypes.NullFlavor.NotApplicable
                       }
            }
            ;
            else if (!(other is ICodedSimple))
            {
                return(false);
            }

            return(!this.IsNull && !(other as ANY).IsNull && this.Code != null && (other as ICodedSimple).CodeValue != null && Util.ToWireFormat(this.Code).Equals(Util.ToWireFormat((other as ICodedSimple).CodeValue)));
        }
Exemple #2
0
        /// <summary>
        /// Compares this instance of ANY with another
        /// </summary>
        /// <param name="other">The other <see cref="T:MARC.Everest.Datatypes.ANY"/> to comapre</param>
        /// <returns>True if this instance and <paramref name="other"/> are semantically equal</returns>
        /// <remarks>Since the semantic equals method uses the native boolean type for its implementation, the following alterations have been made
        /// to the equality rules:
        /// <list type="number">
        /// <item><description>If <paramref name="other"/> is null the result is null</description></item>
        /// <item><description>If <paramref name="other"/> has a nullFlavor or this instance has a nullflavor the result is a BL with a nullFlavor of NA (as per 7.1.4 of reference guide) or the most common null flavor between the two. </description></item>
        /// <item><description>If <paramref name="other"/>'s data type does not equal this instance's data type the result is false</description></item>
        /// <item><description>If <paramref name="other"/> and this instance have a null flavor, the common anscestor </description></item>
        /// </list>
        /// </para></remarks>
        public virtual BL SemanticEquals(IAny other)
        {
            if (other == null)
            {
                return(null);
            }
            else if (this.IsNull && other.IsNull)
            {
                return new BL()
                       {
                           NullFlavor = NullFlavorUtil.GetCommonParent(this.NullFlavor, other.NullFlavor)
                       }
            }
            ;
            else if (this.IsNull ^ other.IsNull)
            {
                return new BL()
                       {
                           NullFlavor = DataTypes.NullFlavor.NotApplicable
                       }
            }
            ;
            // Have the same type
            bool isEqual = other.DataType == this.DataType;

            return(isEqual);
        }
Exemple #3
0
        public BL And(BL b1)
        {
            if (this.IsNull && b1.IsNull)
            {
                return new BL()
                       {
                           NullFlavor = NullFlavorUtil.GetCommonParent(this.NullFlavor, b1.NullFlavor)
                       }
            }
            ;

            // Truth table
            // b1 > f t n
            // f    f f f
            // t    f t n
            // n    f n n
            bool?[][] truth = new bool?[][] {
                new bool?[] { false, false, false },
                new bool?[] { false, true, null },
                new bool?[] { false, null, null }
            };

            int tx = this.Value == null ? 2 : Math.Abs(Convert.ToInt16(this.Value));
            int ty = b1 == null || b1.Value == null ? 2 : Math.Abs(Convert.ToInt16(b1.Value));

            // New value
            BL retVal = new BL();

            retVal.Value = truth[tx][ty];
            if (retVal.Value == null)
            {
                retVal.NullFlavor = new CS <NullFlavor>(DataTypes.NullFlavor.NotApplicable);
            }
            return(retVal);
        }
Exemple #4
0
        /// <summary>
        /// Determine semantic equality to a coded simple
        /// </summary>
        public override BL SemanticEquals(IAny other)
        {
            if (other == null)
            {
                return(null);
            }
            else if (this.IsNull && other.IsNull)
            {
                return new BL()
                       {
                           NullFlavor = NullFlavorUtil.GetCommonParent(this.NullFlavor, other.NullFlavor)
                       }
            }
            ;
            else if (this.IsNull ^ other.IsNull)
            {
                return new BL()
                       {
                           NullFlavor = DataTypes.NullFlavor.NotApplicable
                       }
            }
            ;
            else if (other is CO)
            {
                CO otherCo = other as CO;

                if (this.Code == null || otherCo.Code == null)
                {
                    return(false);
                }
                return(this.Code.SemanticEquals(otherCo.Code));
            }
            else if (other is ICodedSimple && this.Code != null)
            {
                return(this.Code.SemanticEquals(other));
            }
            else
            {
                return(false);
            }
        }
Exemple #5
0
        /// <summary>
        /// Determines semantic equality between this instance of NPPD and <paramref name="other"/>
        /// </summary>
        public override BL SemanticEquals(MARC.Everest.DataTypes.Interfaces.IAny other)
        {
            if (other == null)
            {
                return(null);
            }
            else if (this.IsNull && other.IsNull)
            {
                return new BL()
                       {
                           NullFlavor = NullFlavorUtil.CommonAncestorWith(this.NullFlavor, other.NullFlavor)
                       }
            }
            ;
            else if (this.IsNull ^ other.IsNull)
            {
                return new BL()
                       {
                           NullFlavor = DataTypes.NullFlavor.NotApplicable
                       }
            }
            ;
            else if (!other.GetType().IsGenericType ||
                     other.GetType().GetGenericTypeDefinition().Equals(typeof(NPPD <>)))
            {
                return(false);
            }

            // Items must be in both sets
            int  otherNppdCount = 0;
            bool isEqual        = true;

            foreach (object itm in (other as IEnumerable))
            {
                isEqual &= this.Items.Contains(itm as UVP <T>);
                otherNppdCount++;
            }
            return(isEqual && otherNppdCount.Equals(this.Items.Count));
        }
Exemple #6
0
        /// <summary>
        /// Semantic equals
        /// </summary>
        public override BL SemanticEquals(IAny other)
        {
            if (other == null)
            {
                return(null);
            }
            else if (this.IsNull && other.IsNull)
            {
                return new BL()
                       {
                           NullFlavor = NullFlavorUtil.CommonAncestorWith(this.NullFlavor, other.NullFlavor)
                       }
            }
            ;
            else if (this.IsNull ^ other.IsNull)
            {
                return new BL()
                       {
                           NullFlavor = DataTypes.NullFlavor.NotApplicable
                       }
            }
            ;

            ST otherSt = other as ST;

            if (otherSt != null)
            {
                return(otherSt.Value != null?otherSt.Value.Equals(this.Value) : this.Value == null);
            }
            ED otherEd = other as ED; // ST may also be equal to ED when value is text/plain

            if (otherEd.MediaType == "text/plain")
            {
                return(otherEd.Value != null?otherEd.Value.Equals(this.Value) : this.Value == null);
            }
            return(false);
        }
    }
 /// <summary>
 /// Gets a common ancestor
 /// </summary>
 public static NullFlavor CommonAncestorWith(this CS <NullFlavor> a, CS <NullFlavor> other)
 {
     return(NullFlavorUtil.CommonAncestorWith((NullFlavor)a, (NullFlavor)other));
 }
Exemple #8
0
 /// <summary>
 /// Gets a common ancestor
 /// </summary>
 public static NullFlavor GetCommonParent(this CS <NullFlavor> a, CS <NullFlavor> other)
 {
     return(NullFlavorUtil.GetCommonParent((NullFlavor)a, (NullFlavor)other));
 }