本文整理汇总了Java中java.util.SortedSet.comparator方法的典型用法代码示例。如果您正苦于以下问题:Java SortedSet.comparator方法的具体用法?Java SortedSet.comparator怎么用?Java SortedSet.comparator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.SortedSet
的用法示例。
在下文中一共展示了SortedSet.comparator方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: containsAll
import java.util.SortedSet; //导入方法依赖的package包/类
/**
* Returns {@code true} if every element in {@code values} is {@linkplain #contains contained} in
* this range.
*/
public boolean containsAll(Iterable<? extends C> values) {
if (Iterables.isEmpty(values)) {
return true;
}
// this optimizes testing equality of two range-backed sets
if (values instanceof SortedSet) {
SortedSet<? extends C> set = cast(values);
Comparator<?> comparator = set.comparator();
if (Ordering.natural().equals(comparator) || comparator == null) {
return contains(set.first()) && contains(set.last());
}
}
for (C value : values) {
if (!contains(value)) {
return false;
}
}
return true;
}
示例2: deepCopy
import java.util.SortedSet; //导入方法依赖的package包/类
/**
* Performs a deep copy of the supplied {@link Map} such that the
* {@link SortedMap} returned has copies of the supplied {@link
* Map}'s {@linkplain Map#values() values}.
*
* <p>This method may return {@code null} if {@code source} is
* {@code null}.</p>
*
* <p>The {@link SortedMap} returned by this method is
* mutable.</p>
*
* @param source the {@link Map} to copy; may be {@code null} in
* which case {@code null} will be returned
*
* @return a mutable {@link SortedMap}, or {@code null}
*/
private static final SortedMap<String, SortedSet<Entry>> deepCopy(final Map<? extends String, ? extends SortedSet<Entry>> source) {
final SortedMap<String, SortedSet<Entry>> returnValue;
if (source == null) {
returnValue = null;
} else if (source.isEmpty()) {
returnValue = Collections.emptySortedMap();
} else {
returnValue = new TreeMap<>();
final Collection<? extends Map.Entry<? extends String, ? extends SortedSet<Entry>>> entrySet = source.entrySet();
if (entrySet != null && !entrySet.isEmpty()) {
for (final Map.Entry<? extends String, ? extends SortedSet<Entry>> entry : entrySet) {
final String key = entry.getKey();
final SortedSet<Entry> value = entry.getValue();
if (value == null) {
returnValue.put(key, null);
} else {
final SortedSet<Entry> newValue = new TreeSet<>(value.comparator());
newValue.addAll(value);
returnValue.put(key, newValue);
}
}
}
}
return returnValue;
}
示例3: isDescending
import java.util.SortedSet; //导入方法依赖的package包/类
public static final boolean isDescending(SortedSet<?> set) {
if (null == set.comparator()) {
// natural order
return false;
}
if (Collections.reverseOrder() == set.comparator()) {
// reverse natural order.
return true;
}
if (set.comparator().equals(Collections.reverseOrder(Collections.reverseOrder(set.comparator())))) {
// it's a Collections.reverseOrder(Comparator).
return true;
}
throw new IllegalStateException("can't determine ordering for " + set);
}
示例4: comparator
import java.util.SortedSet; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
// if sortedSet.comparator() is null, the set must be naturally ordered
public static <E> Comparator<? super E> comparator(SortedSet<E> sortedSet) {
Comparator<? super E> result = sortedSet.comparator();
if (result == null) {
result = (Comparator<? super E>) Ordering.natural();
}
return result;
}
示例5: SortedSetSubsetTestSetGenerator
import java.util.SortedSet; //导入方法依赖的package包/类
public SortedSetSubsetTestSetGenerator(
TestSortedSetGenerator<E> delegate, Bound to, Bound from) {
this.to = to;
this.from = from;
this.delegate = delegate;
SortedSet<E> emptySet = delegate.create();
this.comparator = emptySet.comparator();
SampleElements<E> samples = delegate.samples();
List<E> samplesList = new ArrayList<E>(samples.asList());
Collections.sort(samplesList, comparator);
this.firstInclusive = samplesList.get(0);
this.lastInclusive = samplesList.get(samplesList.size() - 1);
}
示例6: hasSameComparator
import java.util.SortedSet; //导入方法依赖的package包/类
private static boolean hasSameComparator(
Iterable<?> elements, Comparator<?> comparator) {
if (elements instanceof SortedSet) {
SortedSet<?> sortedSet = (SortedSet<?>) elements;
Comparator<?> comparator2 = sortedSet.comparator();
return (comparator2 == null)
? comparator == Ordering.natural()
: comparator.equals(comparator2);
}
return false;
}
示例7: assertSortedSetCharacteristics
import java.util.SortedSet; //导入方法依赖的package包/类
void assertSortedSetCharacteristics(SortedSet<Integer> s, int keyCharacteristics) {
assertSetCharacteristics(s, keyCharacteristics);
if (s.comparator() != null) {
assertNotNullComparator(s);
}
else {
assertNullComparator(s);
}
}
示例8: PriorityBlockingQueue
import java.util.SortedSet; //导入方法依赖的package包/类
/**
* Creates a {@code PriorityBlockingQueue} containing the elements
* in the specified collection. If the specified collection is a
* {@link SortedSet} or a {@link PriorityQueue}, this
* priority queue will be ordered according to the same ordering.
* Otherwise, this priority queue will be ordered according to the
* {@linkplain Comparable natural ordering} of its elements.
*
* @param c the collection whose elements are to be placed
* into this priority queue
* @throws ClassCastException if elements of the specified collection
* cannot be compared to one another according to the priority
* queue's ordering
* @throws NullPointerException if the specified collection or any
* of its elements are null
*/
public PriorityBlockingQueue(Collection<? extends E> c) {
this.lock = new ReentrantLock();
this.notEmpty = lock.newCondition();
boolean heapify = true; // true if not known to be in heap order
boolean screen = true; // true if must screen for nulls
if (c instanceof SortedSet<?>) {
SortedSet<? extends E> ss = (SortedSet<? extends E>) c;
this.comparator = (Comparator<? super E>) ss.comparator();
heapify = false;
}
else if (c instanceof PriorityBlockingQueue<?>) {
PriorityBlockingQueue<? extends E> pq =
(PriorityBlockingQueue<? extends E>) c;
this.comparator = (Comparator<? super E>) pq.comparator();
screen = false;
if (pq.getClass() == PriorityBlockingQueue.class) // exact match
heapify = false;
}
Object[] a = c.toArray();
int n = a.length;
// If c.toArray incorrectly doesn't return Object[], copy it.
if (a.getClass() != Object[].class)
a = Arrays.copyOf(a, n, Object[].class);
if (screen && (n == 1 || this.comparator != null)) {
for (int i = 0; i < n; ++i)
if (a[i] == null)
throw new NullPointerException();
}
this.queue = a;
this.size = n;
if (heapify)
heapify();
}
示例9: DynamicSortedSet
import java.util.SortedSet; //导入方法依赖的package包/类
public DynamicSortedSet(SortedSet<E> ss) {
this.comparator = ss.comparator();
addAll(ss);
}
示例10: PersistentSortedSet
import java.util.SortedSet; //导入方法依赖的package包/类
/**
* Constructs a PersistentSortedSet
*
* @param session The session
* @param set The underlying set data
*/
public PersistentSortedSet(SessionImplementor session, SortedSet set) {
super( session, set );
comparator = set.comparator();
}
示例11: ConcurrentSkipListSet
import java.util.SortedSet; //导入方法依赖的package包/类
/**
* Constructs a new set containing the same elements and using the
* same ordering as the specified sorted set.
*
* @param s sorted set whose elements will comprise the new set
* @throws NullPointerException if the specified sorted set or any
* of its elements are null
*/
public ConcurrentSkipListSet(SortedSet<E> s) {
m = new ConcurrentSkipListMap<E,Object>(s.comparator());
addAll(s);
}