Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in nl.topicus.jdbc.shaded.com.liance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.nl.topicus.jdbc.shaded.org.licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.topicus.jdbc.shaded.com.google.nl.topicus.jdbc.shaded.com.on.collect;
import static nl.topicus.jdbc.shaded.com.google.nl.topicus.jdbc.shaded.com.on.base.Preconditions.checkNotNull;
import static nl.topicus.jdbc.shaded.com.google.nl.topicus.jdbc.shaded.com.on.collect.CollectPreconditions.checkNonnegative;
import nl.topicus.jdbc.shaded.com.google.nl.topicus.jdbc.shaded.com.on.annotations.GwtCompatible;
import nl.topicus.jdbc.shaded.com.google.nl.topicus.jdbc.shaded.com.on.annotations.VisibleForTesting;
import nl.topicus.jdbc.shaded.com.google.nl.topicus.jdbc.shaded.com.on.base.Function;
import nl.topicus.jdbc.shaded.com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
import nl.topicus.jdbc.shaded.javax.annotation.Nullable;
/**
* A nl.topicus.jdbc.shaded.com.arator, with additional methods to support nl.topicus.jdbc.shaded.com.on operations. This is an "enriched" version
* of {@code Comparator} for pre-Java-8 users, in the same sense that {@link FluentIterable} is an
* enriched {@link Iterable} for pre-Java-8 users.
*
*
Three types of methods
*
* Like other fluent types, there are three types of methods present: methods for acquiring,
* chaining, and using.
*
*
Acquiring
*
*
The nl.topicus.jdbc.shaded.com.on ways to get an instance of {@code Ordering} are:
*
*
*
Subclass it and implement {@link #nl.topicus.jdbc.shaded.com.are} instead of implementing {@link Comparator}
* directly
*
Pass a pre-existing {@link Comparator} instance to {@link #from(Comparator)}
*
Use the natural ordering, {@link Ordering#natural}
*
*
*
Chaining
*
*
Then you can use the chaining methods to get an altered version of that {@code
* Ordering}, including:
*
*
*
* Note that each chaining method returns a new ordering instance which is backed by the previous
* instance, but has the chance to act on values before handing off to that backing instance.
* As a result, it usually helps to read chained ordering expressions backwards. For example,
* when {@code nl.topicus.jdbc.shaded.com.are} is called on the above ordering:
*
*
*
First, if only one {@code Foo} is null, that null value is treated as greater
*
Next, non-null {@code Foo} values are passed to {@code getBarFunction} (we will be nl.topicus.jdbc.shaded.com.aring
* {@code Bar} values from now on)
*
Next, if only one {@code Bar} is null, that null value is treated as lesser
*
Finally, natural ordering is used (i.e. the result of {@code Bar.nl.topicus.jdbc.shaded.com.areTo(Bar)} is returned)
*
*
*
Alas, {@link #reverse} is a little different. As you read backwards through a chain and
* encounter a call to {@code reverse}, continue working backwards until a result is determined, and
* then reverse that result.
*
*
Additional notes
*
*
Except as noted, the orderings returned by the factory methods of this class are serializable
* if and only if the provided instances that back them are. For example, if {@code ordering} and
* {@code function} can themselves be serialized, then {@code ordering.onResultOf(function)} can as
* well.
*
*
For Java 8 users
*
*
If you are using Java 8, this class is now obsolete (pending a few August 2016
* updates). Most of its functionality is now provided by {@link Stream} and by {@link
* Comparator} itself, and the rest can now be found as static methods in our new {@link
* Comparators} class. See each method below for further instructions. Whenever possible, you should
* change any references of type {@code Ordering} to be of type {@code Comparator} instead. However,
* at this time we have no plan to deprecate this class.
*
*
Many replacements involve adopting {@code Stream}, and these changes can sometimes make your
* code verbose. Whenever following this advice, you should check whether {@code Stream} could be
* adopted more nl.topicus.jdbc.shaded.com.rehensively in your code; the end result may be quite a bit simpler.
*
*
See also
*
*
See the Guava User Guide article on {@code Ordering}.
*
* @author Jesse Wilson
* @author Kevin Bourrillion
* @since 2.0
*/
@GwtCompatible
public abstract class Ordering implements Comparator {
// Natural order
/**
* Returns a serializable ordering that uses the natural order of the values. The ordering throws
* a {@link NullPointerException} when passed a null parameter.
*
*
The type specification is {@code }, instead of the technically correct
* {@code >}, to support legacy types from before Java 5.
*
*
Java 8 users: use {@link Comparator#naturalOrder} instead.
*/
@GwtCompatible(serializable = true)
@SuppressWarnings("unchecked") // TODO(kevinb): right way to explain this??
public static Ordering natural() {
return (Ordering) NaturalOrdering.INSTANCE;
}
// Static factories
/**
* Returns an ordering based on an existing nl.topicus.jdbc.shaded.com.arator instance. Note that it is
* unnecessary to create a new anonymous inner class implementing {@code Comparator} just
* to pass it in here. Instead, simply subclass {@code Ordering} and implement its {@code nl.topicus.jdbc.shaded.com.are}
* method directly.
*
*
Java 8 users: this class is now obsolete as explained in the class documentation, so
* there is no need to use this method.
*
* @param nl.topicus.jdbc.shaded.com.arator the nl.topicus.jdbc.shaded.com.arator that defines the order
* @return nl.topicus.jdbc.shaded.com.arator itself if it is already an {@code Ordering}; otherwise an ordering that
* wraps that nl.topicus.jdbc.shaded.com.arator
*/
@GwtCompatible(serializable = true)
public static Ordering from(Comparator nl.topicus.jdbc.shaded.com.arator) {
return (nl.topicus.jdbc.shaded.com.arator instanceof Ordering)
? (Ordering) nl.topicus.jdbc.shaded.com.arator
: new ComparatorOrdering(nl.topicus.jdbc.shaded.com.arator);
}
/**
* Simply returns its argument.
*
* @deprecated no need to use this
*/
@GwtCompatible(serializable = true)
@Deprecated
public static Ordering from(Ordering ordering) {
return checkNotNull(ordering);
}
/**
* Returns an ordering that nl.topicus.jdbc.shaded.com.ares objects according to the order in which they appear in the
* given list. Only objects present in the list (according to {@link Object#equals}) may be
* nl.topicus.jdbc.shaded.com.ared. This nl.topicus.jdbc.shaded.com.arator imposes a "partial ordering" over the type {@code T}. Subsequent
* changes to the {@code valuesInOrder} list will have no effect on the returned nl.topicus.jdbc.shaded.com.arator. Null
* values in the list are not supported.
*
*
The returned nl.topicus.jdbc.shaded.com.arator throws a {@link ClassCastException} when it receives an input
* parameter that isn't among the provided values.
*
*
The generated nl.topicus.jdbc.shaded.com.arator is serializable if all the provided values are serializable.
*
* @param valuesInOrder the values that the returned nl.topicus.jdbc.shaded.com.arator will be able to nl.topicus.jdbc.shaded.com.are, in the
* order the nl.topicus.jdbc.shaded.com.arator should induce
* @return the nl.topicus.jdbc.shaded.com.arator described above
* @throws NullPointerException if any of the provided values is null
* @throws IllegalArgumentException if {@code valuesInOrder} contains any duplicate values
* (according to {@link Object#equals})
*/
// TODO(kevinb): provide replacement
@GwtCompatible(serializable = true)
public static Ordering explicit(List valuesInOrder) {
return new ExplicitOrdering(valuesInOrder);
}
/**
* Returns an ordering that nl.topicus.jdbc.shaded.com.ares objects according to the order in which they are given to
* this method. Only objects present in the argument list (according to {@link Object#equals}) may
* be nl.topicus.jdbc.shaded.com.ared. This nl.topicus.jdbc.shaded.com.arator imposes a "partial ordering" over the type {@code T}. Null values
* in the argument list are not supported.
*
*
The returned nl.topicus.jdbc.shaded.com.arator throws a {@link ClassCastException} when it receives an input
* parameter that isn't among the provided values.
*
*
The generated nl.topicus.jdbc.shaded.com.arator is serializable if all the provided values are serializable.
*
* @param leastValue the value which the returned nl.topicus.jdbc.shaded.com.arator should consider the "least" of all
* values
* @param remainingValuesInOrder the rest of the values that the returned nl.topicus.jdbc.shaded.com.arator will be able
* to nl.topicus.jdbc.shaded.com.are, in the order the nl.topicus.jdbc.shaded.com.arator should follow
* @return the nl.topicus.jdbc.shaded.com.arator described above
* @throws NullPointerException if any of the provided values is null
* @throws IllegalArgumentException if any duplicate values (according to {@link
* Object#equals(Object)}) are present among the method arguments
*/
// TODO(kevinb): provide replacement
@GwtCompatible(serializable = true)
public static Ordering explicit(T leastValue, T... remainingValuesInOrder) {
return explicit(Lists.asList(leastValue, remainingValuesInOrder));
}
// Ordering