Ejemplo n.º 1
0
 public bool Equals(IMessageId other)
 {
     if(other == null || other.GetType() != GetType())
         return false;
     return ((MessageId)other).id == id;
 }
Ejemplo n.º 2
0
        public int CompareTo(IMessageId o)
        {
            if (o is BatchMessageId bm)
            {
                var ord           = 0;
                var ledgercompare = _ledgerId.CompareTo(bm.LedgerId);

                if (ledgercompare != 0)
                {
                    ord = ledgercompare;
                }

                var entryCompare = EntryId.CompareTo(bm.EntryId);
                if (entryCompare != 0 && ord == 0)
                {
                    ord = entryCompare;
                }

                var partitionCompare = PartitionIndex.CompareTo(bm.PartitionIndex);
                if (partitionCompare != 0 && ord == 0)
                {
                    ord = partitionCompare;
                }

                var result = ledgercompare == 0 && entryCompare == 0 && partitionCompare == 0;
                if (result && bm.BatchIndex > -1)
                {
                    return(-1);
                }

                return(ord);
            }
            if (o is MessageId other)
            {
                var ledgerCompare = _ledgerId.CompareTo(other.LedgerId);
                if (ledgerCompare != 0)
                {
                    return(ledgerCompare);
                }

                var entryCompare = _entryId.CompareTo(other.EntryId);
                if (entryCompare != 0)
                {
                    return(entryCompare);
                }

                var partitionedCompare = _partitionIndex.CompareTo(other.PartitionIndex);
                if (partitionedCompare != 0)
                {
                    return(partitionedCompare);
                }

                return(0);
            }
            if (o is TopicMessageId impl)
            {
                return(CompareTo(impl.InnerMessageId));
            }
            throw new ArgumentException("expected MessageId object. Got instance of " + o.GetType().FullName);
        }
Ejemplo n.º 3
0
        // If all messageId in map are same Size, and all bigger/smaller than the other, return valid value.
        public int CompareTo(IMessageId o)
        {
            if (!(o is MultiMessageId))
            {
                throw new ArgumentException("expected MultiMessageId object. Got instance of " + o.GetType().FullName);
            }

            var other    = (MultiMessageId)o;
            var otherMap = other.Map;

            if ((Map == null || Map.Count == 0) && (otherMap == null || otherMap.Count == 0))
            {
                return(0);
            }

            if (otherMap == null || Map == null || otherMap.Count != Map.Count)
            {
                throw new ArgumentException("Current Size and other Size not equals");
            }

            var result = 0;

            foreach (var entry in HashMapHelper.SetOfKeyValuePairs(Map))
            {
                if (!otherMap.TryGetValue(entry.Key, out var otherMessage))
                {
                    throw new ArgumentException("Other MessageId not have topic " + entry.Key);
                }

                var currentResult = entry.Value.CompareTo(otherMessage);
                if (result == 0)
                {
                    result = currentResult;
                }
                else if (currentResult == 0)
                {
                    continue;
                }
                else if (result != currentResult)
                {
                    throw new ArgumentException("Different MessageId in Map get different compare result");
                }
                else
                {
                    continue;
                }
            }

            return(result);
        }