Пример #1
0
        private int partition(int left, int right, java.util.Comparator <fastmath.Vector>
                              cmp)
        {
            int i = left - 1;
            int j = right;

            while (true)
            {
                // find item on left to swap
                while (cmp.compare(row(++i), row(right)) > 0)
                {
                }
                // find item on right to swap
                while (cmp.compare(row(right), row(--j)) > 0)
                {
                    if (j == left)
                    {
                        break;
                    }
                }
                // check if pointers cross
                if (i >= j)
                {
                    break;
                }
                exch(i, j);
            }
            // swap with partition element
            if (i != right)
            {
                exch(i, right);
            }
            return(i);
        }
Пример #2
0
 /**
  * Gets a Comparator that passes transformed objects to the given comparator.
  * <p>
  * Objects passed to the returned comparator will first be transformed
  * by the given transformer before they are compared by the given
  * comparator.
  *
  * @param comparator  the sort order to use
  * @param transformer  the transformer to use
  * @return  a comparator that transforms its input objects before comparing them
  * @see  TransformingComparator
  */
 public static java.util.Comparator <Object> transformedComparator(java.util.Comparator <Object> comparator, Transformer transformer)
 {
     if (comparator == null)
     {
         comparator = NATURAL_COMPARATOR;
     }
     return(new TransformingComparator(transformer, comparator));
 }
Пример #3
0
 /**
  * Gets a Comparator that controls the comparison of <code>null</code> values.
  * <p>
  * The returned comparator will consider a null value to be greater than
  * any nonnull value, and equal to any other null value.  Two nonnull
  * values will be evaluated with the given comparator.
  *
  * @param comparator the comparator that wants to allow nulls
  * @return  a version of that comparator that allows nulls
  * @see NullComparator
  */
 public static java.util.Comparator <Object> nullHighComparator(java.util.Comparator <Object> comparator)
 {
     if (comparator == null)
     {
         comparator = NATURAL_COMPARATOR;
     }
     return(new NullComparator(comparator, true));
 }
Пример #4
0
 /**
  * Gets a comparator that reverses the order of the given comparator.
  *
  * @param comparator  the comparator to reverse
  * @return  a comparator that reverses the order of the input comparator
  * @see ReverseComparator
  */
 public static java.util.Comparator <Object> reversedComparator(java.util.Comparator <Object> comparator)
 {
     if (comparator == null)
     {
         comparator = NATURAL_COMPARATOR;
     }
     return(new ReverseComparator(comparator));
 }
 /**
  * Constructs a new <code>CollatingIterator</code> that will use the
  * specified comparator to provide ordered iteration over the array
  * of iterators.
  *
  * @param comp  the comparator to use to sort, or null to use natural sort order
  * @param iterators  the array of iterators
  * @throws NullPointerException if iterators array is or contains null
  */
 public CollatingIterator(java.util.Comparator <Object> comp, java.util.Iterator <Object>[] iterators)
     : this(comp, iterators.Length)
 {
     for (int i = 0; i < iterators.Length; i++)
     {
         addIterator(iterators[i]);
     }
 }
 /**
  * Constructs a new <code>CollatingIterator</code> that will use the
  * specified comparator to provide ordered iteration over the collection
  * of iterators.
  *
  * @param comp  the comparator to use to sort, or null to use natural sort order
  * @param iterators  the collection of iterators
  * @throws NullPointerException if the iterators collection is or contains null
  * @throws ClassCastException if the iterators collection contains an
  *         element that's not an {@link Iterator}
  */
 public CollatingIterator(java.util.Comparator <Object> comp, java.util.Collection <Object> iterators) :
     this(comp, iterators.size())
 {
     for (java.util.Iterator <Object> it = iterators.iterator(); it.hasNext();)
     {
         java.util.Iterator <Object> item = (java.util.Iterator <Object>)it.next();
         addIterator(item);
     }
 }
Пример #7
0
 public VPackCache(VPackFieldNamingStrategy fieldNamingStrategy
                   )
     : base()
 {
     this.cache = new java.util.concurrent.ConcurrentHashMap <global::System.Type, System.Collections.Generic.IDictionary
                                                              <string, FieldInfo> >();
     this.fieldComparator     = new _Comparator_91();
     this.fieldNamingStrategy = fieldNamingStrategy;
 }
Пример #8
0
        /**
         *  Returns the larger of the given objects according to the given
         *  comparator, returning the second object if the comparator
         *  returns equal.
         *
         *  @param o1  the first object to compare
         *  @param o2  the second object to compare
         *  @param comparator  the sort order to use
         *  @return  the larger of the two objects
         */
        public static Object max(Object o1, Object o2, java.util.Comparator <Object> comparator)
        {
            if (comparator == null)
            {
                comparator = NATURAL_COMPARATOR;
            }
            int c = comparator.compare(o1, o2);

            return((c > 0) ? o1 : o2);
        }
