public void increment( long count ) { this.count = Math.addExact( this.count, count ); }
private long secondsWithNanos( long seconds, long nanos ) { return Math.addExact( seconds, nanos / NANOS_PER_SECOND ); }
private long offset( long position ) { if ( position < 0 ) { throw new IllegalArgumentException( "Position must be >= 0." ); } return Math.addExact( position, offset ); }
static long addExact(long usedBytes, long bytes) { try { return Math.addExact(usedBytes, bytes); } catch (ArithmeticException e) { throw new RuntimeException(format("Overflow detected. usedBytes: %d, bytes: %d", usedBytes, bytes), e); } } }
@Override public void addValue(long value) { nonNullValueCount++; minimum = Math.min(value, minimum); maximum = Math.max(value, maximum); if (!overflow) { try { sum = addExact(sum, value); } catch (ArithmeticException e) { overflow = true; } } }
public static int toMonths(int year, int months) { try { return addExact(multiplyExact(year, 12), months); } catch (ArithmeticException e) { throw new IllegalArgumentException(e); } }
public static int toMonths(int year, int months) { try { return addExact(multiplyExact(year, 12), months); } catch (ArithmeticException e) { throw new IllegalArgumentException(e); } }
/** * Constructs a Deadline that is a given duration after now. */ public static Deadline fromNow(Duration duration) { return new Deadline(Math.addExact(System.nanoTime(), duration.toNanos())); } }
public static long toMillis(long day, long hour, long minute, long second, long millis) { try { long value = millis; value = addExact(value, multiplyExact(day, MILLIS_IN_DAY)); value = addExact(value, multiplyExact(hour, MILLIS_IN_HOUR)); value = addExact(value, multiplyExact(minute, MILLIS_IN_MINUTE)); value = addExact(value, multiplyExact(second, MILLIS_IN_SECOND)); return value; } catch (ArithmeticException e) { throw new IllegalArgumentException(e); } }
public static long toMillis(long day, long hour, long minute, long second, long millis) { try { long value = millis; value = addExact(value, multiplyExact(day, MILLIS_IN_DAY)); value = addExact(value, multiplyExact(hour, MILLIS_IN_HOUR)); value = addExact(value, multiplyExact(minute, MILLIS_IN_MINUTE)); value = addExact(value, multiplyExact(second, MILLIS_IN_SECOND)); return value; } catch (ArithmeticException e) { throw new IllegalArgumentException(e); } }
private long calcAverageLengthInSeconds( long months, long days, long seconds ) { long daysInSeconds = Math.multiplyExact( days, SECONDS_PER_DAY ); long monthsInSeconds = Math.multiplyExact( months, AVG_SECONDS_PER_MONTH ); return Math.addExact( seconds, Math.addExact( daysInSeconds, monthsInSeconds ) ); }
/** * Overflow safe addition of two longs * * @param a left-hand operand * @param b right-hand operand * @return a + b */ public static LongValue add( long a, long b ) { return longValue( Math.addExact( a, b ) ); }
public Deadline plus(Duration other) { return new Deadline(Math.addExact(timeNanos, other.toNanos())); }
@UsedByGeneratedCode public static int checkedAdd(int x, int y) { try { return addExact(x, y); } catch (ArithmeticException e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Concatenated string is too large"); } } }
public void add(Page page) { checkState(canAdd(page), "page buffer is full"); pages.add(page); usedMemoryBytes += page.getRetainedSizeInBytes(); rowCount = addExact(rowCount, page.getPositionCount()); }
public IndexSample combine( IndexSample sample1, IndexSample sample2 ) { long indexSize = Math.addExact( sample1.indexSize(), sample2.indexSize() ); long uniqueValues = Math.addExact( sample1.uniqueValues(), sample2.uniqueValues() ); long sampleSize = Math.addExact( sample1.sampleSize(), sample2.sampleSize() ); return new IndexSample( indexSize, uniqueValues, sampleSize ); } }
@ScalarOperator(ADD) @SqlType(StandardTypes.BIGINT) public static long add(@SqlType(StandardTypes.BIGINT) long left, @SqlType(StandardTypes.BIGINT) long right) { try { return Math.addExact(left, right); } catch (ArithmeticException e) { throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, format("bigint addition overflow: %s + %s", left, right), e); } }
@ScalarOperator(ADD) @SqlType(StandardTypes.INTEGER) public static long add(@SqlType(StandardTypes.INTEGER) long left, @SqlType(StandardTypes.INTEGER) long right) { try { return Math.addExact((int) left, (int) right); } catch (ArithmeticException e) { throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, format("integer addition overflow: %s + %s", left, right), e); } }
@SqlType(StandardTypes.INTEGER) public static long add( @SqlType(StandardTypes.INTEGER) long left, @SqlType(StandardTypes.INTEGER) long right) { return Math.addExact((int) left, (int) right); }
@SqlType(StandardTypes.INTEGER) public static long addBlockPosition( @SqlType(StandardTypes.INTEGER) long first, @BlockPosition @SqlType(value = StandardTypes.INTEGER, nativeContainerType = long.class) Block block, @BlockIndex int position) { return Math.addExact((int) first, (int) INTEGER.getLong(block, position)); } }