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) 2009 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.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.facebook.presto.jdbc.internal.guava.collect;
import com.facebook.presto.jdbc.internal.guava.annotations.GwtCompatible;
import com.facebook.presto.jdbc.internal.guava.primitives.Booleans;
import com.facebook.presto.jdbc.internal.guava.primitives.Ints;
import com.facebook.presto.jdbc.internal.guava.primitives.Longs;
import java.util.Comparator;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* A utility for performing a chained comparison statement. Note: Java 8+ users should
* generally prefer the methods in {@link Comparator}; see below.
*
*
The value of this expression will have the same sign as the first nonzero comparison
* result in the chain, or will be zero if every comparison result was zero.
*
*
Note: {@code ComparisonChain} instances are immutable. For this utility to work
* correctly, calls must be chained as illustrated above.
*
*
Performance note: Even though the {@code ComparisonChain} caller always invokes its {@code
* compare} methods unconditionally, the {@code ComparisonChain} implementation stops calling its
* inputs' {@link Comparable#compareTo compareTo} and {@link Comparator#compare compare} methods as
* soon as one of them returns a nonzero result. This optimization is typically important only in
* the presence of expensive {@code compareTo} and {@code compare} implementations.
*
*
*
* If you are using Java version 8 or greater, you should generally use the static methods in {@link
* Comparator} instead of {@code ComparisonChain}. The example above can be implemented like this:
*
*
With method references it is more succinct: {@code comparing(Foo::aString)} for example.
*
*
Using {@link Comparator} avoids certain types of bugs, for example when you meant to write
* {@code .compare(a.foo, b.foo)} but you actually wrote {@code .compare(a.foo, a.foo)} or {@code
* .compare(a.foo, b.bar)}. {@code ComparisonChain} also has a potential performance problem that
* {@code Comparator} doesn't: it evaluates all the parameters of all the {@code .compare} calls,
* even when the result of the comparison is already known from previous {@code .compare} calls.
* That can be expensive.
*
* @author Mark Davis
* @author Kevin Bourrillion
* @since 2.0
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class ComparisonChain {
private ComparisonChain() {}
/** Begins a new chained comparison statement. See example in the class documentation. */
public static ComparisonChain start() {
return ACTIVE;
}
private static final ComparisonChain ACTIVE =
new ComparisonChain() {
@SuppressWarnings("unchecked") // unsafe; see discussion on supertype
@Override
public ComparisonChain compare(Comparable> left, Comparable> right) {
return classify(((Comparable