public static String mask(String input, int num, String mask) { int length = input.length(); return num > 0 ? input.substring(0, length - num).replaceAll(".", mask) + input.substring(length - num) : input.substring(0, Math.negateExact(num)) + input.substring(Math.negateExact(num), length).replaceAll(".", mask); }
/** * Creates a new {@link LRemCommand} to last {@literal count} values. * * @return a new {@link LRemCommand} to delete last {@literal count} values. */ public static LRemCommand last(long count) { Long value = count < 0L ? count : Math.negateExact(count); return new LRemCommand(null, value, null); }
@ScalarOperator(NEGATION) @SqlType(StandardTypes.INTEGER) public static long negate(@SqlType(StandardTypes.INTEGER) long value) { try { return Math.negateExact((int) value); } catch (ArithmeticException e) { throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, "integer negation overflow: " + value, e); } }
@ScalarOperator(NEGATION) @SqlType(StandardTypes.BIGINT) public static long negate(@SqlType(StandardTypes.BIGINT) long value) { try { return Math.negateExact(value); } catch (ArithmeticException e) { throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, "bigint negation overflow: " + value, e); } }
public static String mask(String input, int num, String mask) { int length = input.length(); return num > 0 ? input.substring(0, length - num).replaceAll(".", mask) + input.substring(length - num) : input.substring(0, Math.negateExact(num)) + input.substring(Math.negateExact(num), length).replaceAll(".", mask); }
/** * Delegates to {@link Math#negateExact(long)} * * @throws ArithmeticException if the result overflows a long **/ public static long safeNegate(long x) { return Math.negateExact(x); }
/** * Returns the negative value of this fraction. * This method does not simplify the fraction. * * @return the result of {@code -this}. * @throws ArithmeticException if the result overflows. */ public Fraction negate() { int n = numerator; int d = denominator; if (n != 0) { n = Math.negateExact(n); } else if (d != 0) { d = Math.negateExact(d); } else { return this; } return new Fraction(n, d); }
/** * Creates a new {@link LRemCommand} to last {@literal count} values. * * @return a new {@link LRemCommand} to delete last {@literal count} values. */ public static LRemCommand last(long count) { Long value = count < 0L ? count : Math.negateExact(count); return new LRemCommand(null, value, null); }
/** * Creates a new {@link LRemCommand} to last {@literal count} values. * * @return a new {@link LRemCommand} to delete last {@literal count} values. */ public static LRemCommand last(long count) { Long value = count < 0L ? count : Math.negateExact(count); return new LRemCommand(null, value, null); }
public static Runnable onceMore(Runnable loopBody) { AtomicInteger lock = new AtomicInteger(); return () -> { // request execution of the runnable int current = lock.incrementAndGet(); // another thread is executing if(current > 1) return; try { do { loopBody.run(); current = lock.addAndGet(Math.negateExact(current)); } while(current > 0); } catch(Throwable t) { lock.set(0); throw t; } }; }
/** * <p>Yields the absolute value of the represented calendar days. </p> * * @return non-negative count of calendar days * @since 3.4/4.3 */ /*[deutsch] * <p>Liefert den absoluten Betrag der repräsentierten Kalendertage. </p> * * @return non-negative count of calendar days * @since 3.4/4.3 */ public CalendarDays abs() { return ((this.days < 0) ? CalendarDays.of(Math.negateExact(this.days)) : this); }
public static Amount neg(Amount a) { return new Amount(Math.negateExact(a.nano)); }
@Override public long get(TemporalUnit unit) { for (Map.Entry<IsoUnit, TemporalUnit> entry : MAP.entrySet()) { if (entry.getValue().equals(unit)) { long amount = this.duration.getPartialAmount(entry.getKey()); if (this.duration.isNegative()) { amount = Math.negateExact(amount); } return amount; } } if (unit.equals(ChronoUnit.HALF_DAYS)) { long hd = Math.floorDiv(this.duration.getPartialAmount(ClockUnit.HOURS), 12); if (this.duration.isNegative()) { hd = Math.negateExact(hd); } return hd; } throw new UnsupportedTemporalTypeException(unit.toString()); // throws NPE if unit is null }
public void execute(Context ctx) { long value = ctx.getIntArgument(0); ctx.setReturnValues(new BInteger(Math.negateExact(value))); } }
@ScalarOperator(NEGATION) @SqlType(StandardTypes.BIGINT) public static long negate(@SqlType(StandardTypes.BIGINT) long value) { try { return Math.negateExact(value); } catch (ArithmeticException e) { throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, "bigint negation overflow: " + value, e); } }
@ScalarOperator(NEGATION) @SqlType(StandardTypes.INTEGER) public static long negate(@SqlType(StandardTypes.INTEGER) long value) { try { return Math.negateExact((int) value); } catch (ArithmeticException e) { throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, "integer negation overflow: " + value, e); } }
@ScalarOperator(NEGATION) @SqlType(StandardTypes.INTEGER) public static long negate(@SqlType(StandardTypes.INTEGER) long value) { try { return Math.negateExact((int) value); } catch (ArithmeticException e) { throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, "integer negation overflow: " + value, e); } }
@ScalarOperator(NEGATION) @SqlType(StandardTypes.BIGINT) public static long negate(@SqlType(StandardTypes.BIGINT) long value) { try { return Math.negateExact(value); } catch (ArithmeticException e) { throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, "bigint negation overflow: " + value, e); } }
@Test public void testAutoCommit() throws SQLException { LOGGER.info("Test Auto Commit"); long cents = 70; long fromAccountId = 1; long toAccountId = 2; DataSource dataSource = newDataSource(); try(Connection connection = dataSource.getConnection(); PreparedStatement transferStatement = connection.prepareStatement( "UPDATE account SET balance = ? WHERE id = ?" ) ) { transferStatement.setLong(1, Math.negateExact(cents)); transferStatement.setLong(2, fromAccountId); transferStatement.executeUpdate(); transferStatement.setLong(1, cents); transferStatement.setLong(2, toAccountId); transferStatement.executeUpdate(); } }
@Test public void testManualCommitWithTemplate() throws SQLException { long cents = 70; long fromAccountId = 1; long toAccountId = 2; transact((Connection connection) -> { try (PreparedStatement transferStatement = connection.prepareStatement( "UPDATE account SET balance = ? WHERE id = ?" )) { transferStatement.setLong(1, Math.negateExact(cents)); transferStatement.setLong(2, fromAccountId); transferStatement.executeUpdate(); transferStatement.setLong(1, cents); transferStatement.setLong(2, toAccountId); transferStatement.executeUpdate(); } catch (SQLException e) { throw new DataAccessException( e); } }); } }