Reduce prompting method complexity
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
43c9faaee7
commit
9c8866827d
@ -211,7 +211,7 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
||||
}
|
||||
|
||||
private String doPrompt(final String message, final long timeout, final long tic)
|
||||
throws InterruptedIOException, IOException {
|
||||
throws IOException {
|
||||
do {
|
||||
if (!checkPrompt()) {
|
||||
break;
|
||||
@ -227,13 +227,7 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
final long timeoutLeft = getTimeoutLeft(tic, timeout);
|
||||
final String res;
|
||||
if (timeoutLeft == 0) {
|
||||
res = actualConnected.prompt(message);
|
||||
} else {
|
||||
res = actualConnected.prompt(message, timeoutLeft);
|
||||
}
|
||||
final String res = actualPrompt(message, timeout, tic, actualConnected);
|
||||
synchronized (promptLock) {
|
||||
if (prompting) {
|
||||
prompting = false;
|
||||
@ -254,6 +248,15 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String actualPrompt(final String message, final long timeout,
|
||||
final long tic, final ConsoleInput actualConnected) throws IOException {
|
||||
final long timeoutLeft = getTimeoutLeft(tic, timeout);
|
||||
if (timeoutLeft == 0) {
|
||||
return actualConnected.prompt(message);
|
||||
}
|
||||
return actualConnected.prompt(message, timeoutLeft);
|
||||
}
|
||||
|
||||
private static boolean checkTimeout(final long tic, final long timeout) {
|
||||
return timeout <= 0 || tic + timeout > System.currentTimeMillis();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user