@Test void builderIsNotReusable() { final CommandBuilder.SimpleBuilder<String> builder = new CommandBuilder.SimpleBuilder<>(new DoNothingCommand()); final CanonCommand<String> canonCommand = builder.build(); assertNotNull(canonCommand); assertThrows(IllegalStateException.class, builder::build); }
public CanonCommand<R> build() { if (wasBuilt) throw new IllegalStateException("Build has already been called"); wasBuilt = true; try { final List<Supplier<DecoratorCommand<R>>> localDecorators = getDecorators(); if (localDecorators.isEmpty()) return canonCommand; for (final Supplier<DecoratorCommand<R>> decoratorSupplier : localDecorators) { decoratedCommand = decoratorSupplier.get(); } return decoratedCommand; } finally { decoratedCommand = null; decorators.clear(); } }
CommandBuilder { public CanonCommand<R> build() { if (wasBuilt) throw new IllegalStateException("Build has already been called"); wasBuilt = true; try { final List<Supplier<DecoratorCommand<R>>> localDecorators = getDecorators(); if (localDecorators.isEmpty()) return canonCommand; for (final Supplier<DecoratorCommand<R>> decoratorSupplier : localDecorators) { decoratedCommand = decoratorSupplier.get(); } return decoratedCommand; } finally { decoratedCommand = null; decorators.clear(); } } }
CommandBuilder { public CanonCommand<R> build() { if (wasBuilt) throw new IllegalStateException("Build has already been called"); wasBuilt = true; try { final List<Supplier<DecoratorCommand<R>>> localDecorators = getDecorators(); if (localDecorators.isEmpty()) return canonCommand; for (final Supplier<DecoratorCommand<R>> decoratorSupplier : localDecorators) { decoratedCommand = decoratorSupplier.get(); } return decoratedCommand; } finally { decoratedCommand = null; decorators.clear(); } } CommandBuilder(final CanonCommand<R> canonCommand); }
CommandBuilder { public CanonCommand<R> build() { if (wasBuilt) throw new IllegalStateException("Build has already been called"); wasBuilt = true; try { final List<Supplier<DecoratorCommand<R>>> localDecorators = getDecorators(); if (localDecorators.isEmpty()) return canonCommand; for (final Supplier<DecoratorCommand<R>> decoratorSupplier : localDecorators) { decoratedCommand = decoratorSupplier.get(); } return decoratedCommand; } finally { decoratedCommand = null; decorators.clear(); } } CommandBuilder(final CanonCommand<R> canonCommand); T timeout(final Duration timeout); T withDefaultOnException(final R defaultValue); CanonCommand<R> build(); }
CommandBuilder { public CanonCommand<R> build() { if (wasBuilt) throw new IllegalStateException("Build has already been called"); wasBuilt = true; try { final List<Supplier<DecoratorCommand<R>>> localDecorators = getDecorators(); if (localDecorators.isEmpty()) return canonCommand; for (final Supplier<DecoratorCommand<R>> decoratorSupplier : localDecorators) { decoratedCommand = decoratorSupplier.get(); } return decoratedCommand; } finally { decoratedCommand = null; decorators.clear(); } } CommandBuilder(final CanonCommand<R> canonCommand); T timeout(final Duration timeout); T withDefaultOnException(final R defaultValue); CanonCommand<R> build();  }