Пример #9
0
 /**
  * Construct a Comparator chain with a single Comparator,
  * sorting in the given order
  *
  * @param comparator First Comparator in the ComparatorChain
  * @param reverse    false = forward sort; true = reverse sort
  */
 public ComparatorChain(java.util.Comparator <Object> comparator, bool reverse)
 {
     comparatorChain = new java.util.ArrayList <Object>();
     comparatorChain.add(comparator);
     orderingBits = new java.util.BitSet(1);
     if (reverse == true)
     {
         orderingBits.set(0);
     }
 }
        /**
         *  Construct an instance that sorts <code>null</code> higher or lower than
         *  any non-<code>null</code> object it is compared with.  When comparing
         *  two non-<code>null</code> objects, the specified {@link Comparator} is
         *  used.
         *
         *  @param nonNullComparator the comparator to use when comparing two
         *  non-<code>null</code> objects. This argument cannot be
         *  <code>null</code>
         *
         *  @param nullsAreHigh a <code>true</code> value indicates that
         *  <code>null</code> should be compared as higher than a
         *  non-<code>null</code> object.  A <code>false</code> value indicates
         *  that <code>null</code> should be compared as lower than a
         *  non-<code>null</code> object.
         *
         *  @exception NullPointerException if <code>nonNullComparator</code> is
         *  <code>null</code>
         **/
        public NullComparator(java.util.Comparator <Object> nonNullComparator, bool nullsAreHigh)
        {
            this.nonNullComparator = nonNullComparator;
            this.nullsAreHigh      = nullsAreHigh;

            if (nonNullComparator == null)
            {
                throw new java.lang.NullPointerException("null nonNullComparator");
            }
        }
Пример #11
0
        /**
         * Add a Comparator to the end of the chain using the
         * given sort order
         *
         * @param comparator Comparator to add to the end of the chain
         * @param reverse    false = forward sort order; true = reverse sort order
         */
        public void addComparator(java.util.Comparator <Object> comparator, bool reverse)
        {
            checkLocked();

            comparatorChain.add(comparator);
            if (reverse == true)
            {
                orderingBits.set(comparatorChain.size() - 1);
            }
        }
Пример #12
0
 /**
  * Creates a comparator that inverts the comparison
  * of the given comparator.  If you pass in <code>null</code>,
  * the ReverseComparator defaults to reversing the
  * natural order, as per
  * {@link java.util.Collections#reverseOrder()}</b>.
  *
  * @param comparator Comparator to reverse
  */
 public ReverseComparator(java.util.Comparator <Object> comparator)
 {
     if (comparator != null)
     {
         this.comparator = comparator;
     }
     else
     {
         this.comparator = ComparableComparator.getInstance();
     }
 }
Пример #13
0
 public virtual void sort(java.util.Comparator <fastmath.Vector> cmp)
 {
     try
     {
         sort(0, numRows - 1, cmp);
     }
     catch (fastmath.exceptions.FastMathException e)
     {
         throw new System.Exception(e.Message, e);
     }
 }
Пример #14
0
 public virtual void sort(java.util.Comparator arg0)
 {
     global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
     if (!IsClrObject)
     {
         @__env.CallVoidMethod(this.JvmHandle, global::android.widget.ArrayAdapter._sort10922, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0));
     }
     else
     {
         @__env.CallNonVirtualVoidMethod(this.JvmHandle, global::android.widget.ArrayAdapter.staticClass, global::android.widget.ArrayAdapter._sort10922, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0));
     }
 }
Пример #15
0
        /// <exception cref="fastmath.exceptions.FastMathException"/>
        protected internal virtual void sort(int left, int right, java.util.Comparator <fastmath.Vector
                                                                                        > cmp)
        {
            if (right <= left)
            {
                return;
            }
            int i = partition(left, right, cmp);

            sort(left, i - 1, cmp);
            sort(i + 1, right, cmp);
        }
Пример #16
0
        /**
         * Constructs a new empty buffer that specifying initial capacity,
         * sort order and comparator.
         *
         * @param capacity  the initial capacity for the buffer, greater than zero
         * @param ascendingOrder  true to use the order imposed by the given
         *   comparator; false to reverse that order
         * @param comparator  the comparator used to order the elements,
         *  null means use natural order
         * @throws IllegalArgumentException if <code>capacity</code> is <code>&lt;= 0</code>
         */
        public PriorityBuffer(int capacity, bool ascendingOrder, java.util.Comparator <Object> comparator)
            : base()
        {
            if (capacity <= 0)
            {
                throw new java.lang.IllegalArgumentException("invalid capacity");
            }
            this.ascendingOrder = ascendingOrder;

            //+1 as 0 is noop
            this.elements    = new Object[capacity + 1];
            this.comparatorJ = comparator;
        }
