Java Code Examples for java.util.function.ToLongFunction#applyAsLong()

The following examples show how to use java.util.function.ToLongFunction#applyAsLong() . 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: LeaderState.java    From incubator-ratis with Apache License 2.0 6 votes vote down vote up
private long[] getSorted(List<RaftPeerId> followerIDs, boolean includeSelf,
    ToLongFunction<FollowerInfo> getFollowerIndex, LongSupplier getLogIndex) {
  final int length = includeSelf ? followerIDs.size() + 1 : followerIDs.size();
  if (length == 0) {
    throw new IllegalArgumentException("followers.size() == "
        + followerIDs.size() + " and includeSelf == " + includeSelf);
  }

  final long[] indices = new long[length];
  List<FollowerInfo> followerInfos = getFollowerInfos(followerIDs);
  for (int i = 0; i < followerInfos.size(); i++) {
    indices[i] = getFollowerIndex.applyAsLong(followerInfos.get(i));
  }

  if (includeSelf) {
    // note that we also need to wait for the local disk I/O
    indices[length - 1] = getLogIndex.getAsLong();
  }

  Arrays.sort(indices);
  return indices;
}
 
Example 2
Source File: DefaultCardinalityEstimator.java    From rheem with Apache License 2.0 5 votes vote down vote up
public DefaultCardinalityEstimator(double certaintyProb,
                                   int numInputs,
                                   boolean isAllowMoreInputs,
                                   ToLongFunction<long[]> singlePointEstimator) {
    this(certaintyProb,
            numInputs,
            isAllowMoreInputs,
            (inputCards, rheemContext) -> singlePointEstimator.applyAsLong(inputCards));
}
 
Example 3
Source File: Collectors.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * Returns a {@code Collector} that produces the arithmetic mean of a long-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be summed
 * @return a {@code Collector} that produces the sum of a derived property
 */
public static <T> Collector<T, ?, Double>
averagingLong(ToLongFunction<? super T> mapper) {
    return new CollectorImpl<>(
            () -> new long[2],
            (a, t) -> { a[0] += mapper.applyAsLong(t); a[1]++; },
            (a, b) -> { a[0] += b[0]; a[1] += b[1]; return a; },
            a -> (a[1] == 0) ? 0.0d : (double) a[0] / a[1], CH_NOID);
}
 
Example 4
Source File: Collectors.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a {@code Collector} that produces the sum of a long-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be summed
 * @return a {@code Collector} that produces the sum of a derived property
 */
public static <T> Collector<T, ?, Long>
summingLong(ToLongFunction<? super T> mapper) {
    return new CollectorImpl<>(
            () -> new long[1],
            (a, t) -> { a[0] += mapper.applyAsLong(t); },
            (a, b) -> { a[0] += b[0]; return a; },
            a -> a[0], CH_NOID);
}
 
Example 5
Source File: Collectors.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a {@code Collector} that produces the arithmetic mean of a long-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be averaged
 * @return a {@code Collector} that produces the arithmetic mean of a
 * derived property
 */
public static <T> Collector<T, ?, Double>
averagingLong(ToLongFunction<? super T> mapper) {
    return new CollectorImpl<>(
            () -> new long[2],
            (a, t) -> { a[0] += mapper.applyAsLong(t); a[1]++; },
            (a, b) -> { a[0] += b[0]; a[1] += b[1]; return a; },
            a -> (a[1] == 0) ? 0.0d : (double) a[0] / a[1], CH_NOID);
}
 
Example 6
Source File: Collectors.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a {@code Collector} that produces the sum of a long-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be summed
 * @return a {@code Collector} that produces the sum of a derived property
 */
public static <T> Collector<T, ?, Long>
summingLong(ToLongFunction<? super T> mapper) {
    return new CollectorImpl<>(
            () -> new long[1],
            (a, t) -> { a[0] += mapper.applyAsLong(t); },
            (a, b) -> { a[0] += b[0]; return a; },
            a -> a[0], CH_NOID);
}
 
