From e5c3bb015207a685c668cbd6e0c7cdc29a5114b5 Mon Sep 17 00:00:00 2001 From: Emmanuel Bigeon Date: Mon, 6 May 2019 20:51:12 -0400 Subject: [PATCH] Replace ConstantString by lambda expression Signed-off-by: Emmanuel Bigeon --- .../net/bigeon/gclc/manager/EmptyInput.java | 38 +------------------ .../gclc/manager/StreamConsoleInput.java | 5 +-- .../net/bigeon/gclc/tools/ConstantString.java | 4 +- 3 files changed, 6 insertions(+), 41 deletions(-) diff --git a/gclc/src/main/java/net/bigeon/gclc/manager/EmptyInput.java b/gclc/src/main/java/net/bigeon/gclc/manager/EmptyInput.java index 0f0fdb3..ab58ebf 100644 --- a/gclc/src/main/java/net/bigeon/gclc/manager/EmptyInput.java +++ b/gclc/src/main/java/net/bigeon/gclc/manager/EmptyInput.java @@ -40,48 +40,12 @@ package net.bigeon.gclc.manager; import java.util.function.Supplier; -/*- - * #%L - * Generic Command Ligne console - * %% - * Copyright (C) 2014 - 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 net.bigeon.gclc.tools.ConstantString; - /** A console input that return empty to all prompting. * * @author Emmanuel Bigeon */ public final class EmptyInput implements ConsoleInput { - private static final ConstantString CONSTANT_STRING = new ConstantString(""); + private static final Supplier CONSTANT_STRING = () -> ""; /** The empty prompter. */ public static final ConsoleInput INSTANCE = new EmptyInput(); diff --git a/gclc/src/main/java/net/bigeon/gclc/manager/StreamConsoleInput.java b/gclc/src/main/java/net/bigeon/gclc/manager/StreamConsoleInput.java index d8adb3e..e86ae87 100644 --- a/gclc/src/main/java/net/bigeon/gclc/manager/StreamConsoleInput.java +++ b/gclc/src/main/java/net/bigeon/gclc/manager/StreamConsoleInput.java @@ -79,7 +79,6 @@ import java.io.PrintStream; import java.nio.charset.Charset; import java.util.function.Supplier; -import net.bigeon.gclc.tools.ConstantString; import net.bigeon.gclc.utils.ReadingRunnable; /** A console using the input stream and print stream. @@ -90,7 +89,7 @@ import net.bigeon.gclc.utils.ReadingRunnable; public final class StreamConsoleInput implements ConsoleInput { /** The default prompt. */ - public static final Supplier DEFAULT_PROMPT = new ConstantString("> "); //$NON-NLS-1$ + public static final Supplier DEFAULT_PROMPT = () -> ("> "); //$NON-NLS-1$ /** The command prompt. It can be changed. */ private Supplier prompt = DEFAULT_PROMPT; @@ -213,7 +212,7 @@ public final class StreamConsoleInput implements ConsoleInput { * @see net.bigeon.gclc.manager.ConsoleInput#setPrompt(java.lang.String) */ @Override public void setPrompt(final String prompt) { - this.prompt = new ConstantString(prompt); + this.prompt = () -> (prompt); } @Override diff --git a/gclc/src/main/java/net/bigeon/gclc/tools/ConstantString.java b/gclc/src/main/java/net/bigeon/gclc/tools/ConstantString.java index 73d5109..268b31c 100644 --- a/gclc/src/main/java/net/bigeon/gclc/tools/ConstantString.java +++ b/gclc/src/main/java/net/bigeon/gclc/tools/ConstantString.java @@ -73,7 +73,9 @@ import java.util.function.Supplier; /** A supplier of string that hold a constant string. * - * @author Emmanuel Bigeon */ + * @author Emmanuel Bigeon + * @since 2.1.2, use a lambda expression instead */ +@Deprecated public class ConstantString implements Supplier { private final String string;