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

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

源代码1 项目: j2objc   文件: IntPipeline.java
@Override
public final IntStream map(IntUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Integer>(this, StreamShape.INT_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        public Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedInt<Integer>(sink) {
                @Override
                public void accept(int t) {
                    downstream.accept(mapper.applyAsInt(t));
                }
            };
        }
    };
}
 
源代码2 项目: dragonwell8_jdk   文件: IntStream.java
/**
 * Returns an infinite sequential ordered {@code IntStream} produced by iterative
 * application of a function {@code f} to an initial element {@code seed},
 * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
 * {@code f(f(seed))}, etc.
 *
 * <p>The first element (position {@code 0}) in the {@code IntStream} will be
 * the provided {@code seed}.  For {@code n > 0}, the element at position
 * {@code n}, will be the result of applying the function {@code f} to the
 * element at position {@code n - 1}.
 *
 * @param seed the initial element
 * @param f a function to be applied to the previous element to produce
 *          a new element
 * @return A new sequential {@code IntStream}
 */
public static IntStream iterate(final int seed, final IntUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfInt iterator = new PrimitiveIterator.OfInt() {
        int t = seed;

        @Override
        public boolean hasNext() {
            return true;
        }

        @Override
        public int nextInt() {
            int v = t;
            t = f.applyAsInt(t);
            return v;
        }
    };
    return StreamSupport.intStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
源代码3 项目: jdk8u-dev-jdk   文件: IntPipeline.java
@Override
public final IntStream map(IntUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Integer>(this, StreamShape.INT_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedInt<Integer>(sink) {
                @Override
                public void accept(int t) {
                    downstream.accept(mapper.applyAsInt(t));
                }
            };
        }
    };
}
 
源代码4 项目: TencentKona-8   文件: IntPipeline.java
@Override
public final IntStream map(IntUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Integer>(this, StreamShape.INT_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedInt<Integer>(sink) {
                @Override
                public void accept(int t) {
                    downstream.accept(mapper.applyAsInt(t));
                }
            };
        }
    };
}
 
源代码5 项目: consulo   文件: IntEnumerator.java
void dump(DataOutputStream stream, IntUnaryOperator idRemapping) throws IOException {
  DataInputOutputUtil.writeINT(stream, myIds.size());
  IOException[] exception = new IOException[1];
  myIds.forEach(id -> {
    try {
      int remapped = idRemapping.applyAsInt(id);
      if (remapped == 0) {
        exception[0] = new IOException("remapping is not found for " + id);
        return false;
      }
      DataInputOutputUtil.writeINT(stream, remapped);
    }
    catch (IOException e) {
      exception[0] = e;
      return false;
    }
    return true;
  });
  if (exception[0] != null) {
    throw exception[0];
  }
}
 
源代码6 项目: openjdk-jdk8u-backup   文件: IntStream.java
/**
 * Returns an infinite sequential ordered {@code IntStream} produced by iterative
 * application of a function {@code f} to an initial element {@code seed},
 * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
 * {@code f(f(seed))}, etc.
 *
 * <p>The first element (position {@code 0}) in the {@code IntStream} will be
 * the provided {@code seed}.  For {@code n > 0}, the element at position
 * {@code n}, will be the result of applying the function {@code f} to the
 * element at position {@code n - 1}.
 *
 * @param seed the initial element
 * @param f a function to be applied to to the previous element to produce
 *          a new element
 * @return A new sequential {@code IntStream}
 */