Example 7
Source File: Collectors.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a {@code Collector} that produces the arithmetic mean of a long-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be summed
 * @return a {@code Collector} that produces the sum of a derived property
 */
public static <T> Collector<T, ?, Double>
averagingLong(ToLongFunction<? super T> mapper) {
    return new CollectorImpl<>(
            () -> new long[2],
            (a, t) -> { a[0] += mapper.applyAsLong(t); a[1]++; },
            (a, b) -> { a[0] += b[0]; a[1] += b[1]; return a; },
            a -> (a[1] == 0) ? 0.0d : (double) a[0] / a[1], CH_NOID);
}
 
Example 8
Source File: Collectors.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a {@code Collector} that produces the sum of a long-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be summed
 * @return a {@code Collector} that produces the sum of a derived property
 */
public static <T> Collector<T, ?, Long>
summingLong(ToLongFunction<? super T> mapper) {
    return new CollectorImpl<>(
            () -> new long[1],
            (a, t) -> { a[0] += mapper.applyAsLong(t); },
            (a, b) -> { a[0] += b[0]; return a; },
            a -> a[0], CH_NOID);
}
 
Example 9
Source File: Collectors.java    From desugar_jdk_libs with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a {@code Collector} that produces the arithmetic mean of a long-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be summed
 * @return a {@code Collector} that produces the sum of a derived property
 */
public static <T> Collector<T, ?, Double>
averagingLong(ToLongFunction<? super T> mapper) {
    return new CollectorImpl<>(
            () -> new long[2],
            (a, t) -> { a[0] += mapper.applyAsLong(t); a[1]++; },
            (a, b) -> { a[0] += b[0]; a[1] += b[1]; return a; },
            a -> (a[1] == 0) ? 0.0d : (double) a[0] / a[1], CH_NOID);
}
 
Example 10
Source File: Collectors.java    From desugar_jdk_libs with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a {@code Collector} that produces the sum of a long-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be summed
 * @return a {@code Collector} that produces the sum of a derived property
 */
public static <T> Collector<T, ?, Long>
summingLong(ToLongFunction<? super T> mapper) {
    return new CollectorImpl<>(
            () -> new long[1],
            (a, t) -> { a[0] += mapper.applyAsLong(t); },
            (a, b) -> { a[0] += b[0]; return a; },
            a -> a[0], CH_NOID);
}
 
Example 11
Source File: Collectors.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a {@code Collector} that produces the arithmetic mean of a long-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be summed
 * @return a {@code Collector} that produces the sum of a derived property
 */
public static <T> Collector<T, ?, Double>
averagingLong(ToLongFunction<? super T> mapper) {
    return new CollectorImpl<>(
            () -> new long[2],
            (a, t) -> { a[0] += mapper.applyAsLong(t); a[1]++; },
            (a, b) -> { a[0] += b[0]; a[1] += b[1]; return a; },
            a -> (a[1] == 0) ? 0.0d : (double) a[0] / a[1], CH_NOID);
}
 
Example 12
Source File: Collectors.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * Returns a {@code Collector} that produces the sum of a long-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be summed
 * @return a {@code Collector} that produces the sum of a derived property
 */
public static <T> Collector<T, ?, Long>
summingLong(ToLongFunction<? super T> mapper) {
    return new CollectorImpl<>(
            () -> new long[1],
            (a, t) -> { a[0] += mapper.applyAsLong(t); },
            (a, b) -> { a[0] += b[0]; return a; },
            a -> a[0], CH_NOID);
}
 
Example 13
Source File: Collectors.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a {@code Collector} that produces the arithmetic mean of a long-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be summed
 * @return a {@code Collector} that produces the sum of a derived property
 */
public static <T> Collector<T, ?, Double>
averagingLong(ToLongFunction<? super T> mapper) {
    return new CollectorImpl<>(
            () -> new long[2],
            (a, t) -> { a[0] += mapper.applyAsLong(t); a[1]++; },
            (a, b) -> { a[0] += b[0]; a[1] += b[1]; return a; },
            a -> (a[1] == 0) ? 0.0d : (double) a[0] / a[1], CH_NOID);
}
 
