类java.util.function.IntFunction源码实例Demo

下面列出了怎么用java.util.function.IntFunction的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: hadoop-ozone   文件: TestOzoneFSInputStream.java
@Test
public void readToByteBuffer() throws IOException {
  for (IntFunction<ByteBuffer> constructor : BUFFER_CONSTRUCTORS) {
    for (int streamLength = 1; streamLength <= 10; streamLength++) {
      for (int bufferCapacity = 0; bufferCapacity <= 10; bufferCapacity++) {
        testReadToByteBuffer(constructor, streamLength, bufferCapacity, 0);
        if (bufferCapacity > 1) {
          testReadToByteBuffer(constructor, streamLength, bufferCapacity, 1);
          if (bufferCapacity > 2) {
            testReadToByteBuffer(constructor, streamLength, bufferCapacity,
                bufferCapacity - 1);
          }
        }
        testReadToByteBuffer(constructor, streamLength, bufferCapacity,
            bufferCapacity);
      }
    }
  }
}
 
源代码2 项目: jdk1.8-source-analysis   文件: AbstractPipeline.java
/**
 * Collect the elements output from the pipeline stage.
 *
 * @param generator the array generator to be used to create array instances
 * @return a flat array-backed Node that holds the collected output elements
 */
@SuppressWarnings("unchecked")
final Node<E_OUT> evaluateToArrayNode(IntFunction<E_OUT[]> generator) {
    if (linkedOrConsumed)
        throw new IllegalStateException(MSG_STREAM_LINKED);
    linkedOrConsumed = true;

    // If the last intermediate operation is stateful then
    // evaluate directly to avoid an extra collection step
    if (isParallel() && previousStage != null && opIsStateful()) {
        // Set the depth of this, last, pipeline stage to zero to slice the
        // pipeline such that this operation will not be included in the
        // upstream slice and upstream operations will not be included
        // in this slice
        depth = 0;
        return opEvaluateParallel(previousStage, previousStage.sourceSpliterator(0), generator);
    }
    else {
        return evaluate(sourceSpliterator(0), true, generator);
    }
}
 
源代码3 项目: Quicksql   文件: Mappings.java
/**
 * Returns a mapping that shifts a given mapping's source by a given
 * offset.
 *
 * <p>For example, given {@code mapping} with sourceCount=2, targetCount=8,
 * and (source, target) entries {[0: 5], [1: 7]}, offsetSource(mapping, 3)
 * returns a mapping with sourceCount=5, targetCount=8,
 * and (source, target) entries {[3: 5], [4: 7]}.
 *
 * @param mapping     Input mapping
 * @param offset      Offset to be applied to each source
 * @param sourceCount New source count; must be at least {@code mapping}'s
 *                    source count plus {@code offset}
 * @return Shifted mapping
 */
public static TargetMapping offsetSource(
    final TargetMapping mapping, final int offset, final int sourceCount) {
  if (sourceCount < mapping.getSourceCount() + offset) {
    throw new IllegalArgumentException("new source count too low");
  }
  return target(
      (IntFunction<Integer>) source -> {
        int source2 = source - offset;
        return source2 < 0 || source2 >= mapping.getSourceCount()
            ? null
            : mapping.getTargetOpt(source2);
      },
      sourceCount,
      mapping.getTargetCount());
}
 
源代码4 项目: TencentKona-8   文件: SortedOps.java
@Override
public <P_IN> Node<Long> opEvaluateParallel(PipelineHelper<Long> helper,
                                            Spliterator<P_IN> spliterator,
                                            IntFunction<Long[]> generator) {
    if (StreamOpFlag.SORTED.isKnown(helper.getStreamAndOpFlags())) {
        return helper.evaluate(spliterator, false, generator);
    }
    else {
        Node.OfLong n = (Node.OfLong) helper.evaluate(spliterator, true, generator);

        long[] content = n.asPrimitiveArray();
        Arrays.parallelSort(content);

        return Nodes.node(content);
    }
}
 
源代码5 项目: jdk1.8-source-analysis   文件: IntPipeline.java
@Override
public final <U> Stream<U> mapToObj(IntFunction<? extends U> mapper) {
    Objects.requireNonNull(mapper);
    return new ReferencePipeline.StatelessOp<Integer, U>(this, StreamShape.INT_VALUE,
                                                         StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Integer> opWrapSink(int flags, Sink<U> sink) {
            return new Sink.ChainedInt<U>(sink) {
                @Override
                public void accept(int t) {
                    downstream.accept(mapper.apply(t));
                }
            };
        }
    };
}
 
