Java Code Examples for java.util.Spliterator#characteristics()

The following examples show how to use java.util.Spliterator#characteristics() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LinkedBlockingDeque8Test.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Spliterator characteristics are as advertised
 */
public void testSpliterator_characteristics() {
    LinkedBlockingDeque q = new LinkedBlockingDeque();
    Spliterator s = q.spliterator();
    int characteristics = s.characteristics();
    int required = Spliterator.CONCURRENT
        | Spliterator.NONNULL
        | Spliterator.ORDERED;
    assertEquals(required, characteristics & required);
    assertTrue(s.hasCharacteristics(required));
    assertEquals(0, characteristics
                 & (Spliterator.DISTINCT
                    | Spliterator.IMMUTABLE
                    | Spliterator.SORTED));
}
 
Example 2
Source File: LinkedBlockingQueue8Test.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Spliterator characteristics are as advertised
 */
public void testSpliterator_characteristics() {
    LinkedBlockingQueue q = new LinkedBlockingQueue();
    Spliterator s = q.spliterator();
    int characteristics = s.characteristics();
    int required = Spliterator.CONCURRENT
        | Spliterator.NONNULL
        | Spliterator.ORDERED;
    assertEquals(required, characteristics & required);
    assertTrue(s.hasCharacteristics(required));
    assertEquals(0, characteristics
                 & (Spliterator.DISTINCT
                    | Spliterator.IMMUTABLE
                    | Spliterator.SORTED));
}
 
Example 3
Source File: SpliteratorLateBindingFailFastTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "Source")
public <T> void lateBindingTestWithCharacteritics(String description, Supplier<Source<T>> ss) {
    Source<T> source = ss.get();
    Collection<T> c = source.asCollection();
    Spliterator<T> s = c.spliterator();
    s.characteristics();

    Set<T> r = new HashSet<>();
    s.forEachRemaining(r::add);

    assertEquals(r, new HashSet<>(c));
}
 
Example 4
Source File: SpliteratorLateBindingFailFastTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "Source")
public <T> void lateBindingTestWithCharacteritics(String description, Supplier<Source<T>> ss) {
    Source<T> source = ss.get();
    Collection<T> c = source.asCollection();
    Spliterator<T> s = c.spliterator();
    s.characteristics();

    Set<T> r = new HashSet<>();
    s.forEachRemaining(r::add);

    assertEquals(r, new HashSet<>(c));
}
 
Example 5
Source File: SpliteratorLateBindingTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "Source.Non.Binding.Characteristics")
public <T> void testCharacteristics(String description, Supplier<Source<T>> ss) {
    Source<T> source = ss.get();
    Spliterator<T> s = source.spliterator();

    s.characteristics();
    source.update();

    Set<T> a = new HashSet<>();
    s.forEachRemaining(a::add);

    Set<T> e = new HashSet<>();
    source.spliterator().forEachRemaining(e::add);
    assertEquals(a, e);
}
 
Example 6
Source File: SpliteratorLateBindingFailFastTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "Source")
public <T> void lateBindingTestWithCharacteritics(String description, Supplier<Source<T>> ss) {
    Source<T> source = ss.get();
    Collection<T> c = source.asCollection();
    Spliterator<T> s = c.spliterator();
    s.characteristics();

    Set<T> r = new HashSet<>();
    s.forEachRemaining(r::add);

    assertEquals(r, new HashSet<>(c));
}
 
Example 7
Source File: SpliteratorLateBindingFailFastTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "Source")
public <T> void lateBindingTestWithCharacteritics(String description, Supplier<Source<T>> ss) {
    Source<T> source = ss.get();
    Collection<T> c = source.asCollection();
    Spliterator<T> s = c.spliterator();
    s.characteristics();

    Set<T> r = new HashSet<>();
    s.forEachRemaining(r::add);

    assertEquals(r, new HashSet<>(c));
}
 
Example 8
Source File: SpliteratorTraversingAndSplittingTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
SplitNode(Consumer<T> c, Spliterator<T> s) {
    this(c, s.characteristics(), s);
}
 
Example 9
Source File: SpliteratorTraversingAndSplittingTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
SplitNode(Consumer<T> c, Spliterator<T> s) {
    this(c, s.characteristics(), s);
}
 
Example 10
Source File: SpliteratorCollisions.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
SplitNode(Consumer<T> c, Spliterator<T> s) {
    this(c, s.characteristics(), s);
}
 
Example 11
Source File: SpliteratorCollisions.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
SplitNode(Consumer<T> c, Spliterator<T> s) {
    this(c, s.characteristics(), s);
}
 
Example 12
Source File: SpliteratorCollisions.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
SplitNode(Consumer<T> c, Spliterator<T> s) {
    this(c, s.characteristics(), s);
}
 
Example 13
Source File: SpliteratorTestHelper.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
SplitNode(Consumer<T> c, Spliterator<T> s) {
    this(c, s.characteristics(), s);
}
 
Example 14
Source File: SpliteratorTestHelper.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
SplitNode(Consumer<T> c, Spliterator<T> s) {
    this(c, s.characteristics(), s);
}
 
Example 15
Source File: SpliteratorCollisions.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
SplitNode(Consumer<T> c, Spliterator<T> s) {
    this(c, s.characteristics(), s);
}
 
Example 16
Source File: SpliteratorCollisions.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
SplitNode(Consumer<T> c, Spliterator<T> s) {
    this(c, s.characteristics(), s);
}
 
Example 17
Source File: StreamOpFlag.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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;
    }
}
 
Example 18
Source File: StreamOpFlag.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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;
    }
}
 
Example 19
Source File: StreamOpFlag.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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;
    }
}
 
Example 20
Source File: StreamOpFlag.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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;
    }
}