本文整理了Java中java.lang.Math.toIntExact()
方法的一些代码示例,展示了Math.toIntExact()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Math.toIntExact()
方法的具体详情如下:
包路径:java.lang.Math
类名称:Math
方法名:toIntExact
暂无
代码示例来源:origin: prestodb/presto
private static int preceding(int rowPosition, long value)
{
if (value > rowPosition) {
return 0;
}
return toIntExact(rowPosition - value);
}
代码示例来源:origin: prestodb/presto
@Override
public int size()
{
return toIntExact(bufferOffset + bufferPosition);
}
代码示例来源:origin: prestodb/presto
@Override
public int getValueLength(Slice slice, int offset)
{
return toIntExact(readVInt(slice, offset));
}
代码示例来源:origin: prestodb/presto
public int getFullGcCount()
{
long startFullGcCount = this.startFullGcCount.get();
if (startFullGcCount < 0) {
return 0;
}
long endFullGcCount = this.endFullGcCount.get();
if (endFullGcCount <= 0) {
endFullGcCount = gcMonitor.getMajorGcCount();
}
return toIntExact(max(0, endFullGcCount - startFullGcCount));
}
代码示例来源:origin: prestodb/presto
@Override
public void setPosition(long position)
{
if (delegate == null) {
if (position < 0 || position > globalLength) {
throw new IndexOutOfBoundsException("Invalid position " + position + " for slice with length " + globalLength);
}
initialPosition = toIntExact(position);
return;
}
delegate.setPosition(position);
}
代码示例来源:origin: prestodb/presto
@Override
public void writeLong(BlockBuilder blockBuilder, long value)
{
try {
toIntExact(value);
}
catch (ArithmeticException e) {
throw new PrestoException(GENERIC_INTERNAL_ERROR, format("Value (%sb) is not a valid single-precision float", Long.toBinaryString(value).replace(' ', '0')));
}
blockBuilder.writeInt((int) value).closeEntry();
}
代码示例来源:origin: prestodb/presto
@Override
public int hashCode(Object value)
{
try {
return toIntExact(Long.hashCode((long) hashCodeHandle.invokeExact(value)));
}
catch (Throwable t) {
throwIfInstanceOf(t, Error.class);
throwIfInstanceOf(t, PrestoException.class);
throw new PrestoException(GENERIC_INTERNAL_ERROR, t);
}
}
代码示例来源:origin: prestodb/presto
public long getCheckpoint()
{
// if the decompressed buffer is empty, return a checkpoint starting at the next block
if (current == null || (current.position() == 0 && current.remaining() == 0)) {
return createInputStreamCheckpoint(toIntExact(compressedSliceInput.position()), 0);
}
// otherwise return a checkpoint at the last compressed block read and the current position in the buffer
return createInputStreamCheckpoint(currentCompressedBlockOffset, toIntExact(current.position()));
}
代码示例来源:origin: prestodb/presto
@Override
public SqlIntervalYearMonth getExpectedValue(int start, int length)
{
if (length == 0) {
return null;
}
double sum = 0;
for (int i = start; i < start + length; i++) {
sum += i;
}
return new SqlIntervalYearMonth(toIntExact(round(sum / length)));
}
代码示例来源:origin: prestodb/presto
@Description("Creates a Bing tile from XY coordinates and zoom level")
@ScalarFunction("bing_tile")
@SqlType(BingTileType.NAME)
public static long toBingTile(@SqlType(StandardTypes.INTEGER) long tileX, @SqlType(StandardTypes.INTEGER) long tileY, @SqlType(StandardTypes.INTEGER) long zoomLevel)
{
checkZoomLevel(zoomLevel);
checkCoordinate(tileX, zoomLevel);
checkCoordinate(tileY, zoomLevel);
return BingTile.fromCoordinates(toIntExact(tileX), toIntExact(tileY), toIntExact(zoomLevel)).encode();
}
代码示例来源:origin: prestodb/presto
@UsedByGeneratedCode
public static Object objectSubscript(Type elementType, Block array, long index)
{
checkIndex(array, index);
int position = toIntExact(index - 1);
if (array.isNull(position)) {
return null;
}
return elementType.getObject(array, position);
}
代码示例来源:origin: prestodb/presto
@Override
public long getNextJoinPosition(long currentJoinPosition, int probePosition, Page allProbeChannelsPage)
{
int partition = decodePartition(currentJoinPosition);
long joinPosition = decodeJoinPosition(currentJoinPosition);
LookupSource lookupSource = lookupSources[partition];
long nextJoinPosition = lookupSource.getNextJoinPosition(joinPosition, probePosition, allProbeChannelsPage);
if (nextJoinPosition < 0) {
return nextJoinPosition;
}
return encodePartitionedJoinPosition(partition, toIntExact(nextJoinPosition));
}
代码示例来源:origin: prestodb/presto
@Override
public StreamDataOutput getStreamDataOutput(int column)
{
return new StreamDataOutput(buffer::writeDataTo, new Stream(column, streamKind, toIntExact(buffer.getOutputDataSize()), true));
}
代码示例来源:origin: prestodb/presto
@Override
public StreamDataOutput getStreamDataOutput(int column)
{
return new StreamDataOutput(buffer::writeDataTo, new Stream(column, DATA, toIntExact(buffer.getOutputDataSize()), false));
}
代码示例来源:origin: prestodb/presto
private static Block fixedWidthSequence(long start, long stop, long step, FixedWidthType type)
{
checkValidStep(start, stop, step);
int length = toIntExact((stop - start) / step + 1L);
checkMaxEntry(length);
BlockBuilder blockBuilder = type.createBlockBuilder(null, length);
for (long i = 0, value = start; i < length; ++i, value += step) {
type.writeLong(blockBuilder, value);
}
return blockBuilder.build();
}
代码示例来源:origin: prestodb/presto
private Slice getSliceOutput()
{
buffer.close();
DynamicSliceOutput output = new DynamicSliceOutput(toIntExact(buffer.getOutputDataSize()));
buffer.writeDataTo(output);
Slice slice = output.slice();
buffer.reset();
return slice;
}
}
代码示例来源:origin: prestodb/presto
@ScalarOperator(CAST)
@LiteralParameters("x")
@SqlType("varchar(x)")
public static Slice castToSlice(@SqlType(StandardTypes.INTERVAL_YEAR_TO_MONTH) long value)
{
return utf8Slice(IntervalYearMonth.formatMonths(toIntExact(value)));
}
代码示例来源:origin: prestodb/presto
private static SerializedPage readSerializedPage(SliceInput sliceInput)
{
int positionCount = sliceInput.readInt();
byte codecMarker = sliceInput.readByte();
int uncompressedSizeInBytes = sliceInput.readInt();
int sizeInBytes = sliceInput.readInt();
Slice slice = sliceInput.readSlice(toIntExact((sizeInBytes)));
return new SerializedPage(slice, lookupCodecFromMarker(codecMarker), positionCount, uncompressedSizeInBytes);
}
代码示例来源:origin: prestodb/presto
@Description("add the specified amount of time to the given time")
@LiteralParameters("x")
@ScalarFunction("date_add")
@SqlType(StandardTypes.TIME)
public static long addFieldValueTime(ConnectorSession session, @SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.TIME) long time)
{
if (session.isLegacyTimestamp()) {
ISOChronology chronology = getChronology(session.getTimeZoneKey());
return modulo24Hour(chronology, getTimeField(chronology, unit).add(time, toIntExact(value)));
}
return modulo24Hour(getTimeField(UTC_CHRONOLOGY, unit).add(time, toIntExact(value)));
}
代码示例来源:origin: prestodb/presto
@Description("add the specified amount of time to the given timestamp")
@LiteralParameters("x")
@ScalarFunction("date_add")
@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE)
public static long addFieldValueTimestampWithTimeZone(
@SqlType("varchar(x)") Slice unit,
@SqlType(StandardTypes.BIGINT) long value,
@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long timestampWithTimeZone)
{
long millis = getTimestampField(unpackChronology(timestampWithTimeZone), unit).add(unpackMillisUtc(timestampWithTimeZone), toIntExact(value));
return updateMillisUtc(millis, timestampWithTimeZone);
}
内容来源于网络,如有侵权,请联系作者删除!