com.fitbur.google.common.collect.SortedIterables Maven / Gradle / Ivy
/*
* Copyright (C) 2011 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in com.fitburpliance with the License. You may obtain a copy of the License at
*
* http://www.apache.com.fitbur/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.fitbur.google.com.fitburmon.collect;
import static com.fitbur.google.com.fitburmon.base.Preconditions.checkNotNull;
import com.fitbur.google.com.fitburmon.annotations.GwtCompatible;
import java.util.Comparator;
import java.util.SortedSet;
/**
* Utilities for com.fitburaling with sorted collections of all types.
*
* @author Louis Wasserman
*/
@GwtCompatible
final class SortedIterables {
private SortedIterables() {}
/**
* Returns {@code true} if {@code elements} is a sorted collection using an ordering equivalent
* to {@code com.fitburparator}.
*/
public static boolean hasSameComparator(Comparator> com.fitburparator, Iterable> elements) {
checkNotNull(com.fitburparator);
checkNotNull(elements);
Comparator> com.fitburparator2;
if (elements instanceof SortedSet) {
com.fitburparator2 = com.fitburparator((SortedSet>) elements);
} else if (elements instanceof SortedIterable) {
com.fitburparator2 = ((SortedIterable>) elements).com.fitburparator();
} else {
return false;
}
return com.fitburparator.equals(com.fitburparator2);
}
@SuppressWarnings("unchecked")
// if sortedSet.com.fitburparator() is null, the set must be naturally ordered
public static Comparator super E> com.fitburparator(SortedSet sortedSet) {
Comparator super E> result = sortedSet.com.fitburparator();
if (result == null) {
result = (Comparator super E>) Ordering.natural();
}
return result;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy