Reduce line duplication due to moved class

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
Emmanuel Bigeon 2019-06-08 12:05:50 -04:00
parent fe8f0212ea
commit 7a2991acc1

View File

@ -4,46 +4,8 @@
*/
package net.bigeon.gclc.socket;
/*-
* #%L
* GCLC Socket
* %%
* Copyright (C) 2016 - 2018 Bigeon
* %%
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Collection;
import net.bigeon.gclc.command.Command;
import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.exception.CommandRunExceptionType;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.manager.ConsoleOutput;
@ -56,11 +18,7 @@ import net.bigeon.gclc.manager.ConsoleOutput;
@Deprecated
public final class RemoteDisconnectCommand<T> extends Command {
/** The connexion manager. */
private final ConnexionManager<T> manager;
/** If all connexion should be disconnected when no argument have been
* specified. */
private final boolean all;
private final net.bigeon.gclc.socket.cmd.RemoteDisconnectCommand real;
/** Create the disconnection command.
*
@ -71,8 +29,8 @@ public final class RemoteDisconnectCommand<T> extends Command {
public RemoteDisconnectCommand(final String name, final ConnexionManager<T> manager,
final boolean all) {
super(name);
this.manager = manager;
this.all = all;
real = new net.bigeon.gclc.socket.cmd.RemoteDisconnectCommand<>(name, manager,
all);
}
/* (non-Javadoc)
@ -81,52 +39,20 @@ public final class RemoteDisconnectCommand<T> extends Command {
@Override
public void execute(final ConsoleOutput out, final ConsoleInput in,
final String... args) throws CommandRunException {
if (args.length == 0 && all) {
final Collection<String> coll = manager.getConnected();
for (final String string : coll) {
manager.disconnect(string);
}
}
for (final String string : args) {
if (manager.isConnected(string)) {
manager.disconnect(string);
} else {
print(out,
MessageFormat.format("[WARNING] {0} is not connected", string)); //$NON-NLS-1$
}
}
}
/** Print a message if the output is defined.
*
* @param out the output
* @param string the message
* @throws CommandRunException if the output exists but cannot be printed to */
private static void print(final ConsoleOutput out, final String string)
throws CommandRunException {
if (out != null) {
try {
out.println(string);
} catch (final IOException e) {
throw new CommandRunException(CommandRunExceptionType.INTERACTION,
"Unable to print to existing output", e); //$NON-NLS-1$
}
}
real.execute(out, in, args);
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#tip() */
@Override
public String tip() {
return "Close a connexion."; //$NON-NLS-1$
return real.tip();
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.Command#usageDetail() */
@Override
protected String usageDetail() {
return MessageFormat.format(
" If arguments are provided the corresponding connexions are closed, otherwise\n{0} are.",
all ? "all connexions" : "none");
return "";
}
}