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) 2017, Haiyang Li.
*
* 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.landawn.abacus.util;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Map;
import com.landawn.abacus.util.function.Function;
import com.landawn.abacus.util.function.ToBooleanFunction;
import com.landawn.abacus.util.function.ToByteFunction;
import com.landawn.abacus.util.function.ToCharFunction;
import com.landawn.abacus.util.function.ToDoubleFunction;
import com.landawn.abacus.util.function.ToFloatFunction;
import com.landawn.abacus.util.function.ToIntFunction;
import com.landawn.abacus.util.function.ToLongFunction;
import com.landawn.abacus.util.function.ToShortFunction;
/**
*
* Factory utility class for Comparator.
*
* @author haiyangl
*
*/
public abstract class Comparators {
@SuppressWarnings("rawtypes")
static final Comparator NULL_FIRST_COMPARATOR = new Comparator() {
@Override
public int compare(final Comparable a, final Comparable b) {
return a == null ? (b == null ? 0 : -1) : (b == null ? 1 : a.compareTo(b));
}
};
@SuppressWarnings("rawtypes")
static final Comparator NULL_LAST_COMPARATOR = new Comparator() {
@Override
public int compare(final Comparable a, final Comparable b) {
return a == null ? (b == null ? 0 : 1) : (b == null ? -1 : a.compareTo(b));
}
};
@SuppressWarnings("rawtypes")
static final Comparator NATURAL_ORDER = NULL_FIRST_COMPARATOR;
@SuppressWarnings("rawtypes")
static final Comparator REVERSED_ORDER = Collections.reverseOrder(NATURAL_ORDER);
static final Comparator COMPARING_IGNORE_CASE = new Comparator() {
@Override
public int compare(String a, String b) {
return N.compareIgnoreCase(a, b);
}
};
static final Comparator COMPARING_BY_LENGTH = new Comparator() {
@Override
public int compare(CharSequence a, CharSequence b) {
return (a == null ? 0 : a.length()) - (b == null ? 0 : b.length());
}
};
@SuppressWarnings("rawtypes")
static final Comparator COMPARING_BY_SIZE = new Comparator() {
@Override
public int compare(Collection a, Collection b) {
return (a == null ? 0 : a.size()) - (b == null ? 0 : b.size());
}
};
@SuppressWarnings("rawtypes")
static final Comparator