1313import java .io .ByteArrayInputStream ;
1414import java .io .ByteArrayOutputStream ;
1515import java .io .File ;
16- import java .io .FileReader ;
1716import java .io .IOException ;
1817import java .io .InputStream ;
1918import java .io .InputStreamReader ;
@@ -1450,7 +1449,7 @@ public String up(String hint) {
14501449 }
14511450 boolean found = false ;
14521451 for (int pid = patternId ; pid < patterns .size (); pid ++) {
1453- if (hint .length () == 0 || patterns .get (pid ).startsWith (hint )) {
1452+ if (hint .isEmpty () || patterns .get (pid ).startsWith (hint )) {
14541453 patternId = pid + 1 ;
14551454 out = patterns .get (pid );
14561455 found = true ;
@@ -1467,7 +1466,7 @@ public String up(String hint) {
14671466
14681467 public String down (String hint ) {
14691468 String out = hint ;
1470- if (patterns .size () > 0 ) {
1469+ if (! patterns .isEmpty () ) {
14711470 if (lastMoveUp ) {
14721471 patternId --;
14731472 }
@@ -1493,7 +1492,7 @@ public String down(String hint) {
14931492 }
14941493
14951494 public void add (String pattern ) {
1496- if (pattern .trim ().length () == 0 ) {
1495+ if (pattern .trim ().isEmpty () ) {
14971496 return ;
14981497 }
14991498 patterns .remove (pattern );
@@ -1512,7 +1511,7 @@ public void persist() {
15121511 try (BufferedWriter writer = Files .newBufferedWriter (
15131512 historyFile .toAbsolutePath (), StandardOpenOption .WRITE , StandardOpenOption .CREATE )) {
15141513 for (String s : patterns ) {
1515- if (s .trim ().length () > 0 ) {
1514+ if (! s .trim ().isEmpty () ) {
15161515 writer .append (s );
15171516 writer .newLine ();
15181517 }
@@ -1656,11 +1655,11 @@ public Nano(Terminal terminal, Path root, Options opts, ConfigurationPath config
16561655 }
16571656
16581657 private void parseConfig (Path file ) throws IOException {
1659- try (BufferedReader reader = new BufferedReader ( new FileReader ( file . toFile ()) )) {
1658+ try (BufferedReader reader = Files . newBufferedReader ( file )) {
16601659 String line ;
16611660 while ((line = reader .readLine ()) != null ) {
16621661 line = line .trim ();
1663- if (line .length () > 0 && !line .startsWith ("#" )) {
1662+ if (! line .isEmpty () && !line .startsWith ("#" )) {
16641663 List <String > parts = SyntaxHighlighter .RuleSplitter .split (line );
16651664 if (parts .get (0 ).equals (COMMAND_INCLUDE )) {
16661665 SyntaxHighlighter .nanorcInclude (parts .get (1 ), syntaxFiles );
@@ -2151,7 +2150,7 @@ private boolean save(String name) throws IOException {
21512150 setMessage ("Wrote " + buffer .lines .size () + " lines" );
21522151 return true ;
21532152 } catch (IOException e ) {
2154- setMessage ("Error writing " + name + ": " + e . toString () );
2153+ setMessage ("Error writing " + name + ": " + e );
21552154 return false ;
21562155 } finally {
21572156 Files .deleteIfExists (t );
@@ -2312,7 +2311,7 @@ private String getReadMessage() {
23122311 return sb .toString ();
23132312 }
23142313
2315- void gotoLine () throws IOException {
2314+ void gotoLine () {
23162315 KeyMap <Operation > readKeyMap = new KeyMap <>();
23172316 readKeyMap .setUnicode (Operation .INSERT );
23182317 for (char i = 32 ; i < 256 ; i ++) {
@@ -2360,7 +2359,7 @@ void gotoLine() throws IOException {
23602359 int [] args = {0 , 0 };
23612360 try {
23622361 for (int i = 0 ; i < pos .length ; i ++) {
2363- if (pos [i ].trim ().length () > 0 ) {
2362+ if (! pos [i ].trim ().isEmpty () ) {
23642363 args [i ] = Integer .parseInt (pos [i ]) - 1 ;
23652364 if (args [i ] < 0 ) {
23662365 throw new NumberFormatException ();
@@ -2786,12 +2785,7 @@ String replace() throws IOException {
27862785 if (editBuffer .length () > 0 ) {
27872786 replaceTerm = editBuffer .toString ();
27882787 }
2789- if (replaceTerm == null ) {
2790- setMessage ("Cancelled" );
2791- throw new IllegalArgumentException ();
2792- } else {
2793- patternHistory .add (replaceTerm );
2794- }
2788+ patternHistory .add (replaceTerm );
27952789 return replaceTerm ;
27962790 case HELP :
27972791 help ("nano-replace-help.txt" );
@@ -2868,7 +2862,7 @@ String computeCurPos() {
28682862 sb .append ("/" );
28692863 sb .append (buffer .length (buffer .lines .get (buffer .line )) + 1 );
28702864 sb .append (" (" );
2871- if (buffer .lines .get (buffer .line ).length () > 0 ) {
2865+ if (! buffer .lines .get (buffer .line ).isEmpty () ) {
28722866 sb .append (Math .round (
28732867 (100.0 * (buffer .offsetInLine + buffer .column )) / (buffer .length (buffer .lines .get (buffer .line )))));
28742868 } else {
@@ -2965,7 +2959,7 @@ void smoothScrolling() {
29652959 setMessage ("Smooth scrolling " + (smoothScrolling ? "enabled" : "disabled" ));
29662960 }
29672961
2968- void mouseSupport () throws IOException {
2962+ void mouseSupport () {
29692963 mouseSupport = !mouseSupport ;
29702964 setMessage ("Mouse support " + (mouseSupport ? "enabled" : "disabled" ));
29712965 terminal .trackMouse (mouseSupport ? Terminal .MouseTracking .Normal : Terminal .MouseTracking .Off );
0 commit comments