java.util.function.LongSupplier#getAsLong ( )源码实例Demo

下面列出了java.util.function.LongSupplier#getAsLong ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: incubator-ratis   文件: LeaderState.java
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;
}
 
源代码2 项目: IPAddress   文件: AddressDivisionGrouping.java
protected static void checkOverflow(
		long increment,
		long lowerValue,
		long upperValue,
		long count,
		LongSupplier maxValue
		) {
	if(increment < 0) {
		if(lowerValue < -increment) {
			throw new AddressValueException(increment);
		}
	} else {
		if(count > 1) {
			increment -= count - 1;
		}
		if(increment > maxValue.getAsLong() - upperValue) {
			throw new AddressValueException(increment);
		}
	}
}
 
源代码3 项目: hadoop-ozone   文件: AbstractSpaceUsageSource.java
/**
 * Measures execution time of {@code supplier#getAsLong} and logs it via the
 * given {@code logger}.
 * @return the same value as returned by {@code supplier#getAsLong}
 */
protected static long time(LongSupplier supplier, Logger logger) {
  long start = Time.monotonicNow();

  long result = supplier.getAsLong();

  long end = Time.monotonicNow();
  long elapsed = end - start;
  logger.debug("Completed check in {} ms, result: {}", elapsed, result);

  return result;
}
 
源代码4 项目: lucene-solr   文件: TestLucene80DocValuesFormat.java
private void doTestSparseNumericBlocksOfVariousBitsPerValue(double density) throws Exception {
  Directory dir = newDirectory();
  IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
  conf.setMaxBufferedDocs(atLeast(Lucene80DocValuesFormat.NUMERIC_BLOCK_SIZE));
  conf.setRAMBufferSizeMB(-1);
  conf.setMergePolicy(newLogMergePolicy(random().nextBoolean()));
  IndexWriter writer = new IndexWriter(dir, conf);
  Document doc = new Document();
  Field storedField = newStringField("stored", "", Field.Store.YES);
  Field dvField = new NumericDocValuesField("dv", 0);
  doc.add(storedField);
  doc.add(dvField);

  final int numDocs = atLeast(Lucene80DocValuesFormat.NUMERIC_BLOCK_SIZE*3);
  final LongSupplier longs = blocksOfVariousBPV();
  for (int i = 0; i < numDocs; i++) {
    if (random().nextDouble() > density) {
      writer.addDocument(new Document());
      continue;
    }
    long value = longs.getAsLong();
    storedField.setStringValue(Long.toString(value));
    dvField.setLongValue(value);
    writer.addDocument(doc);
  }

  writer.forceMerge(1);

  writer.close();
  
  // compare
  assertDVIterate(dir);
  assertDVAdvance(dir, 1); // Tests all jump-lengths from 1 to maxDoc (quite slow ~= 1 minute for 200K docs)

  dir.close();
}
 
源代码5 项目: micrometer   文件: TimeWindowMax.java
private void record(LongSupplier sampleSupplier) {
    rotate();
    long sample = sampleSupplier.getAsLong();
    for (AtomicLong max : ringBuffer) {
        updateMax(max, sample);
    }
}
 
源代码6 项目: ditto   文件: AbstractCommandSizeValidator.java
/**
 * Guard function that throws when a size limit is specified, and the given size supplier returns a size
 * greater than the limit.
 *
 * @param sizeSupplier the length calc function (only called when limit is present)
 * @param headersSupplier the headersSupplier for the exception
 * @throws T if size limit is set and exceeded
 */
public void ensureValidSize(final LongSupplier sizeSupplier, final Supplier<DittoHeaders> headersSupplier) {
    if (null != maxSize) {
        long actualSize = sizeSupplier.getAsLong();
        if (maxSize < actualSize) {
            throw newInvalidSizeException(maxSize, actualSize, headersSupplier.get());
        }
    }
}
 