源代码6 项目: jdk1.8-source-analysis   文件: SortedOps.java
@Override
public <P_IN> Node<T> opEvaluateParallel(PipelineHelper<T> helper,
                                         Spliterator<P_IN> spliterator,
                                         IntFunction<T[]> generator) {
    // If the input is already naturally sorted and this operation
    // naturally sorts then collect the output
    if (StreamOpFlag.SORTED.isKnown(helper.getStreamAndOpFlags()) && isNaturalSort) {
        return helper.evaluate(spliterator, false, generator);
    }
    else {
        // @@@ Weak two-pass parallel implementation; parallel collect, parallel sort
        T[] flattenedData = helper.evaluate(spliterator, true, generator).asArray(generator);
        Arrays.parallelSort(flattenedData, comparator);
        return Nodes.node(flattenedData);
    }
}
 
源代码7 项目: jdk1.8-source-analysis   文件: SortedOps.java
@Override
public <P_IN> Node<Integer> opEvaluateParallel(PipelineHelper<Integer> helper,
                                               Spliterator<P_IN> spliterator,
                                               IntFunction<Integer[]> generator) {
    if (StreamOpFlag.SORTED.isKnown(helper.getStreamAndOpFlags())) {
        return helper.evaluate(spliterator, false, generator);
    }
    else {
        Node.OfInt n = (Node.OfInt) helper.evaluate(spliterator, true, generator);

        int[] content = n.asPrimitiveArray();
        Arrays.parallelSort(content);

        return Nodes.node(content);
    }
}
 
源代码8 项目: hadoop-ozone   文件: TestOzoneFSInputStream.java
@Test
public void readEmptyStreamToByteBuffer() throws IOException {
  for (IntFunction<ByteBuffer> constructor : BUFFER_CONSTRUCTORS) {
    final OzoneFSInputStream subject = createTestSubject(emptyStream());
    final ByteBuffer buf = constructor.apply(1);

    final int bytesRead = subject.read(buf);

    assertEquals(-1, bytesRead);
    assertEquals(0, buf.position());
  }
}
 
源代码9 项目: hadoop-ozone   文件: TestOzoneFSInputStream.java
@Test
public void bufferPositionUnchangedOnEOF() throws IOException {
  for (IntFunction<ByteBuffer> constructor : BUFFER_CONSTRUCTORS) {
    final OzoneFSInputStream subject = createTestSubject(eofStream());
    final ByteBuffer buf = constructor.apply(123);

    final int bytesRead = subject.read(buf);

    assertEquals(-1, bytesRead);
    assertEquals(0, buf.position());
  }
}
 
源代码10 项目: dragonwell8_jdk   文件: SetAllTest.java
@Test(dataProvider = "string")
public void testSetAllString(String name, int size, IntFunction<String> generator, String[] expected) {
    String[] result = new String[size];
    Arrays.setAll(result, generator);
    assertEquals(result, expected, "setAll(String[], IntFunction<String>) case " + name + " failed.");

    // ensure fresh array
    result = new String[size];
    Arrays.parallelSetAll(result, generator);
    assertEquals(result, expected, "parallelSetAll(String[], IntFunction<String>) case " + name + " failed.");
}
 
源代码11 项目: dragonwell8_jdk   文件: AbstractPipeline.java
@Override
@SuppressWarnings("unchecked")
final <P_IN> Node<E_OUT> evaluate(Spliterator<P_IN> spliterator,
                                  boolean flatten,
                                  IntFunction<E_OUT[]> generator) {
    if (isParallel()) {
        // @@@ Optimize if op of this pipeline stage is a stateful op
        return evaluateToNode(this, spliterator, flatten, generator);
    }
    else {
        Node.Builder<E_OUT> nb = makeNodeBuilder(
                exactOutputSizeIfKnown(spliterator), generator);
        return wrapAndCopyInto(nb, spliterator).build();
    }
}
 
源代码12 项目: presto   文件: PartitionedConsumption.java
private PartitionedConsumption(
        int consumersCount,
        ListenableFuture<?> activator,
        Iterable<Integer> partitionNumbers,
        IntFunction<ListenableFuture<T>> loader,
        IntConsumer disposer)
{
    checkArgument(consumersCount > 0, "consumersCount must be positive");
    this.consumersCount = consumersCount;
    this.partitions = createPartitions(activator, partitionNumbers, loader, disposer);
}
 
源代码13 项目: patchwork-api   文件: EnumHacks.java
public static <T extends Enum<T>> T constructAndAdd(Class<T> clazz, IntFunction<? extends T> constructor) {
	T[] values = clazz.getEnumConstants();
	T instance = constructor.apply(values.length);
	addToValues(values, instance);
	clearCachedValues(clazz);
	return instance;
}
 
