本文整理匯總了Java中java.util.Spliterator.getComparator方法的典型用法代碼示例。如果您正苦於以下問題:Java Spliterator.getComparator方法的具體用法?Java Spliterator.getComparator怎麽用?Java Spliterator.getComparator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Spliterator
的用法示例。
在下文中一共展示了Spliterator.getComparator方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: assertSpliterator
import java.util.Spliterator; //導入方法依賴的package包/類
private static void assertSpliterator(Spliterator<?> s) {
if (s.hasCharacteristics(Spliterator.SUBSIZED)) {
assertTrue(s.hasCharacteristics(Spliterator.SIZED));
}
if (s.hasCharacteristics(Spliterator.SIZED)) {
assertTrue(s.estimateSize() != Long.MAX_VALUE);
assertTrue(s.getExactSizeIfKnown() >= 0);
}
try {
s.getComparator();
assertTrue(s.hasCharacteristics(Spliterator.SORTED));
} catch (IllegalStateException e) {
assertFalse(s.hasCharacteristics(Spliterator.SORTED));
}
}
示例2: assertISEComparator
import java.util.Spliterator; //導入方法依賴的package包/類
void assertISEComparator(Spliterator<?> s) {
boolean caught = false;
try {
s.getComparator();
}
catch (IllegalStateException e) {
caught = true;
}
assertTrue(caught, "Throwing IllegalStateException");
}
示例3: testGetComparator_IllegalStateException
import java.util.Spliterator; //導入方法依賴的package包/類
/**
* Spliterator.getComparator throws IllegalStateException iff the
* spliterator does not report SORTED.
*/
public void testGetComparator_IllegalStateException() {
Collection c = impl.emptyCollection();
Spliterator s = c.spliterator();
boolean reportsSorted = s.hasCharacteristics(Spliterator.SORTED);
try {
s.getComparator();
assertTrue(reportsSorted);
} catch (IllegalStateException ex) {
assertFalse(reportsSorted);
}
}
示例4: filter
import java.util.Spliterator; //導入方法依賴的package包/類
/** Returns a {@code Spliterator} filtered by the specified predicate. */
static <T> Spliterator<T> filter(Spliterator<T> fromSpliterator, Predicate<? super T> predicate) {
checkNotNull(fromSpliterator);
checkNotNull(predicate);
class Splitr implements Spliterator<T>, Consumer<T> {
T holder = null;
@Override
public void accept(T t) {
this.holder = t;
}
@Override
public boolean tryAdvance(Consumer<? super T> action) {
while (fromSpliterator.tryAdvance(this)) {
try {
if (predicate.test(holder)) {
action.accept(holder);
return true;
}
} finally {
holder = null;
}
}
return false;
}
@Override
public Spliterator<T> trySplit() {
Spliterator<T> fromSplit = fromSpliterator.trySplit();
return (fromSplit == null) ? null : filter(fromSplit, predicate);
}
@Override
public long estimateSize() {
return fromSpliterator.estimateSize() / 2;
}
@Override
public Comparator<? super T> getComparator() {
return fromSpliterator.getComparator();
}
@Override
public int characteristics() {
return fromSpliterator.characteristics()
& (Spliterator.DISTINCT
| Spliterator.NONNULL
| Spliterator.ORDERED
| Spliterator.SORTED);
}
}
return new Splitr();
}
示例5: fromCharacteristics
import java.util.Spliterator; //導入方法依賴的package包/類
/**
* Converts a spliterator characteristic bit set to stream flags.
*
* @implSpec
* If the spliterator is naturally {@code SORTED} (the associated
* {@code Comparator} is {@code null}) then the characteristic is converted
* to the {@link #SORTED} flag, otherwise the characteristic is not
* converted.
*
* @param spliterator the spliterator from which to obtain characteristic
* bit set.
* @return the stream flags.
*/
static int fromCharacteristics(Spliterator<?> spliterator) {
int characteristics = spliterator.characteristics();
if ((characteristics & Spliterator.SORTED) != 0 && spliterator.getComparator() != null) {
// Do not propagate the SORTED characteristic if it does not correspond
// to a natural sort order
return characteristics & SPLITERATOR_CHARACTERISTICS_MASK & ~Spliterator.SORTED;
}
else {
return characteristics & SPLITERATOR_CHARACTERISTICS_MASK;
}
}