当前位置: 首页>>代码示例>>Java>>正文


Java SortedSet.comparator方法代码示例

本文整理汇总了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;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:26,代码来源:Range.java

示例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;
}
 
开发者ID:microbean,项目名称:microbean-helm,代码行数:42,代码来源:ChartRepository.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:EmptyNavigableSet.java

示例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;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:10,代码来源:SortedIterables.java

示例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);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:16,代码来源:DerivedCollectionGenerators.java

示例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;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:ImmutableSortedSet.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:SpliteratorCharacteristics.java

示例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();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:50,代码来源:PriorityBlockingQueue.java

示例9: DynamicSortedSet

import java.util.SortedSet; //导入方法依赖的package包/类
public DynamicSortedSet(SortedSet<E> ss) {
	this.comparator = ss.comparator();
	addAll(ss);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:5,代码来源:DynamicSortedSet.java

示例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();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:PersistentSortedSet.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:ConcurrentSkipListSet.java


注:本文中的java.util.SortedSet.comparator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。