public static IntStream iterate(final int seed, final IntUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfInt iterator = new PrimitiveIterator.OfInt() {
        int t = seed;

        @Override
        public boolean hasNext() {
            return true;
        }

        @Override
        public int nextInt() {
            int v = t;
            t = f.applyAsInt(t);
            return v;
        }
    };
    return StreamSupport.intStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
源代码7 项目: jdk8u_jdk   文件: IntStream.java
/**
 * Returns an infinite sequential ordered {@code IntStream} produced by iterative
 * application of a function {@code f} to an initial element {@code seed},
 * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
 * {@code f(f(seed))}, etc.
 *
 * <p>The first element (position {@code 0}) in the {@code IntStream} will be
 * the provided {@code seed}.  For {@code n > 0}, the element at position
 * {@code n}, will be the result of applying the function {@code f} to the
 * element at position {@code n - 1}.
 *
 * @param seed the initial element
 * @param f a function to be applied to the previous element to produce
 *          a new element
 * @return A new sequential {@code IntStream}
 */
public static IntStream iterate(final int seed, final IntUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfInt iterator = new PrimitiveIterator.OfInt() {
        int t = seed;

        @Override
        public boolean hasNext() {
            return true;
        }

        @Override
        public int nextInt() {
            int v = t;
            t = f.applyAsInt(t);
            return v;
        }
    };
    return StreamSupport.intStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
源代码8 项目: Java8CN   文件: IntPipeline.java
@Override
public final IntStream map(IntUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Integer>(this, StreamShape.INT_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedInt<Integer>(sink) {
                @Override
                public void accept(int t) {
                    downstream.accept(mapper.applyAsInt(t));
                }
            };
        }
    };
}
 
源代码9 项目: jdk8u-jdk   文件: IntPipeline.java
@Override
public final IntStream map(IntUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Integer>(this, StreamShape.INT_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedInt<Integer>(sink) {
                @Override
                public void accept(int t) {
                    downstream.accept(mapper.applyAsInt(t));
                }
            };
        }
    };
}
 
源代码10 项目: FreeBuilder   文件: NullableMapperMethodTest.java
@Test
public void mapCanAcceptPrimitiveFunctionalInterface() {
  behaviorTester
      .with(new Processor(features))
      .with(SourceBuilder.forTesting()
          .addLine("package com.example;")
          .addLine("@%s", FreeBuilder.class)
          .addLine("public interface DataType {")
          .addLine("  @%s Integer %s;", Nullable.class, convention.get("property"))
          .addLine("")
          .addLine("  public static class Builder extends DataType_Builder {")
          .addLine("    @Override public Builder mapProperty(%s mapper) {",
              IntUnaryOperator.class)
          .addLine("      return super.mapProperty(mapper);")
          .addLine("    }")
          .addLine("  }")
          .addLine("}"))
      .with(testBuilder()
          .addLine("DataType value = new DataType.Builder()")
          .addLine("    .%s(11)", convention.set("property"))
          .addLine("    .mapProperty(a -> a + 3)")
          .addLine("    .build();")
          .addLine("assertEquals(14, (int) value.%s);", convention.get("property"))
          .build())
      .runTest();
}
 
源代码11 项目: JDKSourceCode1.8   文件: IntPipeline.java
@Override
public final IntStream map(IntUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Integer>(this, StreamShape.INT_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedInt<Integer>(sink) {
                @Override
                public void accept(int t) {
                    downstream.accept(mapper.applyAsInt(t));
                }
            };
        }
    };
}
 
源代码12 项目: jdk8u-jdk   文件: SetAllTest.java
@Test(dataProvider = "int")
public void testSetAllInt(String name, int size, IntUnaryOperator generator, int[] expected) {
    int[] result = new int[size];
    Arrays.setAll(result, generator);
    assertEquals(result, expected, "setAll(int[], IntUnaryOperator) case " + name + " failed.");

    // ensure fresh array
    result = new int[size];
    Arrays.parallelSetAll(result, generator);
    assertEquals(result, expected, "parallelSetAll(int[], IntUnaryOperator) case " + name + " failed.");
}
 
源代码13 项目: openjdk-8-source   文件: SetAllTest.java
@Test(dataProvider = "int")
public void testSetAllInt(String name, int size, IntUnaryOperator generator, int[] expected) {
    int[] result = new int[size];
    Arrays.setAll(result, generator);
    assertEquals(result, expected, "setAll(int[], IntUnaryOperator) case " + name + " failed.");

    // ensure fresh array
    result = new int[size];
    Arrays.parallelSetAll(result, generator);
    assertEquals(result, expected, "parallelSetAll(int[], IntUnaryOperator) case " + name + " failed.");
}
 
源代码14 项目: crate   文件: ArrayLengthQuery.java
NumTermsPerDocTwoPhaseIterator(LeafReader reader,
                               IntUnaryOperator numTermsOfDoc,
                               IntPredicate matches) {
    super(DocIdSetIterator.all(reader.maxDoc()));
    this.numTermsOfDoc = numTermsOfDoc;
    this.matches = matches;
}
 
