java.util.function.LongFunction Java Examples

The following examples show how to use java.util.function.LongFunction. 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: FlinkUniverse.java    From flink-statefun with Apache License 2.0 6 votes vote down vote up
private SingleOutputStreamOperator<Void> feedbackOperator(
    SingleOutputStreamOperator<Message> functionOut) {

  LongFunction<Message> toMessage = new CheckpointToMessage(universe.messageFactoryType());

  FeedbackSinkOperator<Message> sinkOperator =
      new FeedbackSinkOperator<>(FEEDBACK_KEY, toMessage);

  return functionOut
      .keyBy(new MessageKeySelector())
      .transform(
          StatefulFunctionsJobConstants.WRITE_BACK_OPERATOR_NAME,
          TypeInformation.of(Void.class),
          sinkOperator)
      .uid(StatefulFunctionsJobConstants.WRITE_BACK_OPERATOR_UID);
}
 
Example #2
Source File: LongPipeline.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
@Override
public final LongStream flatMap(LongFunction<? extends LongStream> mapper) {
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(long t) {
                    try (LongStream result = mapper.apply(t)) {
                        // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                        if (result != null)
                            result.sequential().forEach(i -> downstream.accept(i));
                    }
                }
            };
        }
    };
}
 
Example #3
Source File: OrderedAsync.java    From incubator-ratis with Apache License 2.0 6 votes vote down vote up
CompletableFuture<RaftClientReply> send(RaftClientRequest.Type type, Message message, RaftPeerId server) {
  if (!type.is(TypeCase.WATCH) && !type.is(TypeCase.STREAM)) {
    Objects.requireNonNull(message, "message == null");
  }
  try {
    requestSemaphore.acquire();
  } catch (InterruptedException e) {
    return JavaUtils.completeExceptionally(IOUtils.toInterruptedIOException(
        "Interrupted when sending " + type + ", message=" + message, e));
  }

  final long callId = RaftClientImpl.nextCallId();
  final LongFunction<PendingOrderedRequest> constructor = seqNum -> new PendingOrderedRequest(callId, seqNum,
      slidingWindowEntry -> client.newRaftClientRequest(server, callId, message, type, slidingWindowEntry));
  return getSlidingWindow(server).submitNewRequest(constructor, this::sendRequestWithRetry
  ).getReplyFuture(
  ).thenApply(reply -> RaftClientImpl.handleRaftException(reply, CompletionException::new)
  ).whenComplete((r, e) -> requestSemaphore.release());
}
 
Example #4
Source File: OrcBatchReader.java    From flink with Apache License 2.0 6 votes vote down vote up
private static <T> void readNonNullLongColumn(Object[] vals, int fieldIdx, LongColumnVector vector,
												int childCount, LongFunction<T> reader) {

	if (vector.isRepeating) { // fill complete column with first value
		T repeatingValue = reader.apply(vector.vector[0]);
		fillColumnWithRepeatingValue(vals, fieldIdx, repeatingValue, childCount);
	} else {
		if (fieldIdx == -1) { // set as an object
			for (int i = 0; i < childCount; i++) {
				vals[i] = reader.apply(vector.vector[i]);
			}
		} else { // set as a field of Row
			Row[] rows = (Row[]) vals;
			for (int i = 0; i < childCount; i++) {
				rows[i].setField(fieldIdx, reader.apply(vector.vector[i]));
			}
		}
	}
}
 
Example #5
Source File: LongPipeline.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final LongStream flatMap(LongFunction<? extends LongStream> mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(long t) {
                    try (LongStream result = mapper.apply(t)) {
                        // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                        if (result != null)
                            result.sequential().forEach(i -> downstream.accept(i));
                    }
                }
            };
        }
    };
}
 
Example #6
Source File: OrcBatchReader.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private static <T> void readNonNullLongColumn(Object[] vals, int fieldIdx, LongColumnVector vector,
												int childCount, LongFunction<T> reader) {

	if (vector.isRepeating) { // fill complete column with first value
		T repeatingValue = reader.apply(vector.vector[0]);
		fillColumnWithRepeatingValue(vals, fieldIdx, repeatingValue, childCount);
	} else {
		if (fieldIdx == -1) { // set as an object
			for (int i = 0; i < childCount; i++) {
				vals[i] = reader.apply(vector.vector[i]);
			}
		} else { // set as a field of Row
			Row[] rows = (Row[]) vals;
			for (int i = 0; i < childCount; i++) {
				rows[i].setField(fieldIdx, reader.apply(vector.vector[i]));
			}
		}
	}
}
 
Example #7
Source File: LongPipeline.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final LongStream flatMap(LongFunction<? extends LongStream> mapper) {
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(long t) {
                    try (LongStream result = mapper.apply(t)) {
                        // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                        if (result != null)
                            result.sequential().forEach(i -> downstream.accept(i));
                    }
                }
            };
        }
    };
}
 
Example #8
Source File: LongPipeline.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final <U> Stream<U> mapToObj(LongFunction<? extends U> mapper) {
    Objects.requireNonNull(mapper);
    return new ReferencePipeline.StatelessOp<Long, U>(this, StreamShape.LONG_VALUE,
                                                      StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<U> sink) {
            return new Sink.ChainedLong<U>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.apply(t));
                }
            };
        }
    };
}
 
Example #9
Source File: BytesSSZReader.java    From incubator-tuweni with Apache License 2.0 6 votes vote down vote up
private <T> List<T> readFixedList(int listSize, LongFunction<byte[]> bytesSupplier, Function<byte[], T> converter) {
  int originalIndex = this.index;
  List<T> elements;
  try {
    elements = new ArrayList<>();
    while (listSize > 0) {
      byte[] bytes = bytesSupplier.apply(listSize);
      elements.add(converter.apply(bytes));
      // When lists have lengths passed in, the listSize argument is the number of
      // elements in the list, instead of the number of bytes in the list, so
      // we only subtract one each time an element is processed in this case.
      listSize -= 1;
      if (listSize < 0) {
        throw new InvalidSSZTypeException("SSZ encoded list length does not align with lengths of its elements");
      }
    }
  } catch (Exception e) {
    this.index = originalIndex;
    throw e;
  }
  return elements;
}
 
Example #10
Source File: IntegralPrimitiveToString.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public <N extends Number> N[] numberProvider(LongFunction<N> boxer, int bits, N... extras) {
    List<N> numbers = new ArrayList<>();

    for(int bitmag = 0; bitmag < bits; bitmag++) {
        long value = 1L << bitmag;
        numbers.add(boxer.apply(value));
        numbers.add(boxer.apply(value - 1));
        numbers.add(boxer.apply(value + 1));
        numbers.add(boxer.apply(-value));
        for(int divisor = 0; divisor < SOME_PRIMES.length && value < SOME_PRIMES[divisor]; divisor++) {
            numbers.add(boxer.apply(value - SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value + SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value * SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value / SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value | SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value & SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value ^ SOME_PRIMES[divisor]));
        }
    }

    numbers.addAll(Arrays.asList(extras));

    return (N[]) numbers.toArray(new Number[numbers.size()]);
}
 
Example #11
Source File: SlidingWindow.java    From incubator-ratis with Apache License 2.0 6 votes vote down vote up
/**
 * A new request arrives, create it with {@link #nextSeqNum}
 * and then try sending it to the server.
 *
 * @param requestConstructor use seqNum to create a new request.
 * @return the new request.
 */
public synchronized REQUEST submitNewRequest(
    LongFunction<REQUEST> requestConstructor, Consumer<REQUEST> sendMethod) {
  if (!requests.isEmpty()) {
    Preconditions.assertTrue(nextSeqNum == requests.lastSeqNum() + 1,
        () -> "nextSeqNum=" + nextSeqNum + " but " + this);
  }

  final long seqNum = nextSeqNum++;
  final REQUEST r = requestConstructor.apply(seqNum);

  if (exception != null) {
    alreadyClosed(r, exception);
    return r;
  }

  requests.putNewRequest(r);

  final boolean submitted = sendOrDelayRequest(r, sendMethod);
  LOG.debug("{}: submitting a new request {} in {}? {}",
      requests.getName(), r, this, submitted? "submitted": "delayed");
  return r;
}
 
Example #12
Source File: BytesSSZReader.java    From incubator-tuweni with Apache License 2.0 6 votes vote down vote up
private List<Bytes> readList(LongFunction<Bytes> bytesSupplier) {
  ensureBytes(4, () -> "SSZ encoded data is not a list");
  int originalIndex = this.index;
  List<Bytes> elements;
  try {
    // use a long to simulate reading unsigned
    long listSize = consumeBytes(4).toLong(LITTLE_ENDIAN);
    elements = new ArrayList<>();
    while (listSize > 0) {
      Bytes bytes = bytesSupplier.apply(listSize);
      elements.add(bytes);
      listSize -= bytes.size();
      listSize -= 4;
      if (listSize < 0) {
        throw new InvalidSSZTypeException("SSZ encoded list length does not align with lengths of its elements");
      }
    }
  } catch (Exception e) {
    this.index = originalIndex;
    throw e;
  }
  return elements;
}
 
Example #13
Source File: LongPipeline.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
@Override
public final <U> Stream<U> mapToObj(LongFunction<? extends U> mapper) {
    Objects.requireNonNull(mapper);
    return new ReferencePipeline.StatelessOp<Long, U>(this, StreamShape.LONG_VALUE,
                                                      StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<U> sink) {
            return new Sink.ChainedLong<U>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.apply(t));
                }
            };
        }
    };
}
 
Example #14
Source File: LongPipeline.java    From desugar_jdk_libs with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final LongStream flatMap(LongFunction<? extends LongStream> mapper) {
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(long t) {
                    try (LongStream result = mapper.apply(t)) {
                        // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                        if (result != null)
                            result.sequential().forEach(i -> downstream.accept(i));
                    }
                }
            };
        }
    };
}
 
Example #15
Source File: IntegralPrimitiveToString.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public <N extends Number> N[] numberProvider(LongFunction<N> boxer, int bits, N... extras) {
    List<N> numbers = new ArrayList<>();

    for(int bitmag = 0; bitmag < bits; bitmag++) {
        long value = 1L << bitmag;
        numbers.add(boxer.apply(value));
        numbers.add(boxer.apply(value - 1));
        numbers.add(boxer.apply(value + 1));
        numbers.add(boxer.apply(-value));
        for(int divisor = 0; divisor < SOME_PRIMES.length && value < SOME_PRIMES[divisor]; divisor++) {
            numbers.add(boxer.apply(value - SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value + SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value * SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value / SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value | SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value & SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value ^ SOME_PRIMES[divisor]));
        }
    }

    numbers.addAll(Arrays.asList(extras));

    return (N[]) numbers.toArray(new Number[numbers.size()]);
}
 
Example #16
Source File: LongPipeline.java    From desugar_jdk_libs with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final <U> Stream<U> mapToObj(LongFunction<? extends U> mapper) {
    Objects.requireNonNull(mapper);
    return new ReferencePipeline.StatelessOp<Long, U>(this, StreamShape.LONG_VALUE,
                                                      StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<U> sink) {
            return new Sink.ChainedLong<U>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.apply(t));
                }
            };
        }
    };
}
 
Example #17
Source File: IntegralPrimitiveToString.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public <N extends Number> N[] numberProvider(LongFunction<N> boxer, int bits, N... extras) {
    List<N> numbers = new ArrayList<>();

    for(int bitmag = 0; bitmag < bits; bitmag++) {
        long value = 1L << bitmag;
        numbers.add(boxer.apply(value));
        numbers.add(boxer.apply(value - 1));
        numbers.add(boxer.apply(value + 1));
        numbers.add(boxer.apply(-value));
        for(int divisor = 0; divisor < SOME_PRIMES.length && value < SOME_PRIMES[divisor]; divisor++) {
            numbers.add(boxer.apply(value - SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value + SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value * SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value / SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value | SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value & SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value ^ SOME_PRIMES[divisor]));
        }
    }

    numbers.addAll(Arrays.asList(extras));

    return (N[]) numbers.toArray(new Number[numbers.size()]);
}
 
Example #18
Source File: LongPipeline.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
@Override
public final LongStream flatMap(LongFunction<? extends LongStream> mapper) {
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(long t) {
                    try (LongStream result = mapper.apply(t)) {
                        // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                        if (result != null)
                            result.sequential().forEach(i -> downstream.accept(i));
                    }
                }
            };
        }
    };
}
 
Example #19
Source File: LongPipeline.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final <U> Stream<U> mapToObj(LongFunction<? extends U> mapper) {
    Objects.requireNonNull(mapper);
    return new ReferencePipeline.StatelessOp<Long, U>(this, StreamShape.LONG_VALUE,
                                                      StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<U> sink) {
            return new Sink.ChainedLong<U>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.apply(t));
                }
            };
        }
    };
}
 
Example #20
Source File: LongPipeline.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
@Override
public final <U> Stream<U> mapToObj(LongFunction<? extends U> mapper) {
    Objects.requireNonNull(mapper);
    return new ReferencePipeline.StatelessOp<Long, U>(this, StreamShape.LONG_VALUE,
                                                      StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<U> sink) {
            return new Sink.ChainedLong<U>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.apply(t));
                }
            };
        }
    };
}
 
Example #21
Source File: StorageIterators.java    From exonum-java-binding with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new iterator over an index.
 *
 * <p>The returned iterator is a {@link ConfigurableRustIter}
 * wrapped in a {@link RustIterAdapter}.
 *
 * @param nativeHandle nativeHandle of this iterator
 * @param nextFunction a function to call to get the next item
 * @param disposeOperation an operation to call to destroy the corresponding native iterator
 * @param collectionAccess a database access of the collection over which to iterate
 * @param modificationCounter a modification counter of the collection
 * @param transformingFunction a function to apply to elements returned by native iterator
 *                             (usually, to an array of bytes)
 */
static <ElementT, NativeT> Iterator<ElementT> createIterator(
    long nativeHandle,
    LongFunction<NativeT> nextFunction,
    LongConsumer disposeOperation,
    AbstractAccess collectionAccess,
    ModificationCounter modificationCounter,
    Function<? super NativeT, ? extends ElementT> transformingFunction) {

  // Register the destructor first.
  NativeHandle handle = new NativeHandle(nativeHandle);
  Cleaner cleaner = collectionAccess.getCleaner();
  cleaner.add(new ProxyDestructor(handle, RustIter.class, disposeOperation));

  Iterator<NativeT> iterator = new RustIterAdapter<>(
      new ConfigurableRustIter<>(
          handle,
          nextFunction,
          modificationCounter
      )
  );

  return Iterators.transform(iterator, transformingFunction::apply);
}
 
Example #22
Source File: BytesSSZReader.java    From cava with Apache License 2.0 6 votes vote down vote up
private <T> List<T> readList(LongFunction<byte[]> bytesSupplier, Function<byte[], T> converter) {
  ensureBytes(4, () -> "SSZ encoded data is not a list");
  int originalIndex = this.index;
  List<T> elements;
  try {
    // use a long to simulate reading unsigned
    long listSize = consumeBytes(4).toLong(LITTLE_ENDIAN);
    elements = new ArrayList<>();
    while (listSize > 0) {
      byte[] bytes = bytesSupplier.apply(listSize);
      elements.add(converter.apply(bytes));
      listSize -= bytes.length;
      listSize -= 4;
      if (listSize < 0) {
        throw new InvalidSSZTypeException("SSZ encoded list length does not align with lengths of its elements");
      }
    }
  } catch (Exception e) {
    this.index = originalIndex;
    throw e;
  }
  return elements;
}
 
Example #23
Source File: IntegralPrimitiveToString.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public <N extends Number> N[] numberProvider(LongFunction<N> boxer, int bits, N... extras) {
    List<N> numbers = new ArrayList<>();

    for(int bitmag = 0; bitmag < bits; bitmag++) {
        long value = 1L << bitmag;
        numbers.add(boxer.apply(value));
        numbers.add(boxer.apply(value - 1));
        numbers.add(boxer.apply(value + 1));
        numbers.add(boxer.apply(-value));
        for(int divisor = 0; divisor < SOME_PRIMES.length && value < SOME_PRIMES[divisor]; divisor++) {
            numbers.add(boxer.apply(value - SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value + SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value * SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value / SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value | SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value & SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value ^ SOME_PRIMES[divisor]));
        }
    }

    numbers.addAll(Arrays.asList(extras));

    return (N[]) numbers.toArray(new Number[numbers.size()]);
}
 
