Skip to content

Commit

Permalink
Refactored api controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Jan 28, 2024
1 parent 8ab64e4 commit 7f6435b
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/main/java/org/coucal/command/AbstractCommand.java
Original file line number Diff line number Diff line change
@@ -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 <T> the command result type
*/
public abstract class AbstractCommand<T> implements Callable<Integer> {

private Consumer<T> consumer;

public AbstractCommand() {
this.consumer = DefaultOutputHandlers.STDOUT_PRINTER();
}

public AbstractCommand(Consumer<T> consumer) {
this.consumer = consumer;
}

public AbstractCommand<T> withConsumer(Consumer<T> consumer) {
this.consumer = consumer;
return this;
}

public final Consumer<T> getConsumer() {
return consumer;
}
}

0 comments on commit 7f6435b

Please sign in to comment.