源代码7 项目: lucene-solr   文件: TestLucene80DocValuesFormat.java
private void doTestSortedNumericBlocksOfVariousBitsPerValue(LongSupplier counts) throws Exception {
  Directory dir = newDirectory();
  IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
  conf.setMaxBufferedDocs(atLeast(Lucene80DocValuesFormat.NUMERIC_BLOCK_SIZE));
  conf.setRAMBufferSizeMB(-1);
  conf.setMergePolicy(newLogMergePolicy(random().nextBoolean()));
  IndexWriter writer = new IndexWriter(dir, conf);
  
  final int numDocs = atLeast(Lucene80DocValuesFormat.NUMERIC_BLOCK_SIZE*3);
  final LongSupplier values = blocksOfVariousBPV();
  for (int i = 0; i < numDocs; i++) {
    Document doc = new Document();
    
    int valueCount = (int) counts.getAsLong();
    long valueArray[] = new long[valueCount];
    for (int j = 0; j < valueCount; j++) {
      long value = values.getAsLong();
      valueArray[j] = value;
      doc.add(new SortedNumericDocValuesField("dv", value));
    }
    Arrays.sort(valueArray);
    for (int j = 0; j < valueCount; j++) {
      doc.add(new StoredField("stored", Long.toString(valueArray[j])));
    }
    writer.addDocument(doc);
    if (random().nextInt(31) == 0) {
      writer.commit();
    }
  }
  writer.forceMerge(1);

  writer.close();
  
  // compare
  DirectoryReader ir = DirectoryReader.open(dir);
  TestUtil.checkReader(ir);
  for (LeafReaderContext context : ir.leaves()) {
    LeafReader r = context.reader();
    SortedNumericDocValues docValues = DocValues.getSortedNumeric(r, "dv");
    for (int i = 0; i < r.maxDoc(); i++) {
      if (i > docValues.docID()) {
        docValues.nextDoc();
      }
      String expected[] = r.document(i).getValues("stored");
      if (i < docValues.docID()) {
        assertEquals(0, expected.length);
      } else {
        String actual[] = new String[docValues.docValueCount()];
        for (int j = 0; j < actual.length; j++) {
          actual[j] = Long.toString(docValues.nextValue());
        }
        assertArrayEquals(expected, actual);
      }
    }
  }
  ir.close();
  dir.close();
}
 
源代码8 项目: night-config   文件: UnmodifiableConfig.java
/**
 * Like {@link #getOrElse(String[], Supplier)} but returns a primitive long.
 * The config's value must be a {@link Number} or null or nonexistant.
 */
default long getLongOrElse(String[] path, LongSupplier defaultValueSupplier) {
	Number n = get(path);
	return (n == null) ? defaultValueSupplier.getAsLong() : n.longValue();
}
 
源代码9 项目: ProjectAres   文件: DynamicLambdaTest.java
public void testPromoteReturnType() throws Exception {
    class C { int woot() { return 123; } }
    final LongSupplier lambda = Methods.lambda(LongSupplier.class, C.class.getDeclaredMethod("woot"), new C());
    lambda.getAsLong();
}
 
源代码10 项目: incubator-tuweni   文件: TomlTable.java
/**
 * Get a long from the TOML document, or return a default.
 *
 * @param path The key path.
 * @param defaultValue A supplier for the default value.
 * @return The value, or the default.
 * @throws TomlInvalidTypeException If the value is present but not a long, or any element of the path preceding the
 *         final key is not a table.
 */
default long getLong(List<String> path, LongSupplier defaultValue) {
  requireNonNull(defaultValue);
  Long value = getLong(path);
  if (value != null) {
    return value;
  }
  return defaultValue.getAsLong();
}
 
源代码11 项目: cava   文件: TomlTable.java
/**
 * Get a long from the TOML document, or return a default.
 *
 * @param path The key path.
 * @param defaultValue A supplier for the default value.
 * @return The value, or the default.
 * @throws TomlInvalidTypeException If the value is present but not a long, or any element of the path preceding the
 *         final key is not a table.
 */
default long getLong(List<String> path, LongSupplier defaultValue) {
  requireNonNull(defaultValue);
  Long value = getLong(path);
  if (value != null) {
    return value;
  }
  return defaultValue.getAsLong();
}
 
源代码12 项目: dragonwell8_jdk   文件: OptionalLong.java
/**
 * Return the value if present, otherwise invoke {@code other} and return
 * the result of that invocation.
 *
 * @param other a {@code LongSupplier} whose result is returned if no value
 * is present
 * @return the value if present otherwise the result of {@code other.getAsLong()}
 * @throws NullPointerException if value is not present and {@code other} is
 * null
 */
public long orElseGet(LongSupplier other) {
    return isPresent ? value : other.getAsLong();
}
 