Example #24
Source File: IntegralPrimitiveToString.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public <N extends Number> N[] numberProvider(LongFunction<N> boxer, int bits, N... extras) {
    List<N> numbers = new ArrayList<>();

    for(int bitmag = 0; bitmag < bits; bitmag++) {
        long value = 1L << bitmag;
        numbers.add(boxer.apply(value));
        numbers.add(boxer.apply(value - 1));
        numbers.add(boxer.apply(value + 1));
        numbers.add(boxer.apply(-value));
        for(int divisor = 0; divisor < SOME_PRIMES.length && value < SOME_PRIMES[divisor]; divisor++) {
            numbers.add(boxer.apply(value - SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value + SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value * SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value / SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value | SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value & SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value ^ SOME_PRIMES[divisor]));
        }
    }

    numbers.addAll(Arrays.asList(extras));

    return (N[]) numbers.toArray(new Number[numbers.size()]);
}
 
Example #25
Source File: LongPipeline.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final <U> Stream<U> mapToObj(LongFunction<? extends U> mapper) {
    Objects.requireNonNull(mapper);
    return new ReferencePipeline.StatelessOp<Long, U>(this, StreamShape.LONG_VALUE,
                                                      StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<U> sink) {
            return new Sink.ChainedLong<U>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.apply(t));
                }
            };
        }
    };
}
 
Example #26
Source File: LongPipeline.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final LongStream flatMap(LongFunction<? extends LongStream> mapper) {
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(long t) {
                    try (LongStream result = mapper.apply(t)) {
                        // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                        if (result != null)
                            result.sequential().forEach(i -> downstream.accept(i));
                    }
                }
            };
        }
    };
}
 
Example #27
Source File: LongPipeline.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final <U> Stream<U> mapToObj(LongFunction<? extends U> mapper) {
    Objects.requireNonNull(mapper);
    return new ReferencePipeline.StatelessOp<Long, U>(this, StreamShape.LONG_VALUE,
                                                      StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<U> sink) {
            return new Sink.ChainedLong<U>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.apply(t));
                }
            };
        }
    };
}
 
Example #28
Source File: FlinkUniverse.java    From stateful-functions with Apache License 2.0 6 votes vote down vote up
private SingleOutputStreamOperator<Void> feedbackOperator(
    SingleOutputStreamOperator<Message> functionOut) {

  LongFunction<Message> toMessage = new CheckpointToMessage(universe.messageFactoryType());

  FeedbackSinkOperator<Message> sinkOperator =
      new FeedbackSinkOperator<>(FEEDBACK_KEY, toMessage);

  return functionOut
      .keyBy(new MessageKeySelector())
      .transform(
          StatefulFunctionsJobConstants.WRITE_BACK_OPERATOR_NAME,
          TypeInformation.of(Void.class),
          sinkOperator)
      .uid(StatefulFunctionsJobConstants.WRITE_BACK_OPERATOR_UID);
}
 
Example #29
Source File: ConfigurableRustIter.java    From exonum-java-binding with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new iterator over a collection (index).
 *
 * @param nativeHandle nativeHandle of this iterator
 * @param nextFunction a function to call to get the next item
 * @param modificationCounter a collection modification counter
 */
ConfigurableRustIter(NativeHandle nativeHandle,
                     LongFunction<E> nextFunction,
                     ModificationCounter modificationCounter) {
  super(nativeHandle);
  this.nextFunction = nextFunction;
  this.modificationCounter = modificationCounter;
  this.initialModCount = modificationCounter.getCurrentValue();
}
 
Example #30
Source File: Nodes.java    From desugar_jdk_libs with GNU General Public License v2.0 5 votes vote down vote up
CollectorTask(PipelineHelper<P_OUT> helper,
              Spliterator<P_IN> spliterator,
              LongFunction<T_BUILDER> builderFactory,
              BinaryOperator<T_NODE> concFactory) {
    super(helper, spliterator);
    this.helper = helper;
    this.builderFactory = builderFactory;
    this.concFactory = concFactory;
}