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)
|
private String doPrompt(final String message, final long timeout, final long tic)
|
||||||
throws InterruptedIOException, IOException {
|
throws IOException {
|
||||||
do {
|
do {
|
||||||
if (!checkPrompt()) {
|
if (!checkPrompt()) {
|
||||||
break;
|
break;
|
||||||
@ -227,13 +227,7 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final long timeoutLeft = getTimeoutLeft(tic, timeout);
|
final String res = actualPrompt(message, timeout, tic, actualConnected);
|
||||||
final String res;
|
|
||||||
if (timeoutLeft == 0) {
|
|
||||||
res = actualConnected.prompt(message);
|
|
||||||
} else {
|
|
||||||
res = actualConnected.prompt(message, timeoutLeft);
|
|
||||||
}
|
|
||||||
synchronized (promptLock) {
|
synchronized (promptLock) {
|
||||||
if (prompting) {
|
if (prompting) {
|
||||||
prompting = false;
|
prompting = false;
|
||||||
@ -254,6 +248,15 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
return null;
|
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) {
|
private static boolean checkTimeout(final long tic, final long timeout) {
|
||||||
return timeout <= 0 || tic + timeout > System.currentTimeMillis();
|
return timeout <= 0 || tic + timeout > System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user