源代码15 项目: IPAddress   文件: AddressDivisionGrouping.java
protected static long getLongCount(IntUnaryOperator countProvider, int segCount) {
	if(segCount == 0) {
		return 1;
	}
	long result = countProvider.applyAsInt(0);
	for(int i = 1; i < segCount; i++) {
		result *= countProvider.applyAsInt(i);
	}
	return result;
}
 
源代码16 项目: servicetalk   文件: DefaultSerializer.java
@Override
public <T> Publisher<Buffer> serialize(final Publisher<T> source, final BufferAllocator allocator,
                                       final Class<T> type, final IntUnaryOperator bytesEstimator) {
    return new SubscribablePublisher<Buffer>() {
        @Override
        protected void handleSubscribe(final Subscriber<? super Buffer> subscriber) {
            applySerializer0(subscriber, allocator, bytesEstimator, serializationProvider.getSerializer(type),
                    source);
        }
    };
}
 
源代码17 项目: openjdk-jdk9   文件: ReaderTest.java
private void checkAndSetOrder(IntPredicate expectedValue,
                              IntUnaryOperator newValue) {
    if (!expectedValue.test(invocationOrder)) {
        throw new TestSupport.AssertionFailedException(
                expectedValue + " -> " + newValue);
    }
    invocationOrder = newValue.applyAsInt(invocationOrder);
}
 
源代码18 项目: ph-commons   文件: IntIntMap.java
public int computeIfAbsent (final int key, @Nonnull final IntUnaryOperator aProvider)
{
  int ret = get (key);
  if (ret == NO_VALUE)
  {
    ret = aProvider.applyAsInt (key);
    if (ret != NO_VALUE)
      put (key, ret);
  }
  return ret;
}
 
public static IntUnaryOperator createReplaceEntityIdFunc(IntSupplier id1Supplier, IntSupplier id2Supplier) {
	return (entityId) -> {
		int entityId1 = id1Supplier.getAsInt();
		int entityId2 = id2Supplier.getAsInt();
		if (entityId == entityId1) {
			return entityId2;
		}
		if (entityId == entityId2) {
			return entityId1;
		}
		return entityId;
	};
}
 
源代码20 项目: j2objc   文件: IntUnaryOperatorTest.java
public void testAndThen_null() throws Exception {
  IntUnaryOperator plusOne = x -> x + 1;
  try {
    plusOne.andThen(null);
    fail();
  } catch (NullPointerException expected) {}
}
 
源代码21 项目: agrona   文件: Int2IntCounterMapTest.java
@Test
public void shouldComputeIfAbsent()
{
    final int testKey = 7;
    final int testValue = 7;

    final IntUnaryOperator function = (i) -> testValue;

    assertEquals(map.initialValue(), map.get(testKey));

    assertThat(map.computeIfAbsent(testKey, function), is(testValue));
    assertThat(map.get(testKey), is(testValue));
}
 
源代码22 项目: Cardshifter   文件: ECSResourceData.java
public void changeBy(int value, IntUnaryOperator fix) {
    int newValue = current + value;
    set(fix.applyAsInt(newValue));
}
 
@Override
public <T> HttpSerializer<T> serializerFor(final Class<T> type, final IntUnaryOperator bytesEstimator) {
    return new DefaultSizeAwareClassHttpSerializer<>(type, serializer, addContentType, bytesEstimator);
}
 
源代码24 项目: rheem   文件: JavaReservoirSampleOperator.java
/**
 * Creates a new instance.
 */
public JavaReservoirSampleOperator(IntUnaryOperator sampleSizeFunction, DataSetType<Type> type, LongUnaryOperator seed) {
    super(sampleSizeFunction, type, Methods.RESERVOIR, seed);
}
 
源代码25 项目: servicetalk   文件: DefaultSerializer.java
@Override
public <T> BlockingIterable<Buffer> serialize(final BlockingIterable<T> source, final BufferAllocator allocator,
                                              final Class<T> type, final IntUnaryOperator bytesEstimator) {
    return applySerializer0(allocator, bytesEstimator, source, serializationProvider.getSerializer(type));
}
 