源代码14 项目: TencentKona-8   文件: SetAllTest.java
@Test(dataProvider = "string")
public void testSetAllString(String name, int size, IntFunction<String> generator, String[] expected) {
    String[] result = new String[size];
    Arrays.setAll(result, generator);
    assertEquals(result, expected, "setAll(String[], IntFunction<String>) case " + name + " failed.");

    // ensure fresh array
    result = new String[size];
    Arrays.parallelSetAll(result, generator);
    assertEquals(result, expected, "parallelSetAll(String[], IntFunction<String>) case " + name + " failed.");
}
 
源代码15 项目: TencentKona-8   文件: IntPipeline.java
@Override
final <P_IN> Node<Integer> evaluateToNode(PipelineHelper<Integer> helper,
                                          Spliterator<P_IN> spliterator,
                                          boolean flattenTree,
                                          IntFunction<Integer[]> generator) {
    return Nodes.collectInt(helper, spliterator, flattenTree);
}
 
源代码16 项目: TencentKona-8   文件: LongPipeline.java
@Override
final <P_IN> Node<Long> evaluateToNode(PipelineHelper<Long> helper,
                                       Spliterator<P_IN> spliterator,
                                       boolean flattenTree,
                                       IntFunction<Long[]> generator) {
    return Nodes.collectLong(helper, spliterator, flattenTree);
}
 
源代码17 项目: presto   文件: TestOracleTypes.java
private static DataTypeTest unicodeTests(IntFunction<DataType<String>> typeConstructor, ToIntFunction<String> stringLength, int maxSize)
{
    String unicodeText = "攻殻機動隊";
    String nonBmpCharacter = "\ud83d\ude02";
    int unicodeLength = stringLength.applyAsInt(unicodeText);
    int nonBmpLength = stringLength.applyAsInt(nonBmpCharacter);

    return DataTypeTest.create()
            .addRoundTrip(typeConstructor.apply(unicodeLength), unicodeText)
            .addRoundTrip(typeConstructor.apply(unicodeLength + 8), unicodeText)
            .addRoundTrip(typeConstructor.apply(maxSize), unicodeText)
            .addRoundTrip(typeConstructor.apply(nonBmpLength), nonBmpCharacter)
            .addRoundTrip(typeConstructor.apply(nonBmpLength + 5), nonBmpCharacter);
}
 
源代码18 项目: TencentKona-8   文件: CollectorOps.java
@Override
public <P_IN> Node<T> opEvaluateParallel(PipelineHelper<T> helper,
                                         Spliterator<P_IN> spliterator,
                                         IntFunction<T[]> generator) {
    int flags = helper.getStreamAndOpFlags();

    Assert.assertTrue(StreamOpFlag.SIZED.isKnown(flags));
    return super.opEvaluateParallel(helper, spliterator, generator);
}
 
源代码19 项目: dragonwell8_jdk   文件: IntPipeline.java
@Override
final <P_IN> Node<Integer> evaluateToNode(PipelineHelper<Integer> helper,
                                          Spliterator<P_IN> spliterator,
                                          boolean flattenTree,
                                          IntFunction<Integer[]> generator) {
    return Nodes.collectInt(helper, spliterator, flattenTree);
}
 
源代码20 项目: TencentKona-8   文件: SliceOps.java
SliceTask(AbstractPipeline<P_OUT, P_OUT, ?> op,
          PipelineHelper<P_OUT> helper,
          Spliterator<P_IN> spliterator,
          IntFunction<P_OUT[]> generator,
          long offset, long size) {
    super(helper, spliterator);
    this.op = op;
    this.generator = generator;
    this.targetOffset = offset;
    this.targetSize = size;
}
 
源代码21 项目: Flink-CEPplus   文件: CompositeSerializerTest.java
@Test
public void testSingleFieldSerializer() {
	TEST_FIELD_SERIALIZERS.forEach(t -> {
		@SuppressWarnings("unchecked")
		TypeSerializer<Object>[] fieldSerializers = new TypeSerializer[] { t.f0 };
		List<Object>[] instances = Arrays.stream(t.f1)
			.map(Arrays::asList)
			.toArray((IntFunction<List<Object>[]>) List[]::new);
		runTests(t.f0.getLength(), fieldSerializers, instances);
	});
}
 