Example 14
Source File: Collectors.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a {@code Collector} that produces the sum of a long-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be summed
 * @return a {@code Collector} that produces the sum of a derived property
 */
public static <T> Collector<T, ?, Long>
summingLong(ToLongFunction<? super T> mapper) {
    return new CollectorImpl<>(
            () -> new long[1],
            (a, t) -> { a[0] += mapper.applyAsLong(t); },
            (a, b) -> { a[0] += b[0]; return a; },
            a -> a[0], CH_NOID);
}
 
Example 15
Source File: Collectors.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a {@code Collector} that produces the sum of a long-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be summed
 * @return a {@code Collector} that produces the sum of a derived property
 */
public static <T> Collector<T, ?, Long>
summingLong(ToLongFunction<? super T> mapper) {
    return new CollectorImpl<>(
            () -> new long[1],
            (a, t) -> { a[0] += mapper.applyAsLong(t); },
            (a, b) -> { a[0] += b[0]; return a; },
            a -> a[0], CH_NOID);
}
 
Example 16
Source File: Collectors.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a {@code Collector} that produces the sum of a long-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be summed
 * @return a {@code Collector} that produces the sum of a derived property
 */
public static <T> Collector<T, ?, Long>
summingLong(ToLongFunction<? super T> mapper) {
    return new CollectorImpl<>(
            () -> new long[1],
            (a, t) -> { a[0] += mapper.applyAsLong(t); },
            (a, b) -> { a[0] += b[0]; return a; },
            a -> a[0], CH_NOID);
}
 
Example 17
Source File: Collectors.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a {@code Collector} that produces the arithmetic mean of a long-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be summed
 * @return a {@code Collector} that produces the sum of a derived property
 */
public static <T> Collector<T, ?, Double>
averagingLong(ToLongFunction<? super T> mapper) {
    return new CollectorImpl<>(
            () -> new long[2],
            (a, t) -> { a[0] += mapper.applyAsLong(t); a[1]++; },
            (a, b) -> { a[0] += b[0]; a[1] += b[1]; return a; },
            a -> (a[1] == 0) ? 0.0d : (double) a[0] / a[1], CH_NOID);
}
 
Example 18
Source File: Collectors.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a {@code Collector} that produces the arithmetic mean of a long-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be averaged
 * @return a {@code Collector} that produces the arithmetic mean of a
 * derived property
 */
public static <T> Collector<T, ?, Double>
averagingLong(ToLongFunction<? super T> mapper) {
    return new CollectorImpl<>(
            () -> new long[2],
            (a, t) -> { a[0] += mapper.applyAsLong(t); a[1]++; },
            (a, b) -> { a[0] += b[0]; a[1] += b[1]; return a; },
            a -> (a[1] == 0) ? 0.0d : (double) a[0] / a[1], CH_NOID);
}
 
Example 19
Source File: Collectors.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a {@code Collector} that produces the arithmetic mean of a long-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be summed
 * @return a {@code Collector} that produces the sum of a derived property
 */
public static <T> Collector<T, ?, Double>
averagingLong(ToLongFunction<? super T> mapper) {
    return new CollectorImpl<>(
            () -> new long[2],
            (a, t) -> { a[0] += mapper.applyAsLong(t); a[1]++; },
            (a, b) -> { a[0] += b[0]; a[1] += b[1]; return a; },
            a -> (a[1] == 0) ? 0.0d : (double) a[0] / a[1], CH_NOID);
}
 
Example 20
Source File: Collectors.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a {@code Collector} that produces the sum of a long-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be summed
 * @return a {@code Collector} that produces the sum of a derived property
 */
public static <T> Collector<T, ?, Long>
summingLong(ToLongFunction<? super T> mapper) {
    return new CollectorImpl<>(
            () -> new long[1],
            (a, t) -> { a[0] += mapper.applyAsLong(t); },
            (a, b) -> { a[0] += b[0]; return a; },
            a -> a[0], CH_NOID);
}