本文整理汇总了Java中com.google.common.collect.Ordering.natural方法的典型用法代码示例。如果您正苦于以下问题:Java Ordering.natural方法的具体用法?Java Ordering.natural怎么用?Java Ordering.natural使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.Ordering
的用法示例。
在下文中一共展示了Ordering.natural方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testImmutableSortedSet
import com.google.common.collect.Ordering; //导入方法依赖的package包/类
@Test
public void testImmutableSortedSet() {
ImmutableSortedSet<String> set = newSet();
assertEquals(3, set.size());
assertFalse(set.isEmpty());
assertEquals("bar", set.getMinEntry());
assertEquals("foo", set.getMaxEntry());
assertEquals("bar", set.getPredecessorEntry("baz"));
assertTrue(set.contains("foo"));
assertFalse(set.contains("not found"));
assertEquals(set.hashCode(), set.hashCode());
assertEquals(set, set);
ImmutableSortedSet<String> set2 = newSet();
assertEquals(set.hashCode(), set2.hashCode());
assertEquals(set, set2);
List<String> original = new ArrayList<>();
Collections.addAll(original, "abc", "mno", "pqr");
set2 = new ImmutableSortedSet<>(original, Ordering.<String>natural());
assertNotEquals(set.hashCode(), set2.hashCode());
assertNotEquals(set, set2);
}
示例2: OrderingByPosition
import com.google.common.collect.Ordering; //导入方法依赖的package包/类
private OrderingByPosition (int position, boolean reverse, @Nullable Boolean nullFirst) {
this.position = position;
// note, that we are reverse for the queue so this conditional is by intent
Ordering<Comparable> ordering;
nullFirst = nullFirst != null ? !nullFirst : null; // swap because queue is reverse
if (reverse) {
ordering = Ordering.natural();
if (nullFirst == null || !nullFirst) {
ordering = ordering.nullsLast();
} else {
ordering = ordering.nullsFirst();
}
} else {
ordering = Ordering.natural().reverse();
if (nullFirst == null || nullFirst) {
ordering = ordering.nullsFirst();
} else {
ordering = ordering.nullsLast();
}
}
this.ordering = ordering;
}
示例3: isNaturalComparator
import com.google.common.collect.Ordering; //导入方法依赖的package包/类
private static boolean isNaturalComparator(Comparator<?> a)
{
return a == null || a == Comparator.naturalOrder() || a == Ordering.natural();
}
示例4: of
import com.google.common.collect.Ordering; //导入方法依赖的package包/类
public static <V extends Comparable<V>> BTreeSet<V> of(Collection<V> sortedValues)
{
return new BTreeSet<>(BTree.build(sortedValues, UpdateFunction.<V>noOp()), Ordering.<V>natural());
}
示例5: newSet
import com.google.common.collect.Ordering; //导入方法依赖的package包/类
private ImmutableSortedSet<String> newSet() {
List<String> original = new ArrayList<>();
Collections.addAll(original, "foo", "bar", "baz");
return new ImmutableSortedSet<>(original, Ordering.<String>natural());
}
示例6: natural
import com.google.common.collect.Ordering; //导入方法依赖的package包/类
/**
* Returns an instance which specifies that the natural ordering of the elements is guaranteed.
*/
public static <S extends Comparable<? super S>> ElementOrder<S> natural() {
return new ElementOrder<S>(Type.SORTED, Ordering.<S>natural());
}