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

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

源代码1 项目: openjdk-jdk9   文件: LongPipeline.java
@Override
public final LongStream map(LongUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
 
源代码2 项目: dragonwell8_jdk   文件: LongPipeline.java
@Override
public final LongStream map(LongUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
 
源代码3 项目: dragonwell8_jdk   文件: LongStream.java
/**
 * Returns an infinite sequential ordered {@code LongStream} 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 LongStream} 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 LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfLong iterator = new PrimitiveIterator.OfLong() {
        long t = seed;

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

        @Override
        public long nextLong() {
            long v = t;
            t = f.applyAsLong(t);
            return v;
        }
    };
    return StreamSupport.longStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
源代码4 项目: Bytecoder   文件: LongPipeline.java
@Override
public final LongStream map(LongUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
 
源代码5 项目: TencentKona-8   文件: LongPipeline.java
@Override
public final LongStream map(LongUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
 
源代码6 项目: jdk8u60   文件: LongPipeline.java
@Override
public final LongStream map(LongUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
 
源代码7 项目: jdk8u60   文件: LongStream.java
/**
 * Returns an infinite sequential ordered {@code LongStream} 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 LongStream} 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 LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfLong iterator = new PrimitiveIterator.OfLong() {
        long t = seed;

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

        @Override
        public long nextLong() {
            long v = t;
            t = f.applyAsLong(t);
            return v;
        }
    };
    return StreamSupport.longStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
源代码8 项目: JDKSourceCode1.8   文件: LongStream.java
/**
 * Returns an infinite sequential ordered {@code LongStream} 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 LongStream} 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 LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfLong iterator = new PrimitiveIterator.OfLong() {
        long t = seed;

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

        @Override
        public long nextLong() {
            long v = t;
            t = f.applyAsLong(t);
            return v;
        }
    };
    return StreamSupport.longStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
源代码9 项目: desugar_jdk_libs   文件: LongStream.java
/**
 * Returns an infinite sequential ordered {@code LongStream} 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 LongStream} 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 LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfLong iterator = new PrimitiveIterator.OfLong() {
        long t = seed;

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

        @Override
        public long nextLong() {
            long v = t;
            t = f.applyAsLong(t);
            return v;
        }
    };
    return StreamSupport.longStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
源代码10 项目: openjdk-jdk8u   文件: LongStream.java
/**
 * Returns an infinite sequential ordered {@code LongStream} 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 LongStream} 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 LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfLong iterator = new PrimitiveIterator.OfLong() {
        long t = seed;

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

        @Override
        public long nextLong() {
            long v = t;
            t = f.applyAsLong(t);
            return v;
        }
    };
    return StreamSupport.longStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
源代码11 项目: Bytecoder   文件: LongStream.java
/**
 * Returns an infinite sequential ordered {@code LongStream} 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 LongStream} 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}.
 *
 * <p>The action of applying {@code f} for one element
 * <a href="../concurrent/package-summary.html#MemoryVisibility"><i>happens-before</i></a>
 * the action of applying {@code f} for subsequent elements.  For any given
 * element the action may be performed in whatever thread the library
 * chooses.
 *
 * @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 LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    Spliterator.OfLong spliterator = new Spliterators.AbstractLongSpliterator(Long.MAX_VALUE,
           Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL) {
        long prev;
        boolean started;

        @Override
        public boolean tryAdvance(LongConsumer action) {
            Objects.requireNonNull(action);
            long t;
            if (started)
                t = f.applyAsLong(prev);
            else {
                t = seed;
                started = true;
            }
            action.accept(prev = t);
            return true;
        }
    };
    return StreamSupport.longStream(spliterator, false);
}
 
源代码12 项目: openjdk-jdk8u-backup   文件: LongPipeline.java
@Override
public final LongStream map(LongUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
 
源代码13 项目: openjdk-jdk8u-backup   文件: LongStream.java
/**
 * Returns an infinite sequential ordered {@code LongStream} 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 LongStream} 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 LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfLong iterator = new PrimitiveIterator.OfLong() {
        long t = seed;

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

        @Override
        public long nextLong() {
            long v = t;
            t = f.applyAsLong(t);
            return v;
        }
    };
    return StreamSupport.longStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
源代码14 项目: besu   文件: RLPDecodingHelpers.java
/** Read from the provided offset a size of the provided length, assuming this is enough bytes. */
private static int extractSizeFromLongItem(
    final LongUnaryOperator getter, final long offset, final int sizeLength) {
  if (sizeLength > 4) {
    throw new RLPException(
        "RLP item at offset "
            + offset
            + " with size value consuming "
            + sizeLength
            + " bytes exceeds max supported size of "
            + Integer.MAX_VALUE);
  }

  long res = 0;
  int shift = 0;
  for (int i = 0; i < sizeLength; i++) {
    res |= (getter.applyAsLong(offset + (sizeLength - 1) - i) & 0xFF) << shift;
    shift += 8;
  }
  try {
    return Math.toIntExact(res);
  } catch (final ArithmeticException e) {
    throw new RLPException(
        "RLP item at offset "
            + offset
            + " with size value consuming "
            + sizeLength
            + " bytes exceeds max supported size of "
            + Integer.MAX_VALUE,
        e);
  }
}
 
源代码15 项目: besu   文件: RLPDecodingHelpers.java
static RLPElementMetadata rlpElementMetadata(
    final LongUnaryOperator byteGetter, final long size, final long elementStart) {
  final int prefix = Math.toIntExact(byteGetter.applyAsLong(elementStart)) & 0xFF;
  final Kind kind = Kind.of(prefix);
  long payloadStart = 0;
  int payloadSize = 0;

  switch (kind) {
    case BYTE_ELEMENT:
      payloadStart = elementStart;
      payloadSize = 1;
      break;
    case SHORT_ELEMENT:
      payloadStart = elementStart + 1;
      payloadSize = prefix - 0x80;
      break;
    case LONG_ELEMENT:
      final int sizeLengthElt = prefix - 0xb7;
      payloadStart = elementStart + 1 + sizeLengthElt;
      payloadSize = readLongSize(byteGetter, size, elementStart, sizeLengthElt);
      break;
    case SHORT_LIST:
      payloadStart = elementStart + 1;
      payloadSize = prefix - 0xc0;
      break;
    case LONG_LIST:
      final int sizeLengthList = prefix - 0xf7;
      payloadStart = elementStart + 1 + sizeLengthList;
      payloadSize = readLongSize(byteGetter, size, elementStart, sizeLengthList);
      break;
  }

  return new RLPElementMetadata(kind, elementStart, payloadStart, payloadSize);
}
 
源代码16 项目: besu   文件: RLPDecodingHelpers.java
/** The size of the item payload for a "long" item, given the length in bytes of the said size. */
private static int readLongSize(
    final LongUnaryOperator byteGetter,
    final long sizeOfRlpEncodedByteString,
    final long item,
    final int sizeLength) {
  // We will read sizeLength bytes from item + 1. There must be enough bytes for this or the input
  // is corrupted.
  if (sizeOfRlpEncodedByteString - (item + 1) < sizeLength) {
    throw new CorruptedRLPInputException(
        String.format(
            "Invalid RLP item: value of size %d has not enough bytes to read the %d "
                + "bytes payload size",
            sizeOfRlpEncodedByteString, sizeLength));
  }

  // That size (which is at least 1 byte by construction) shouldn't have leading zeros.
  if (byteGetter.applyAsLong(item + 1) == 0) {
    throw new MalformedRLPInputException("Malformed RLP item: size of payload has leading zeros");
  }

  final int res = RLPDecodingHelpers.extractSizeFromLongItem(byteGetter, item + 1, sizeLength);

  // We should not have had the size written separately if it was less than 56 bytes long.
  if (res < 56) {
    throw new MalformedRLPInputException(
        String.format("Malformed RLP item: written as a long item, but size %d < 56 bytes", res));
  }

  return res;
}
 
源代码17 项目: presto   文件: PartitionTransforms.java
private static Block extractDate(Block block, LongUnaryOperator function)
{
    BlockBuilder builder = INTEGER.createFixedSizeBlockBuilder(block.getPositionCount());
    for (int position = 0; position < block.getPositionCount(); position++) {
        if (block.isNull(position)) {
            builder.appendNull();
            continue;
        }
        long value = DATE.getLong(block, position);
        value = function.applyAsLong(value);
        INTEGER.writeLong(builder, value);
    }
    return builder.build();
}
 
源代码18 项目: presto   文件: PartitionTransforms.java
private static Block extractTimestampWithTimeZone(Block block, LongUnaryOperator function)
{
    BlockBuilder builder = INTEGER.createFixedSizeBlockBuilder(block.getPositionCount());
    for (int position = 0; position < block.getPositionCount(); position++) {
        if (block.isNull(position)) {
            builder.appendNull();
            continue;
        }
        long value = unpackMillisUtc(TIMESTAMP_WITH_TIME_ZONE.getLong(block, position));
        value = function.applyAsLong(value);
        INTEGER.writeLong(builder, value);
    }
    return builder.build();
}
 
源代码19 项目: rheem   文件: SampleOperator.java
/**
 * Creates a new instance given user-defined sample size and seed methods.
 */
public SampleOperator(IntUnaryOperator sampleSizeFunction, DataSetType<Type> type, Methods sampleMethod, LongUnaryOperator seedFunction) {
    super(type, type, true);
    this.sampleSizeFunction = sampleSizeFunction;
    this.sampleMethod = sampleMethod;
    this.seedFunction = seedFunction;
}
 
源代码20 项目: oxygen   文件: WheelTimer.java
/**
 * cron任务
 *
 * @param command 任务
 * @param cron 表达式
 * @return ScheduledFuture
 */
public ScheduledFuture<Void> scheduleOnCron(Runnable command, String cron) {
  start();
  LongUnaryOperator operator = new CronExpression(cron).operator();
  long deadline = operator.applyAsLong(0);
  if (deadline == Long.MIN_VALUE) {
    throw Exceptions.fail("cron doesn't have any match in the future");
  }
  PeriodTask task = new PeriodTask(deadline, command, operator, this);
  addTaskInLock(task);
  return task;
}
 
源代码21 项目: incubator-ratis   文件: TestRaftLogIndex.java
static void assertUpdate(RaftLogIndex index, BiFunction<RaftLogIndex, LongUnaryOperator, Boolean> update,
    long oldValue, LongUnaryOperator op, boolean expectUpdate) {
  Assert.assertEquals(oldValue, index.get());
  final boolean updated = update.apply(index, op);
  Assert.assertEquals(expectUpdate, updated);
  Assert.assertEquals(expectUpdate? op.applyAsLong(oldValue): oldValue, index.get());
}
 
源代码22 项目: rheem   文件: FlinkSampleOperator.java
/**
 * Creates a new instance.
 */
public FlinkSampleOperator(IntUnaryOperator sampleSizeFunction, DataSetType<Type> type, LongUnaryOperator seedFunction) {
    super(sampleSizeFunction, type, Methods.RANDOM, seedFunction);
}
 
源代码23 项目: rheem   文件: SparkRandomPartitionSampleOperator.java
/**
 * Creates a new instance.
 */
public SparkRandomPartitionSampleOperator(IntUnaryOperator sampleSizeFunction, DataSetType<Type> type, LongUnaryOperator seedFunction) {
    super(sampleSizeFunction, type, Methods.RANDOM, seedFunction);
}
 
源代码24 项目: rheem   文件: JavaReservoirSampleOperator.java
/**
 * Creates a new instance.
 */
public JavaReservoirSampleOperator(IntUnaryOperator sampleSizeFunction, DataSetType<Type> type, LongUnaryOperator seed) {
    super(sampleSizeFunction, type, Methods.RESERVOIR, seed);
}
 
源代码25 项目: oxygen   文件: CronExpression.java
public LongUnaryOperator operator() {
  return new CronOperator(this);
}
 
源代码26 项目: oxygen   文件: PeriodTask.java
PeriodTask(long deadline, Runnable runnable, LongUnaryOperator operator, WheelTimer timer) {
  super(deadline, runnable);
  this.operator = operator;
  this.timer = timer;
}
 
源代码27 项目: catnip   文件: RoleData.java
@Nonnull
public RoleData updatePermissions(@Nonnull final LongUnaryOperator updater) {
    return permissions(updater.applyAsLong(permissions == null ? 0 : permissions));
}
 
源代码28 项目: openjdk-jdk9   文件: DefaultMethodStreams.java
@Override
public LongStream map(LongUnaryOperator mapper) {
    return s.map(mapper);
}
 
源代码29 项目: jdk8u-jdk   文件: AtomicLong.java
/**
 * Atomically updates the current value with the results of
 * applying the given function, returning the previous value. The
 * function should be side-effect-free, since it may be re-applied
 * when attempted updates fail due to contention among threads.
 *
 * @param updateFunction a side-effect-free function
 * @return the previous value
 * @since 1.8
 */
public final long getAndUpdate(LongUnaryOperator updateFunction) {
    long prev, next;
    do {
        prev = get();
        next = updateFunction.applyAsLong(prev);
    } while (!compareAndSet(prev, next));
    return prev;
}
 
源代码30 项目: jdk8u-jdk   文件: AtomicLong.java
/**
 * Atomically updates the current value with the results of
 * applying the given function, returning the updated value. The
 * function should be side-effect-free, since it may be re-applied
 * when attempted updates fail due to contention among threads.
 *
 * @param updateFunction a side-effect-free function
 * @return the updated value
 * @since 1.8
 */
public final long updateAndGet(LongUnaryOperator updateFunction) {
    long prev, next;
    do {
        prev = get();
        next = updateFunction.applyAsLong(prev);
    } while (!compareAndSet(prev, next));
    return next;
}
 
 类所在包
 类方法
 同包方法