Пример #1
0
 public MultisetField(string name, IonValue value)
 {
     Debug.Assert(name != null);
     _name  = name;
     _value = value;
     Count  = 0;
 }
Пример #2
0
        public override bool IsEquivalentTo(IonValue other)
        {
            if (!(other is IonInt oInt))
            {
                return(false);
            }
            if (NullFlagOn())
            {
                return(oInt.IsNull);
            }
            if (oInt.IsNull)
            {
                return(false);
            }
            if (oInt.IntegerSize != IntegerSize)
            {
                return(false);
            }
            switch (IntegerSize)
            {
            case IntegerSize.Int:
                return(IntValue == oInt.IntValue);

            case IntegerSize.Long:
                return(LongValue == oInt.LongValue);

            case IntegerSize.BigInteger:
                return(BigIntegerValue == oInt.BigIntegerValue);

            default:
                return(false);
            }
        }
Пример #3
0
        public override bool IsEquivalentTo(IonValue other)
        {
            if (!base.IsEquivalentTo(other))
            {
                return(false);
            }

            var oFloat = (IonFloat)other;

            if (NullFlagOn())
            {
                return(oFloat.IsNull);
            }
            if (oFloat.IsNull)
            {
                return(false);
            }

            if (PrivateHelper.IsNegativeZero(_d) ^ PrivateHelper.IsNegativeZero(oFloat._d))
            {
                return(false);
            }

            return(EqualityComparer <double> .Default.Equals(oFloat.Value, Value));
        }
Пример #4
0
        /// <inheritdoc />
        /// <remarks>
        /// Struct equivalence is an expensive operation.
        /// </remarks>
        public override bool IsEquivalentTo(IonValue other)
        {
            if (!(other is IonStruct otherStruct))
            {
                return(false);
            }
            if (NullFlagOn())
            {
                return(other.IsNull);
            }
            if (other.IsNull || otherStruct.Count != Count)
            {
                return(false);
            }

            if (_values.Count != otherStruct._values.Count)
            {
                return(false);
            }

            var multiset = ToMultiset();

            foreach (var v2 in otherStruct._values)
            {
                var field = new MultisetField(v2.FieldNameSymbol.Text, v2);
                if (!multiset.TryGetValue(field, out var mapped) || mapped.Count == 0)
                {
                    return(false);
                }
                mapped.Count--;
            }

            return(true);
        }
Пример #5
0
        public override bool IsEquivalentTo(IonValue other)
        {
            if (!base.IsEquivalentTo(other))
            {
                return(false);
            }

            var otherDec = (IonDecimal)other;

            if (NullFlagOn())
            {
                return(otherDec.IsNull);
            }
            if (other.IsNull)
            {
                return(false);
            }

            if (BigDecimalValue.IsNegativeZero ^ otherDec.BigDecimalValue.IsNegativeZero)
            {
                return(false);
            }

            if (otherDec.BigDecimalValue.Scale > 0 || BigDecimalValue.Scale > 0)
            {
                //precision matters, make sure that this has the same precision
                return(BigDecimalValue.Scale == otherDec.BigDecimalValue.Scale &&
                       BigDecimalValue.IntVal == otherDec.BigDecimalValue.IntVal);
            }

            //this only compares values
            return(BigDecimalValue == otherDec.BigDecimalValue);
        }
Пример #6
0
 public MultisetField(SymbolToken name, IonValue value)
 {
     Debug.Assert(name != null);
     _name  = name;
     _value = value;
     Count  = 0;
 }