Пример #17
0
        /**
         * Replace the Comparator at the given index in the
         * ComparatorChain, using the given sort order
         *
         * @param index      index of the Comparator to replace
         * @param comparator Comparator to set
         * @param reverse    false = forward sort order; true = reverse sort order
         */
        public void setComparator(int index, java.util.Comparator <Object> comparator, bool reverse)
        {
            checkLocked();

            comparatorChain.set(index, comparator);
            if (reverse == true)
            {
                orderingBits.set(index);
            }
            else
            {
                orderingBits.clear(index);
            }
        }
Пример #18
0
 /// <summary>Sorts the content of this adapter using the specified comparator.</summary>
 /// <remarks>Sorts the content of this adapter using the specified comparator.</remarks>
 /// <param name="comparator">
 /// The comparator used to sort the objects contained
 /// in this adapter.
 /// </param>
 public virtual void sort(java.util.Comparator <T> comparator)
 {
     lock (mLock)
     {
         if (mOriginalValues != null)
         {
             java.util.Collections.sort(mOriginalValues, comparator);
         }
         else
         {
             java.util.Collections.sort(mObjects, comparator);
         }
     }
     if (mNotifyOnChange)
     {
         notifyDataSetChanged();
     }
 }
Пример #19
0
        //-----------------------------------------------------------------------

        /**
         * Perform comparisons on the Objects as per
         * Comparator.compare(o1,o2).
         *
         * @param o1  the first object to compare
         * @param o2  the second object to compare
         * @return -1, 0, or 1
         * @exception UnsupportedOperationException
         *                   if the ComparatorChain does not contain at least one
         *                   Comparator
         */
        public int compare(Object o1, Object o2)
        {//throws UnsupportedOperationException {
            if (isLockedJ == false)
            {
                checkChainIntegrity();
                isLockedJ = true;
            }

            // iterate over all comparators in the chain
            java.util.Iterator <Object> comparators = comparatorChain.iterator();
            for (int comparatorIndex = 0; comparators.hasNext(); ++comparatorIndex)
            {
                java.util.Comparator <Object> comparator = (java.util.Comparator <Object>)comparators.next();
                int retval = comparator.compare(o1, o2);
                if (retval != 0)
                {
                    // invert the order if it is a reverse sort
                    if (orderingBits.get(comparatorIndex) == true)
                    {
                        if (java.lang.Integer.MIN_VALUE == retval)
                        {
                            retval = java.lang.Integer.MAX_VALUE;
                        }
                        else
                        {
                            retval *= -1;
                        }
                    }

                    return(retval);
                }
            }

            // if comparators are exhausted, return 0
            return(0);
        }
 /**
  * Read the bag in using a custom routine.
  */
 private void readObject(java.io.ObjectInputStream inJ)
 {//throws IOException, ClassNotFoundException {
     inJ.defaultReadObject();
     java.util.Comparator <Object> comp = (java.util.Comparator <Object>)inJ.readObject();
     base.doReadObject(new java.util.TreeMap <Object, Object>(comp), inJ);
 }
 /**
  *  Construct an instance that sorts <code>null</code> higher than any
  *  non-<code>null</code> object it is compared with.  When comparing two
  *  non-<code>null</code> objects, the specified {@link Comparator} is
  *  used.
  *
  *  @param nonNullComparator the comparator to use when comparing two
  *  non-<code>null</code> objects.  This argument cannot be
  *  <code>null</code>
  *
  *  @exception NullPointerException if <code>nonNullComparator</code> is
  *  <code>null</code>
  **/
 public NullComparator(java.util.Comparator <Object> nonNullComparator)
     : this(nonNullComparator, true)
 {
 }
 /**
  * Constructs a <code>DualTreeBidiMap</code> that decorates the specified maps.
  *
  * @param normalMap  the normal direction map
  * @param reverseMap  the reverse direction map
  * @param inverseBidiMap  the inverse BidiMap
  */
 protected DualTreeBidiMap(java.util.Map <Object, Object> normalMap, java.util.Map <Object, Object> reverseMap, BidiMap inverseBidiMap) :
     base(normalMap, reverseMap, inverseBidiMap)
 {
     this.comparatorJ = ((java.util.SortedMap <Object, Object>)normalMap).comparator();
 }
 /**
  * Constructs a <code>DualTreeBidiMap</code> using the specified Comparator.
  *
  * @param comparator  the Comparator
  */
 public DualTreeBidiMap(java.util.Comparator <Object> comparator) :
     base(new java.util.TreeMap <Object, Object>(comparator), new java.util.TreeMap <Object, Object>(comparator))
 {
     this.comparatorJ = comparator;
 }
 /**
  * Constructs a <code>DualTreeBidiMap</code> and copies the mappings from
  * specified <code>Map</code>.
  *
  * @param map  the map whose mappings are to be placed in this map
  */
 public DualTreeBidiMap(java.util.Map <Object, Object> map) :
     base(new java.util.TreeMap <Object, Object>(), new java.util.TreeMap <Object, Object>())
 {
     putAll(map);
     this.comparatorJ = null;
 }
 /**
  * Creates an empty <code>DualTreeBidiMap</code>
  */
 public DualTreeBidiMap() :
     base(new java.util.TreeMap <Object, Object>(), new java.util.TreeMap <Object, Object>())
 {
     this.comparatorJ = null;
 }
 /**
  * Constructs an empty bag that maintains order on its unique
  * representative members according to the given {@link Comparator}.
  *
  * @param comparator  the comparator to use
  */
 public TreeBag(java.util.Comparator <Object> comparator)
     : base(new java.util.TreeMap <Object, Object>(comparator))
 {
 }
 /**
  * Creates an empty <code>DualTreeBidiMap</code>
  */
 public DualTreeBidiMap()
     : base(new java.util.TreeMap<Object, Object>(), new java.util.TreeMap<Object, Object>())
 {
     this.comparatorJ = null;
 }
 /**
  * Constructs a <code>DualTreeBidiMap</code> using the specified Comparator.
  *
  * @param comparator  the Comparator
  */
 public DualTreeBidiMap(java.util.Comparator<Object> comparator)
     : base(new java.util.TreeMap<Object, Object>(comparator), new java.util.TreeMap<Object, Object>(comparator))
 {
     this.comparatorJ = comparator;
 }
 /**
  * Constructs a <code>DualTreeBidiMap</code> that decorates the specified maps.
  *
  * @param normalMap  the normal direction map
  * @param reverseMap  the reverse direction map
  * @param inverseBidiMap  the inverse BidiMap
  */
 protected DualTreeBidiMap(java.util.Map<Object, Object> normalMap, java.util.Map<Object, Object> reverseMap, BidiMap inverseBidiMap)
     : base(normalMap, reverseMap, inverseBidiMap)
 {
     this.comparatorJ = ((java.util.SortedMap<Object, Object>)normalMap).comparator();
 }