源代码13 项目: TencentKona-8   文件: OptionalLong.java
/**
 * Return the value if present, otherwise invoke {@code other} and return
 * the result of that invocation.
 *
 * @param other a {@code LongSupplier} whose result is returned if no value
 * is present
 * @return the value if present otherwise the result of {@code other.getAsLong()}
 * @throws NullPointerException if value is not present and {@code other} is
 * null
 */
public long orElseGet(LongSupplier other) {
    return isPresent ? value : other.getAsLong();
}
 
源代码14 项目: Java8CN   文件: OptionalLong.java
/**
 * Return the value if present, otherwise invoke {@code other} and return
 * the result of that invocation.
 *
 * @param other a {@code LongSupplier} whose result is returned if no value
 * is present
 * @return the value if present otherwise the result of {@code other.getAsLong()}
 * @throws NullPointerException if value is not present and {@code other} is
 * null
 */
public long orElseGet(LongSupplier other) {
    return isPresent ? value : other.getAsLong();
}
 
源代码15 项目: JDKSourceCode1.8   文件: OptionalLong.java
/**
 * Return the value if present, otherwise invoke {@code other} and return
 * the result of that invocation.
 *
 * @param other a {@code LongSupplier} whose result is returned if no value
 * is present
 * @return the value if present otherwise the result of {@code other.getAsLong()}
 * @throws NullPointerException if value is not present and {@code other} is
 * null
 */
public long orElseGet(LongSupplier other) {
    return isPresent ? value : other.getAsLong();
}
 
源代码16 项目: desugar_jdk_libs   文件: OptionalLong.java
/**
 * Return the value if present, otherwise invoke {@code other} and return
 * the result of that invocation.
 *
 * @param other a {@code LongSupplier} whose result is returned if no value
 * is present
 * @return the value if present otherwise the result of {@code other.getAsLong()}
 * @throws NullPointerException if value is not present and {@code other} is
 * null
 */
public long orElseGet(LongSupplier other) {
    return isPresent ? value : other.getAsLong();
}
 
源代码17 项目: openjdk-8   文件: OptionalLong.java
/**
 * Return the value if present, otherwise invoke {@code other} and return
 * the result of that invocation.
 *
 * @param other a {@code LongSupplier} whose result is returned if no value
 * is present
 * @return the value if present otherwise the result of {@code other.getAsLong()}
 * @throws NullPointerException if value is not present and {@code other} is
 * null
 */
public long orElseGet(LongSupplier other) {
    return isPresent ? value : other.getAsLong();
}
 
源代码18 项目: openjdk-jdk9   文件: OptionalLong.java
/**
 * If a value is present, returns the value, otherwise returns the result
 * produced by the supplying function.
 *
 * @param supplier the supplying function that produces a value to be returned
 * @return the value, if present, otherwise the result produced by the
 *         supplying function
 * @throws NullPointerException if no value is present and the supplying
 *         function is {@code null}
 */
public long orElseGet(LongSupplier supplier) {
    return isPresent ? value : supplier.getAsLong();
}
 
源代码19 项目: jdk8u-jdk   文件: OptionalLong.java
/**
 * Return the value if present, otherwise invoke {@code other} and return
 * the result of that invocation.
 *
 * @param other a {@code LongSupplier} whose result is returned if no value
 * is present
 * @return the value if present otherwise the result of {@code other.getAsLong()}
 * @throws NullPointerException if value is not present and {@code other} is
 * null
 */
public long orElseGet(LongSupplier other) {
    return isPresent ? value : other.getAsLong();
}
 
源代码20 项目: ditto   文件: AbstractCommandSizeValidator.java
/**
 * Guard function that throws when a size limit is specified, and the given size supplier returns a size
 * greater than the limit.
 * Only calls the sizeSupplier, if the upper bound provided by the upperBoundSupplier exceeds the limit.
 *
 * @param upperBoundSupplier a calculation function that returns an upper bound for the size
 * (possibly {@link Long#MAX_VALUE})
 * @param sizeSupplier the length calc function (only called when limit is present)
 * @param headersSupplier the headersSupplier for the exception
 * @throws T if size limit is set and exceeded
 * @since 1.1.0
 */
public void ensureValidSize(final LongSupplier upperBoundSupplier, final LongSupplier sizeSupplier, final Supplier<DittoHeaders> headersSupplier) {
    if (null != maxSize && upperBoundSupplier.getAsLong() >= maxSize) {
        ensureValidSize(sizeSupplier, headersSupplier);
    }
}
 
 同类方法