Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Nov 8, 2024
1 parent cb6b2a8 commit 088bcff
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
16 changes: 8 additions & 8 deletions builtins/src/main/java/org/jline/builtins/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@ public static void history(LineReader reader, PrintStream out, PrintStream err,
} else if (opt.isSet("save")) {
history.save();
} else if (opt.isSet("A")) {
Path file = opt.args().size() > 0 ? currentDir.resolve(opt.args().get(0)) : null;
Path file = !opt.args().isEmpty() ? currentDir.resolve(opt.args().get(0)) : null;
history.append(file, increment);
} else if (opt.isSet("R")) {
Path file = opt.args().size() > 0 ? currentDir.resolve(opt.args().get(0)) : null;
Path file = !opt.args().isEmpty() ? currentDir.resolve(opt.args().get(0)) : null;
history.read(file, increment);
} else if (opt.isSet("W")) {
Path file = opt.args().size() > 0 ? currentDir.resolve(opt.args().get(0)) : null;
Path file = !opt.args().isEmpty() ? currentDir.resolve(opt.args().get(0)) : null;
history.write(file, increment);
} else {
done = false;
Expand Down Expand Up @@ -361,7 +361,7 @@ public ReExecute(History history, Options opt) throws IOException {
if (edit) {
cmdFile = File.createTempFile("jline-history-", null);
cmdWriter = new FileWriter(cmdFile);
} else if (opt.args().size() > 0) {
} else if (!opt.args().isEmpty()) {
String[] s = opt.args().get(argId).split("=");
if (s.length == 2) {
argId = argId + 1;
Expand Down Expand Up @@ -640,7 +640,7 @@ public static void keymap(LineReader reader, PrintStream out, PrintStream err, S
if (opt.isSet("l")) {
boolean commands = opt.isSet("L");
// TODO: handle commands
if (opt.args().size() > 0) {
if (!opt.args().isEmpty()) {
for (String arg : opt.args()) {
KeyMap<Binding> map = keyMaps.get(arg);
if (map == null) {
Expand Down Expand Up @@ -704,7 +704,7 @@ public static void keymap(LineReader reader, PrintStream out, PrintStream err, S
err.println("keymap: keymap can not be selected with -N");
return;
}
if (opt.args().size() > 0) {
if (!opt.args().isEmpty()) {
err.println("keymap: too many arguments for -d");
return;
}
Expand Down Expand Up @@ -869,9 +869,9 @@ public static void keymap(LineReader reader, PrintStream out, PrintStream err, S
err.println("keymap: option -p requires a prefix string");
return;
}
if (opt.args().size() > 0 || !opt.isSet("e") && !opt.isSet("v")) {
if (!opt.args().isEmpty() || !opt.isSet("e") && !opt.isSet("v")) {
Map<String, Binding> bound = map.getBoundKeys();
String seq = opt.args().size() > 0 ? KeyMap.translate(opt.args().get(0)) : null;
String seq = !opt.args().isEmpty() ? KeyMap.translate(opt.args().get(0)) : null;
Map.Entry<String, Binding> begin = null;
String last = null;
Iterator<Entry<String, Binding>> iterator = bound.entrySet().iterator();
Expand Down
21 changes: 8 additions & 13 deletions builtins/src/main/java/org/jline/builtins/Nano.java
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,7 @@ public String up(String hint) {
}
boolean found = false;
for (int pid = patternId; pid < patterns.size(); pid++) {
if (hint.length() == 0 || patterns.get(pid).startsWith(hint)) {
if (hint.isEmpty() || patterns.get(pid).startsWith(hint)) {
patternId = pid + 1;
out = patterns.get(pid);
found = true;
Expand All @@ -1467,7 +1467,7 @@ public String up(String hint) {

public String down(String hint) {
String out = hint;
if (patterns.size() > 0) {
if (!patterns.isEmpty()) {
if (lastMoveUp) {
patternId--;
}
Expand All @@ -1493,7 +1493,7 @@ public String down(String hint) {
}

public void add(String pattern) {
if (pattern.trim().length() == 0) {
if (pattern.trim().isEmpty()) {
return;
}
patterns.remove(pattern);
Expand All @@ -1512,7 +1512,7 @@ public void persist() {
try (BufferedWriter writer = Files.newBufferedWriter(
historyFile.toAbsolutePath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE)) {
for (String s : patterns) {
if (s.trim().length() > 0) {
if (!s.trim().isEmpty()) {
writer.append(s);
writer.newLine();
}
Expand Down Expand Up @@ -2151,7 +2151,7 @@ private boolean save(String name) throws IOException {
setMessage("Wrote " + buffer.lines.size() + " lines");
return true;
} catch (IOException e) {
setMessage("Error writing " + name + ": " + e.toString());
setMessage("Error writing " + name + ": " + e);
return false;
} finally {
Files.deleteIfExists(t);
Expand Down Expand Up @@ -2312,7 +2312,7 @@ private String getReadMessage() {
return sb.toString();
}

void gotoLine() throws IOException {
void gotoLine() {
KeyMap<Operation> readKeyMap = new KeyMap<>();
readKeyMap.setUnicode(Operation.INSERT);
for (char i = 32; i < 256; i++) {
Expand Down Expand Up @@ -2786,12 +2786,7 @@ String replace() throws IOException {
if (editBuffer.length() > 0) {
replaceTerm = editBuffer.toString();
}
if (replaceTerm == null) {
setMessage("Cancelled");
throw new IllegalArgumentException();
} else {
patternHistory.add(replaceTerm);
}
patternHistory.add(replaceTerm);
return replaceTerm;
case HELP:
help("nano-replace-help.txt");
Expand Down Expand Up @@ -2965,7 +2960,7 @@ void smoothScrolling() {
setMessage("Smooth scrolling " + (smoothScrolling ? "enabled" : "disabled"));
}

void mouseSupport() throws IOException {
void mouseSupport() {
mouseSupport = !mouseSupport;
setMessage("Mouse support " + (mouseSupport ? "enabled" : "disabled"));
terminal.trackMouse(mouseSupport ? Terminal.MouseTracking.Normal : Terminal.MouseTracking.Off);
Expand Down
5 changes: 3 additions & 2 deletions demo/src/main/java/org/jline/demo/Repl.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
*/
public class Repl {

@SuppressWarnings("resource")
protected static class MyCommands extends JlineCommandRegistry implements CommandRegistry {
private LineReader reader;
private final Supplier<Path> workDir;
Expand Down Expand Up @@ -95,7 +96,7 @@ private void tput(CommandInput input) {
try {
Options opt = parseOptions(usage, input.xargs());
List<String> argv = opt.args();
if (argv.size() > 0) {
if (!argv.isEmpty()) {
Capability vcap = Capability.byName(argv.get(0));
if (vcap != null) {
terminal()
Expand Down Expand Up @@ -161,7 +162,7 @@ private void echo(CommandInput input) {
List<String> argv = opt.args();
if (opt.isSet("version")) {
terminal().writer().println("echo version: v0.1");
} else if (opt.args().size() >= 1) {
} else if (!opt.args().isEmpty()) {
terminal().writer().println(String.join(" ", opt.args()));
}
} catch (Exception e) {
Expand Down

0 comments on commit 088bcff

Please sign in to comment.