Пример #30
0
 /**
  * Constructs a new empty buffer that sorts in ascending order using the
  * specified comparator.
  *
  * @param comparator  the comparator used to order the elements,
  *  null means use natural order
  */
 public PriorityBuffer(java.util.Comparator <Object> comparator)
     : this(DEFAULT_CAPACITY, true, comparator)
 {
 }
 /**
  * Constructs a <code>DualTreeBidiMap</code> and copies the mappings from
  * specified <code>Map</code>.
  *
  * @param map  the map whose mappings are to be placed in this map
  */
 public DualTreeBidiMap(java.util.Map<Object, Object> map)
     : base(new java.util.TreeMap<Object, Object>(), new java.util.TreeMap<Object, Object>())
 {
     putAll(map);
     this.comparatorJ = null;
 }
Пример #32
0
 /**
  * Constructs a new empty buffer specifying the sort order and comparator.
  *
  * @param ascendingOrder  true to use the order imposed by the given
  *   comparator; false to reverse that order
  * @param comparator  the comparator used to order the elements,
  *  null means use natural order
  */
 public PriorityBuffer(bool ascendingOrder, java.util.Comparator <Object> comparator)
     : this(DEFAULT_CAPACITY, ascendingOrder, comparator)
 {
 }
 /**
  * Gets an iterator that provides an ordered iteration over the elements
  * contained in a collection of {@link Iterator}s.
  * <p>
  * Given two ordered {@link Iterator}s <code>A</code> and <code>B</code>,
  * the {@link Iterator#next()} method will return the lesser of
  * <code>A.next()</code> and <code>B.next()</code> and so on.
  * <p>
  * The comparator is optional. If null is specified then natural order is used.
  *
  * @param comparator  the comparator to use, may be null for natural order
  * @param iterators  the iterators to use, not null or empty or contain nulls
  * @return a combination iterator over the iterators
  * @throws NullPointerException if iterators collection is null or contains a null
  * @throws ClassCastException if the iterators collection contains the wrong object type
  */
 public static java.util.Iterator <Object> collatedIterator(java.util.Comparator <Object> comparator, java.util.Collection <Object> iterators)
 {
     return(new CollatingIterator(comparator, iterators));
 }
Пример #34
0
 /**
  * Constructs a new empty buffer that sorts in ascending order using the
  * specified comparator and initial capacity.
  *
  * @param capacity  the initial capacity for the buffer, greater than zero
  * @param comparator  the comparator used to order the elements,
  *  null means use natural order
  * @throws IllegalArgumentException if <code>capacity</code> is &lt;= <code>0</code>
  */
 public PriorityBuffer(int capacity, java.util.Comparator <Object> comparator)
     : this(capacity, true, comparator)
 {
 }