源代码22 项目: pmd-designer   文件: NodeEditionCodeArea.java
@NonNull
public Label buildExpectedLabel(IntFunction<Val<Integer>> numViolationsPerLine, int idx) {
    Label foo = new Label();
    foo.getStyleClass().addAll("num-violations-gutter-label");
    Val<Integer> num = numViolationsPerLine.apply(idx + 1);
    foo.textProperty().bind(num.map(Object::toString));
    foo.setTooltip(new Tooltip("Number of violations expected on this line"));
    foo.visibleProperty().bind(num.map(it -> it > 0));
    return foo;
}
 
源代码23 项目: dragonwell8_jdk   文件: DoublePipeline.java
@Override
final <P_IN> Node<Double> evaluateToNode(PipelineHelper<Double> helper,
                                         Spliterator<P_IN> spliterator,
                                         boolean flattenTree,
                                         IntFunction<Double[]> generator) {
    return Nodes.collectDouble(helper, spliterator, flattenTree);
}
 
源代码24 项目: dragonwell8_jdk   文件: Nodes.java
@Override
public T[] asArray(IntFunction<T[]> generator) {
    long size = count();
    if (size >= MAX_ARRAY_SIZE)
        throw new IllegalArgumentException(BAD_SIZE);
    T[] array = generator.apply((int) size);
    copyInto(array, 0);
    return array;
}
 
源代码25 项目: jdk1.8-source-analysis   文件: ReferencePipeline.java
@Override
final <P_IN> Node<P_OUT> evaluateToNode(PipelineHelper<P_OUT> helper,
                                    Spliterator<P_IN> spliterator,
                                    boolean flattenTree,
                                    IntFunction<P_OUT[]> generator) {
    return Nodes.collect(helper, spliterator, flattenTree, generator);
}
 
源代码26 项目: jdk1.8-source-analysis   文件: ReferencePipeline.java
@Override
@SuppressWarnings("unchecked")
public final <A> A[] toArray(IntFunction<A[]> generator) {
    // Since A has no relation to U (not possible to declare that A is an upper bound of U)
    // there will be no static type checking.
    // Therefore use a raw type and assume A == U rather than propagating the separation of A and U
    // throughout the code-base.
    // The runtime type of U is never checked for equality with the component type of the runtime type of A[].
    // Runtime checking will be performed when an element is stored in A[], thus if A is not a
    // super type of U an ArrayStoreException will be thrown.
    @SuppressWarnings("rawtypes")
    IntFunction rawGenerator = (IntFunction) generator;
    return (A[]) Nodes.flatten(evaluateToArrayNode(rawGenerator), rawGenerator)
                          .asArray(rawGenerator);
}
 
源代码27 项目: TencentKona-8   文件: Nodes.java
@Override
public T[] asArray(IntFunction<T[]> generator) {
    long size = count();
    if (size >= MAX_ARRAY_SIZE)
        throw new IllegalArgumentException(BAD_SIZE);
    T[] array = generator.apply((int) size);
    copyInto(array, 0);
    return array;
}
 
源代码28 项目: TencentKona-8   文件: Node.java
/**
 * {@inheritDoc}
 *
 * @implSpec the default implementation invokes the generator to create
 * an instance of a boxed primitive array with a length of
 * {@link #count()} and then invokes {@link #copyInto(T[], int)} with
 * that array at an offset of 0.
 */
@Override
default T[] asArray(IntFunction<T[]> generator) {
    if (java.util.stream.Tripwire.ENABLED)
        java.util.stream.Tripwire.trip(getClass(), "{0} calling Node.OfPrimitive.asArray");

    long size = count();
    if (size >= Nodes.MAX_ARRAY_SIZE)
        throw new IllegalArgumentException(Nodes.BAD_SIZE);
    T[] boxed = generator.apply((int) count());
    copyInto(boxed, 0);
    return boxed;
}
 
源代码29 项目: jdk1.8-source-analysis   文件: SpinedBuffer.java
/**
 * Create a new array using the specified array factory, and copy the
 * elements into it.
 */
public E[] asArray(IntFunction<E[]> arrayFactory) {
    long size = count();
    if (size >= Nodes.MAX_ARRAY_SIZE)
        throw new IllegalArgumentException(Nodes.BAD_SIZE);
    E[] result = arrayFactory.apply((int) size);
    copyInto(result, 0);
    return result;
}
 
源代码30 项目: jdk1.8-source-analysis   文件: Nodes.java
@SuppressWarnings("unchecked")
ArrayNode(long size, IntFunction<T[]> generator) {
    if (size >= MAX_ARRAY_SIZE)
        throw new IllegalArgumentException(BAD_SIZE);
    this.array = generator.apply((int) size);
    this.curSize = 0;
}
 
 类所在包
 类方法
 同包方法