源代码26 项目: servicetalk   文件: DefaultSerializer.java
@Override
public <T> Iterable<Buffer> serialize(final Iterable<T> source, final BufferAllocator allocator,
                                      final TypeHolder<T> typeHolder, final IntUnaryOperator bytesEstimator) {
    final StreamingSerializer serializer = serializationProvider.getSerializer(typeHolder);
    return applySerializer0(allocator, bytesEstimator, source, serializer);
}
 
源代码27 项目: IPAddress   文件: IPAddressSection.java
protected static <R extends IPAddressSection, S extends IPAddressSegment> R setPrefixLength(
		R original,
		IPAddressCreator<?, R, ?, S, ?> creator,
		int networkPrefixLength,
		boolean withZeros,
		boolean noShrink,
		boolean singleOnly,
		SegFunction<R, S> segProducer) throws IncompatibleAddressException {
	Integer existingPrefixLength = original.getNetworkPrefixLength();
	if(existingPrefixLength != null) {
		if(networkPrefixLength == existingPrefixLength.intValue()) {
			return original;
		} else if(noShrink && networkPrefixLength > existingPrefixLength.intValue()) {
			checkSubnet(original, networkPrefixLength);
			return original;
		}
	}
	checkSubnet(original, networkPrefixLength);
	IPAddressNetwork<?, R, ?, S, ?> network = creator.getNetwork();
	int maskBits;
	IntUnaryOperator segmentMaskProducer = null;
	if(network.getPrefixConfiguration().allPrefixedAddressesAreSubnets()) {
		if(existingPrefixLength != null) {
			if(networkPrefixLength > existingPrefixLength.intValue()) {
				if(withZeros) {
					maskBits = existingPrefixLength;
				} else {
					maskBits = networkPrefixLength;
				}
			} else { // networkPrefixLength < existingPrefixLength.intValue()
				maskBits = networkPrefixLength;
			} 
		} else {
			maskBits = networkPrefixLength;
		}
	} else {
		if(existingPrefixLength != null) {
			if(withZeros) {
				R leftMask, rightMask;
				if(networkPrefixLength > existingPrefixLength.intValue()) {
					leftMask = network.getNetworkMaskSection(existingPrefixLength);
					rightMask = network.getHostMaskSection(networkPrefixLength);
				} else {
					leftMask = network.getNetworkMaskSection(networkPrefixLength);
					rightMask = network.getHostMaskSection(existingPrefixLength);
				}
				segmentMaskProducer = i -> {
					int val1 = segProducer.apply(leftMask, i).getSegmentValue();
					int val2 = segProducer.apply(rightMask, i).getSegmentValue();
					return val1 | val2;
				};
			}
		}
		maskBits = original.getBitCount();
	}
	if(segmentMaskProducer == null) {
		R mask = network.getNetworkMaskSection(maskBits);
		segmentMaskProducer = i -> segProducer.apply(mask, i).getSegmentValue();
	}
	return getSubnetSegments(
			original,
			cacheBits(networkPrefixLength),
			creator,
			true,
			i -> segProducer.apply(original, i),
			segmentMaskProducer,
			singleOnly);
}
 
源代码28 项目: rheem   文件: SparkRandomPartitionSampleOperator.java
/**
 * Creates a new instance.
 */
public SparkRandomPartitionSampleOperator(IntUnaryOperator sampleSizeFunction, DataSetType<Type> type, LongUnaryOperator seedFunction) {
    super(sampleSizeFunction, type, Methods.RANDOM, seedFunction);
}
 
源代码29 项目: es6draft   文件: TypedArrayFunctions.java
private static final void put(IntUnaryOperator src, int srcPos, ByteBuffer dest, int destPos, int length) {
    for (int n = destPos, k = srcPos; k < srcPos + length;) {
        dest.put(n++, (byte) src.applyAsInt(k++));
    }
}
 
源代码30 项目: parquet-mr   文件: IndexIterator.java
static PrimitiveIterator.OfInt filterTranslate(int arrayLength, IntPredicate filter, IntUnaryOperator translator) {
  return new IndexIterator(0, arrayLength, filter, translator);
}
 
 类所在包
 类方法
 同包方法