code: public static void updateTimer(Optional<Timer> timer, final long duration, final TimeUnit unit) {
      timer.transform(new Function<Timer, Timer>() {
        @Override
        public Timer apply(@Nonnull Timer input) {
          input.update(duration, unit);
          return input;
        }
      });
    }
docs: Updates a timer only if it is defined.
  @param timer an Optional&lt;{@link com.codahale.metrics.Timer}&gt;
  @param duration
  @param unit