From 7f6435b250861e5d23869d8065288aaee361ed58 Mon Sep 17 00:00:00 2001 From: Ben Fortuna Date: Sun, 28 Jan 2024 13:38:24 +1100 Subject: [PATCH] Refactored api controllers --- .../org/coucal/command/AbstractCommand.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main/java/org/coucal/command/AbstractCommand.java diff --git a/src/main/java/org/coucal/command/AbstractCommand.java b/src/main/java/org/coucal/command/AbstractCommand.java new file mode 100644 index 0000000..3c8ede8 --- /dev/null +++ b/src/main/java/org/coucal/command/AbstractCommand.java @@ -0,0 +1,46 @@ +/* + * Copyright 2023 Ben Fortuna + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.coucal.command; + +import java.util.concurrent.Callable; +import java.util.function.Consumer; + +/** + * Base class for all commands that will invoke the specified consumer upon execution completion. + * @param the command result type + */ +public abstract class AbstractCommand implements Callable { + + private Consumer consumer; + + public AbstractCommand() { + this.consumer = DefaultOutputHandlers.STDOUT_PRINTER(); + } + + public AbstractCommand(Consumer consumer) { + this.consumer = consumer; + } + + public AbstractCommand withConsumer(Consumer consumer) { + this.consumer = consumer; + return this; + } + + public final Consumer getConsumer() { + return consumer; + } +}