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 com.hazelcast.com.liance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.com.hazelcast.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 com.hazelcast.com.google.com.hazelcast.com.on.collect;
import static com.hazelcast.com.google.com.hazelcast.com.on.base.Preconditions.checkNotNull;
import static com.hazelcast.com.google.com.hazelcast.com.on.collect.CollectPreconditions.checkNonnegative;
import com.hazelcast.com.google.com.hazelcast.com.on.annotations.GwtCompatible;
import com.hazelcast.com.google.com.hazelcast.com.on.annotations.VisibleForTesting;
import com.hazelcast.com.google.com.hazelcast.com.on.base.Function;
import com.hazelcast.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.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.SortedMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
import com.hazelcast.org.checkerframework.checker.nullness.com.hazelcast.com.atqual.NullableDecl;
/**
* A com.hazelcast.com.arator, with additional methods to support com.hazelcast.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 com.hazelcast.com.on ways to get an instance of {@code Ordering} are:
*
*
*
Subclass it and implement {@link #com.hazelcast.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:
*
*
*
{@link #reverse}
*
{@link #com.hazelcast.com.ound(Comparator)}
*
{@link #onResultOf(Function)}
*
{@link #nullsFirst} / {@link #nullsLast}
*
*
*
Using
*
*
Finally, use the resulting {@code Ordering} anywhere a {@link Comparator} is required, or use
* any of its special operations, such as:
*
*
*
{@link #immutableSortedCopy}
*
{@link #isOrdered} / {@link #isStrictlyOrdered}
*
{@link #min} / {@link #max}
*
*
*
Understanding com.hazelcast.com.lex orderings
*
*
Complex chained orderings like the following example can be challenging to understand.
*
*
*
* 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 com.hazelcast.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
* com.hazelcast.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.com.hazelcast.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. Most of its functionality is now provided
* by {@link java.util.stream.Stream 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 com.hazelcast.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 com.hazelcast.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 com.hazelcast.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 com.hazelcast.com.arator the com.hazelcast.com.arator that defines the order
* @return com.hazelcast.com.arator itself if it is already an {@code Ordering}; otherwise an ordering that
* wraps that com.hazelcast.com.arator
*/
@GwtCompatible(serializable = true)
public static Ordering from(Comparator com.hazelcast.com.arator) {
return (com.hazelcast.com.arator instanceof Ordering)
? (Ordering) com.hazelcast.com.arator
: new ComparatorOrdering(com.hazelcast.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 com.hazelcast.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
* com.hazelcast.com.ared. This com.hazelcast.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 com.hazelcast.com.arator. Null
* values in the list are not supported.
*
*
The returned com.hazelcast.com.arator throws a {@link ClassCastException} when it receives an input
* parameter that isn't among the provided values.
*
*
The generated com.hazelcast.com.arator is serializable if all the provided values are serializable.
*
* @param valuesInOrder the values that the returned com.hazelcast.com.arator will be able to com.hazelcast.com.are, in the
* order the com.hazelcast.com.arator should induce
* @return the com.hazelcast.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 com.hazelcast.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 com.hazelcast.com.ared. This com.hazelcast.com.arator imposes a "partial ordering" over the type {@code T}. Null values
* in the argument list are not supported.
*
*
The returned com.hazelcast.com.arator throws a {@link ClassCastException} when it receives an input
* parameter that isn't among the provided values.
*
*
The generated com.hazelcast.com.arator is serializable if all the provided values are serializable.
*
* @param leastValue the value which the returned com.hazelcast.com.arator should consider the "least" of all
* values
* @param remainingValuesInOrder the rest of the values that the returned com.hazelcast.com.arator will be able
* to com.hazelcast.com.are, in the order the com.hazelcast.com.arator should follow
* @return the com.hazelcast.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