/// <summary>
        /// Compare two entries based on the rules specified by <b>IComparer</b>.
        /// </summary>
        /// <remarks>
        /// <p>
        /// If possible, use the <see cref="IQueryCacheEntry.Extract"/>
        /// method to optimize the value extraction process.</p>
        /// <p>
        /// This method is expected to be implemented by <b>IComparer</b>
        /// wrappers, which simply pass on this invocation to the wrapped
        /// <b>IComparer</b> objects if they too implement this interface, or
        /// to invoke their default compare method passing the actual objects
        /// (not the extracted values) obtained from the extractor using the
        /// passed entries.</p>
        /// <p>
        /// This interface is also expected to be implemented by
        /// <see cref="IValueExtractor"/> implementations that implement the
        /// <b>IComparer</b> interface. It is expected that in most cases,
        /// the <b>IComparer</b> wrappers will eventually terminate at (i.e.
        /// delegate to) <b>IValueExtractors</b> that also implement this
        /// interface.</p>
        /// </remarks>
        /// <param name="entry1">
        /// The first entry to compare values from; read-only.
        /// </param>
        /// <param name="entry2">
        /// The second entry to compare values from; read-only.
        /// </param>
        /// <returns>
        /// A negative integer, zero, or a positive integer as the first
        /// entry denotes a value that is is less than, equal to, or greater
        /// than the value denoted by the second entry .
        /// </returns>
        /// <exception cref="InvalidCastException">
        /// If the arguments' types prevent them from being compared by this
        /// <b>IComparer</b>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// If the extractor cannot handle the passed objects for any other
        /// reason; an implementor should include a descriptive message.
        /// </exception>
        /// <since>Coherence 3.2</since>
        public virtual int CompareEntries(IQueryCacheEntry entry1, IQueryCacheEntry entry2)
        {
            IComparer comparer = Comparer;

            return(comparer is IQueryCacheComparer ?
                   ((IQueryCacheComparer)comparer).CompareEntries(entry1, entry2)
                   : CompareSafe(comparer, entry1.Value, entry2.Value));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Compare two entries based on the rules specified by
        /// <b>IComparer</b>.
        /// </summary>
        /// <remarks>
        /// <p>
        /// If possible, use the <see cref="IQueryCacheEntry.Extract"/>
        /// method to optimize the value extraction process.</p>
        /// <p>
        /// This method is expected to be implemented by <b>IComparer</b>
        /// wrappers, which simply pass on this invocation to the wrapped
        /// <b>IComparer</b> objects if they too implement this interface, or
        /// to invoke their default compare method passing the actual objects
        /// (not the extracted values) obtained from the extractor using the
        /// passed entries.</p>
        /// <p>
        /// This interface is also expected to be implemented by
        /// <see cref="IValueExtractor"/> implementations that implement the
        /// <b>IComparer</b> interface. It is expected that in most cases,
        /// the <b>IComparer</b> wrappers will eventually terminate at (i.e.
        /// delegate to) <b>IValueExtractors</b> that also implement this
        /// interface.</p>
        /// </remarks>
        /// <param name="entry1">
        /// The first entry to compare values from; read-only.
        /// </param>
        /// <param name="entry2">
        /// The second entry to compare values from; read-only.
        /// </param>
        /// <returns>
        /// A negative integer, zero, or a positive integer as the first
        /// entry denotes a value that is is less than, equal to, or greater
        /// than the value denoted by the second entry.
        /// </returns>
        /// <exception cref="InvalidCastException">
        /// If the arguments' types prevent them from being compared by this
        /// <b>IComparer</b>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// If the extractor cannot handle the passed objects for any other
        /// reason; an implementor should include a descriptive message.
        /// </exception>
        /// <since>Coherence 3.2</since>
        public override int CompareEntries(IQueryCacheEntry entry1, IQueryCacheEntry entry2)
        {
            IValueExtractor[] extractors = Extractors;

            for (int i = 0, c = extractors.Length; i < c; i++)
            {
                IValueExtractor extractor = extractors[i];

                int result = SafeComparer.CompareSafe(null, entry1.Extract(extractor), entry2.Extract(extractor));
                if (result != 0)
                {
                    return(result);
                }
            }
            return(0);
        }
        /// <summary>
        /// Compare two entries based on the rules specified by
        /// <b>IComparer</b>.
        /// </summary>
        /// <remarks>
        /// This implementation simply passes on this invocation to the
        /// wrapped <b>IComparer</b> objects if they too implement this
        /// interface, or invokes their default Compare method passing the
        /// values extracted from the passed entries.
        /// </remarks>
        /// <param name="entry1">
        /// The first entry to compare values from; read-only.
        /// </param>
        /// <param name="entry2">
        /// The second entry to compare values from; read-only.
        /// </param>
        /// <returns>
        /// A negative integer, zero, or a positive integer as the first
        /// entry denotes a value that is is less than, equal to, or greater
        /// than the value denoted by the second entry.
        /// </returns>
        public virtual int CompareEntries(IQueryCacheEntry entry1, IQueryCacheEntry entry2)
        {
            IComparer[] comparers = Comparers;
            for (int i = 0, c = comparers.Length; i < c; i++)
            {
                IComparer comparer = comparers[i];
                int       result   = comparer is IQueryCacheComparer
                                         ? ((IQueryCacheComparer)comparer).CompareEntries(entry1, entry2)
                                         : Compare(entry1.Value, entry2.Value);

                if (result != 0)
                {
                    return(result);
                }
            }
            return(0);
        }
 /// <summary>
 /// Compare two entries.
 /// </summary>
 /// <param name="entry1">
 /// The first entry to compare values from; read-only.
 /// </param>
 /// <param name="entry2">
 /// The second entry to compare values from; read-only.
 /// </param>
 /// <returns>
 /// A negative integer, zero, or a positive integer as the first
 /// entry denotes a value that is is less than, equal to, or greater
 /// than the value denoted by the second entry
 /// </returns>
 /// <exception cref="InvalidCastException">
 /// If the arguments' types prevent them from being compared by this
 /// <b>IComparer</b>.
 /// </exception>
 /// <exception cref="ArgumentException">
 /// If the extractor cannot handle the passed objects for any other
 /// reason; an implementor should include a descriptive message.
 /// </exception>
 public virtual int CompareEntries(IQueryCacheEntry entry1, IQueryCacheEntry entry2)
 {
     return(SafeComparer.CompareSafe(null, entry1.Extract(this), entry2.Extract(this)));
 }
 /// <summary>
 /// Compare two entries using the underlying comparator and negate
 /// the result.
 /// </summary>
 /// <param name="entry1">
 /// The first entry to compare values from; read-only.
 /// </param>
 /// <param name="entry2">
 /// The second entry to compare values from; read-only.
 /// </param>
 /// <returns>
 /// A positive integer, zero, or a negative integer as the first
 /// entry denotes a value that is is less than, equal to, or greater
 /// than the value denoted by the second entry .
 /// </returns>
 public override int CompareEntries(IQueryCacheEntry entry1, IQueryCacheEntry entry2)
 {
     return(-base.CompareEntries(entry1, entry2));
 }