java.lang.Math.toIntExact()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(508)

本文整理了Java中java.lang.Math.toIntExact()方法的一些代码示例,展示了Math.toIntExact()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Math.toIntExact()方法的具体详情如下:
包路径:java.lang.Math
类名称:Math
方法名:toIntExact

Math.toIntExact介绍

暂无

代码示例

代码示例来源:origin: prestodb/presto

  1. private static int preceding(int rowPosition, long value)
  2. {
  3. if (value > rowPosition) {
  4. return 0;
  5. }
  6. return toIntExact(rowPosition - value);
  7. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public int size()
  3. {
  4. return toIntExact(bufferOffset + bufferPosition);
  5. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public int getValueLength(Slice slice, int offset)
  3. {
  4. return toIntExact(readVInt(slice, offset));
  5. }

代码示例来源:origin: prestodb/presto

  1. public int getFullGcCount()
  2. {
  3. long startFullGcCount = this.startFullGcCount.get();
  4. if (startFullGcCount < 0) {
  5. return 0;
  6. }
  7. long endFullGcCount = this.endFullGcCount.get();
  8. if (endFullGcCount <= 0) {
  9. endFullGcCount = gcMonitor.getMajorGcCount();
  10. }
  11. return toIntExact(max(0, endFullGcCount - startFullGcCount));
  12. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void setPosition(long position)
  3. {
  4. if (delegate == null) {
  5. if (position < 0 || position > globalLength) {
  6. throw new IndexOutOfBoundsException("Invalid position " + position + " for slice with length " + globalLength);
  7. }
  8. initialPosition = toIntExact(position);
  9. return;
  10. }
  11. delegate.setPosition(position);
  12. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void writeLong(BlockBuilder blockBuilder, long value)
  3. {
  4. try {
  5. toIntExact(value);
  6. }
  7. catch (ArithmeticException e) {
  8. throw new PrestoException(GENERIC_INTERNAL_ERROR, format("Value (%sb) is not a valid single-precision float", Long.toBinaryString(value).replace(' ', '0')));
  9. }
  10. blockBuilder.writeInt((int) value).closeEntry();
  11. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public int hashCode(Object value)
  3. {
  4. try {
  5. return toIntExact(Long.hashCode((long) hashCodeHandle.invokeExact(value)));
  6. }
  7. catch (Throwable t) {
  8. throwIfInstanceOf(t, Error.class);
  9. throwIfInstanceOf(t, PrestoException.class);
  10. throw new PrestoException(GENERIC_INTERNAL_ERROR, t);
  11. }
  12. }

代码示例来源:origin: prestodb/presto

  1. public long getCheckpoint()
  2. {
  3. // if the decompressed buffer is empty, return a checkpoint starting at the next block
  4. if (current == null || (current.position() == 0 && current.remaining() == 0)) {
  5. return createInputStreamCheckpoint(toIntExact(compressedSliceInput.position()), 0);
  6. }
  7. // otherwise return a checkpoint at the last compressed block read and the current position in the buffer
  8. return createInputStreamCheckpoint(currentCompressedBlockOffset, toIntExact(current.position()));
  9. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public SqlIntervalYearMonth getExpectedValue(int start, int length)
  3. {
  4. if (length == 0) {
  5. return null;
  6. }
  7. double sum = 0;
  8. for (int i = start; i < start + length; i++) {
  9. sum += i;
  10. }
  11. return new SqlIntervalYearMonth(toIntExact(round(sum / length)));
  12. }

代码示例来源:origin: prestodb/presto

  1. @Description("Creates a Bing tile from XY coordinates and zoom level")
  2. @ScalarFunction("bing_tile")
  3. @SqlType(BingTileType.NAME)
  4. public static long toBingTile(@SqlType(StandardTypes.INTEGER) long tileX, @SqlType(StandardTypes.INTEGER) long tileY, @SqlType(StandardTypes.INTEGER) long zoomLevel)
  5. {
  6. checkZoomLevel(zoomLevel);
  7. checkCoordinate(tileX, zoomLevel);
  8. checkCoordinate(tileY, zoomLevel);
  9. return BingTile.fromCoordinates(toIntExact(tileX), toIntExact(tileY), toIntExact(zoomLevel)).encode();
  10. }

代码示例来源:origin: prestodb/presto

  1. @UsedByGeneratedCode
  2. public static Object objectSubscript(Type elementType, Block array, long index)
  3. {
  4. checkIndex(array, index);
  5. int position = toIntExact(index - 1);
  6. if (array.isNull(position)) {
  7. return null;
  8. }
  9. return elementType.getObject(array, position);
  10. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public long getNextJoinPosition(long currentJoinPosition, int probePosition, Page allProbeChannelsPage)
  3. {
  4. int partition = decodePartition(currentJoinPosition);
  5. long joinPosition = decodeJoinPosition(currentJoinPosition);
  6. LookupSource lookupSource = lookupSources[partition];
  7. long nextJoinPosition = lookupSource.getNextJoinPosition(joinPosition, probePosition, allProbeChannelsPage);
  8. if (nextJoinPosition < 0) {
  9. return nextJoinPosition;
  10. }
  11. return encodePartitionedJoinPosition(partition, toIntExact(nextJoinPosition));
  12. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public StreamDataOutput getStreamDataOutput(int column)
  3. {
  4. return new StreamDataOutput(buffer::writeDataTo, new Stream(column, streamKind, toIntExact(buffer.getOutputDataSize()), true));
  5. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public StreamDataOutput getStreamDataOutput(int column)
  3. {
  4. return new StreamDataOutput(buffer::writeDataTo, new Stream(column, DATA, toIntExact(buffer.getOutputDataSize()), false));
  5. }

代码示例来源:origin: prestodb/presto

  1. private static Block fixedWidthSequence(long start, long stop, long step, FixedWidthType type)
  2. {
  3. checkValidStep(start, stop, step);
  4. int length = toIntExact((stop - start) / step + 1L);
  5. checkMaxEntry(length);
  6. BlockBuilder blockBuilder = type.createBlockBuilder(null, length);
  7. for (long i = 0, value = start; i < length; ++i, value += step) {
  8. type.writeLong(blockBuilder, value);
  9. }
  10. return blockBuilder.build();
  11. }

代码示例来源:origin: prestodb/presto

  1. private Slice getSliceOutput()
  2. {
  3. buffer.close();
  4. DynamicSliceOutput output = new DynamicSliceOutput(toIntExact(buffer.getOutputDataSize()));
  5. buffer.writeDataTo(output);
  6. Slice slice = output.slice();
  7. buffer.reset();
  8. return slice;
  9. }
  10. }

代码示例来源:origin: prestodb/presto

  1. @ScalarOperator(CAST)
  2. @LiteralParameters("x")
  3. @SqlType("varchar(x)")
  4. public static Slice castToSlice(@SqlType(StandardTypes.INTERVAL_YEAR_TO_MONTH) long value)
  5. {
  6. return utf8Slice(IntervalYearMonth.formatMonths(toIntExact(value)));
  7. }

代码示例来源:origin: prestodb/presto

  1. private static SerializedPage readSerializedPage(SliceInput sliceInput)
  2. {
  3. int positionCount = sliceInput.readInt();
  4. byte codecMarker = sliceInput.readByte();
  5. int uncompressedSizeInBytes = sliceInput.readInt();
  6. int sizeInBytes = sliceInput.readInt();
  7. Slice slice = sliceInput.readSlice(toIntExact((sizeInBytes)));
  8. return new SerializedPage(slice, lookupCodecFromMarker(codecMarker), positionCount, uncompressedSizeInBytes);
  9. }

代码示例来源:origin: prestodb/presto

  1. @Description("add the specified amount of time to the given time")
  2. @LiteralParameters("x")
  3. @ScalarFunction("date_add")
  4. @SqlType(StandardTypes.TIME)
  5. public static long addFieldValueTime(ConnectorSession session, @SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.TIME) long time)
  6. {
  7. if (session.isLegacyTimestamp()) {
  8. ISOChronology chronology = getChronology(session.getTimeZoneKey());
  9. return modulo24Hour(chronology, getTimeField(chronology, unit).add(time, toIntExact(value)));
  10. }
  11. return modulo24Hour(getTimeField(UTC_CHRONOLOGY, unit).add(time, toIntExact(value)));
  12. }

代码示例来源:origin: prestodb/presto

  1. @Description("add the specified amount of time to the given timestamp")
  2. @LiteralParameters("x")
  3. @ScalarFunction("date_add")
  4. @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE)
  5. public static long addFieldValueTimestampWithTimeZone(
  6. @SqlType("varchar(x)") Slice unit,
  7. @SqlType(StandardTypes.BIGINT) long value,
  8. @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long timestampWithTimeZone)
  9. {
  10. long millis = getTimestampField(unpackChronology(timestampWithTimeZone), unit).add(unpackMillisUtc(timestampWithTimeZone), toIntExact(value));
  11. return updateMillisUtc(millis, timestampWithTimeZone);
  12. }

相关文章