Пример #7
0
        /// <summary>
        /// Returns true if this value is equivalent to the other, false otherwise.
        /// </summary>
        /// <param name="other">The other value.</param>
        /// <remarks>
        /// Equivalency is determined by whether the <see cref="IonValue"/> objects has the same annotations,
        /// hold equal values, or in the case of container, they contain equivalent sets of children.
        /// </remarks>
        public virtual bool IsEquivalentTo(IonValue other)
        {
            if (other == null || Type != other.Type)
            {
                return(false);
            }

            var otherAnnotations = other._annotations;

            if (_annotations == null)
            {
                return(otherAnnotations == null || otherAnnotations.Count == 0);
            }

            if (otherAnnotations == null || otherAnnotations.Count != _annotations.Count)
            {
                return(false);
            }

            for (int i = 0, l = _annotations.Count; i < l; i++)
            {
                if (!_annotations[i].IsEquivalentTo(otherAnnotations[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #8
0
 public override bool IsEquivalentTo(IonValue other)
 {
     if (!(other is IonString otherString))
     {
         return(false);
     }
     return(StringVal == otherString.StringVal);
 }
Пример #9
0
        public override bool Contains(IonValue item)
        {
            if (NullFlagOn() || item is null)
            {
                return(false);
            }

            Debug.Assert(_values != null);
            return(item.Container == this);
        }
Пример #10
0
 public override bool IsEquivalentTo(IonValue other)
 {
     if (!(other is IonBlob otherBlob))
     {
         return(false);
     }
     if (NullFlagOn())
     {
         return(otherBlob.IsNull);
     }
     return(!otherBlob.IsNull && otherBlob.Bytes().SequenceEqual(Bytes()));
 }
Пример #11
0
 public override bool IsEquivalentTo(IonValue other)
 {
     if (!(other is IonDecimal otherDec))
     {
         return(false);
     }
     if (NullFlagOn())
     {
         return(otherDec.IsNull);
     }
     return(!otherDec.IsNull && otherDec.DecimalValue == DecimalValue);
 }
Пример #12
0
        public override bool IsEquivalentTo(IonValue other)
        {
            if (!(other is IonTimestamp oTimestamp))
            {
                return(false);
            }
            if (NullFlagOn())
            {
                return(other.IsNull);
            }

            return(!other.IsNull && _timestamp == oTimestamp._timestamp);
        }
Пример #13
0
        public override bool IsEquivalentTo(IonValue other)
        {
            if (!(other is IonFloat oFloat))
            {
                return(false);
            }

            if (NullFlagOn())
            {
                return(oFloat.IsNull);
            }

            return(!oFloat.IsNull && EqualityComparer <double> .Default.Equals(oFloat.Value, Value));
        }
Пример #14
0
        public override bool IsEquivalentTo(IonValue other)
        {
            if (!(other is IonSymbol oSymbol))
            {
                return(false);
            }

            if (NullFlagOn())
            {
                return(oSymbol.IsNull);
            }

            return(!oSymbol.IsNull && oSymbol.StringVal == StringValue);
        }
Пример #15
0
        public override bool IsEquivalentTo(IonValue other)
        {
            if (!(other is IonBool otherBool))
            {
                return(false);
            }

            if (NullFlagOn())
            {
                return(otherBool.IsNull);
            }

            return(!otherBool.IsNull && otherBool.Value == Value);
        }
Пример #16
0
        public override bool IsEquivalentTo(IonValue other)
        {
            if (!base.IsEquivalentTo(other))
            {
                return(false);
            }

            var otherBool = (IonBool)other;

            if (NullFlagOn())
            {
                return(otherBool.IsNull);
            }

            return(!otherBool.IsNull && otherBool.Value == Value);
        }
Пример #17
0
        /// <summary>
        /// Add a new value to this struct.
        /// </summary>
        /// <param name="fieldName">Field name</param>
        /// <param name="value">Ion value to add.</param>
        /// <exception cref="ArgumentNullException">When field name is null.</exception>
        /// <exception cref="ContainedValueException">If the value is already child of a container.</exception>
        public void Add(string fieldName, IonValue value)
        {
            if (fieldName is null)
            {
                throw new ArgumentNullException(nameof(fieldName));
            }
            ThrowIfLocked();
            ThrowIfNull();
            if (value.Container != null)
            {
                throw new ContainedValueException(value);
            }

            value.FieldNameSymbol = new SymbolToken(fieldName, SymbolToken.UnknownSid);
            value.Container       = this;
            _values.Add(value);
        }
Пример #18
0
        public override bool Remove(IonValue item)
        {
            ThrowIfNull();
            ThrowIfLocked();
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            if (item.Container != this)
            {
                return(false);
            }

            Debug.Assert(item.FieldNameSymbol != default && _values != null);
            _values.Remove(item);
            item.Container       = null;
            item.FieldNameSymbol = default;
            return(true);
        }
Пример #19
0
        public void Add(SymbolToken symbol, IonValue value)
        {
            if (symbol.Text != null)
            {
                Add(symbol.Text, value);
                return;
            }

            if (symbol.Sid < 0)
            {
                throw new ArgumentException("symbol has no text or sid", nameof(symbol));
            }
            ThrowIfLocked();
            ThrowIfNull();
            if (value.Container != null)
            {
                throw new ContainedValueException(value);
            }

            value.FieldNameSymbol = symbol;
            value.Container       = this;
            _values.Add(value);
        }
Пример #20
0
 /// <summary>
 /// Returns true if this value is equivalent to the other, false otherwise.
 /// </summary>
 /// <param name="other">The other value.</param>
 /// <remarks>
 /// Equivalency is determined by whether the <see cref="IonValue"/> objects hold equal values, or
 /// in the case of container, they contain equivalent sets of children.
 /// </remarks>
 public abstract bool IsEquivalentTo(IonValue other);
Пример #21
0
 /// <inheritdoc />
 /// <summary>
 /// Use strict reference equality for datagram.
 /// </summary>
 public override bool IsEquivalentTo(IonValue other) => other == this;
Пример #22
0
 public override bool IsEquivalentTo(IonValue other) => other is IonNull;
Пример #23
0
 public override void Add(IonValue item)
 => throw new NotSupportedException("Cannot add a value to a struct without field name");