@Test public void testMultipleException() { Exception exception = new Exception(); Object[] args = RateLimitedLogger.newArgsWithCountSinceLastWarning(new Object[] {1, exception}, 0); assertThat(args).containsExactly(1, 0, exception); }
@VisibleForTesting static @Nullable Object[] newArgsWithCountSinceLastWarning( Object[] args, int countSinceLastWarning) { if (args.length == 0) { return new Object[] {countSinceLastWarning}; } @Nullable Object[] argsPlus = new Object[args.length + 1]; if (args[args.length - 1] instanceof Throwable) { System.arraycopy(args, 0, argsPlus, 0, args.length - 1); argsPlus[args.length - 1] = countSinceLastWarning; argsPlus[args.length] = args[args.length - 1]; return argsPlus; } else { System.arraycopy(args, 0, argsPlus, 0, args.length); argsPlus[args.length] = countSinceLastWarning; return argsPlus; } }
RateLimitedLogger { @VisibleForTesting static @Nullable Object[] newArgsWithCountSinceLastWarning( Object[] args, int countSinceLastWarning) { if (args.length == 0) { return new Object[] {countSinceLastWarning}; } @Nullable Object[] argsPlus = new Object[args.length + 1]; if (args[args.length - 1] instanceof Throwable) { System.arraycopy(args, 0, argsPlus, 0, args.length - 1); argsPlus[args.length - 1] = countSinceLastWarning; argsPlus[args.length] = args[args.length - 1]; return argsPlus; } else { System.arraycopy(args, 0, argsPlus, 0, args.length); argsPlus[args.length] = countSinceLastWarning; return argsPlus; } } }
RateLimitedLogger { @VisibleForTesting static @Nullable Object[] newArgsWithCountSinceLastWarning( Object[] args, int countSinceLastWarning) { if (args.length == 0) { return new Object[] {countSinceLastWarning}; } @Nullable Object[] argsPlus = new Object[args.length + 1]; if (args[args.length - 1] instanceof Throwable) { System.arraycopy(args, 0, argsPlus, 0, args.length - 1); argsPlus[args.length - 1] = countSinceLastWarning; argsPlus[args.length] = args[args.length - 1]; return argsPlus; } else { System.arraycopy(args, 0, argsPlus, 0, args.length); argsPlus[args.length] = countSinceLastWarning; return argsPlus; } } RateLimitedLogger(Class<?> clazz);  RateLimitedLogger(Class<?> clazz, boolean willKeepTrying); }
RateLimitedLogger { @VisibleForTesting static @Nullable Object[] newArgsWithCountSinceLastWarning( Object[] args, int countSinceLastWarning) { if (args.length == 0) { return new Object[] {countSinceLastWarning}; } @Nullable Object[] argsPlus = new Object[args.length + 1]; if (args[args.length - 1] instanceof Throwable) { System.arraycopy(args, 0, argsPlus, 0, args.length - 1); argsPlus[args.length - 1] = countSinceLastWarning; argsPlus[args.length] = args[args.length - 1]; return argsPlus; } else { System.arraycopy(args, 0, argsPlus, 0, args.length); argsPlus[args.length] = countSinceLastWarning; return argsPlus; } } RateLimitedLogger(Class<?> clazz);  RateLimitedLogger(Class<?> clazz, boolean willKeepTrying); void warn(String format, /*@Nullable*/ Object... args); }
RateLimitedLogger { @VisibleForTesting static @Nullable Object[] newArgsWithCountSinceLastWarning( Object[] args, int countSinceLastWarning) { if (args.length == 0) { return new Object[] {countSinceLastWarning}; } @Nullable Object[] argsPlus = new Object[args.length + 1]; if (args[args.length - 1] instanceof Throwable) { System.arraycopy(args, 0, argsPlus, 0, args.length - 1); argsPlus[args.length - 1] = countSinceLastWarning; argsPlus[args.length] = args[args.length - 1]; return argsPlus; } else { System.arraycopy(args, 0, argsPlus, 0, args.length); argsPlus[args.length] = countSinceLastWarning; return argsPlus; } } RateLimitedLogger(Class<?> clazz);  RateLimitedLogger(Class<?> clazz, boolean willKeepTrying); void warn(String format, /*@Nullable*/ Object... args);  }