From 71da02e2dbbe99d76e979ec79cb57d7cea4d3790 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 3 Jul 2021 06:40:34 -0400 Subject: [PATCH] clean up warnings/casts --- app/src/processing/app/Settings.java | 33 +++++++++++++++------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/app/src/processing/app/Settings.java b/app/src/processing/app/Settings.java index efd016f23..ca4aacad1 100644 --- a/app/src/processing/app/Settings.java +++ b/app/src/processing/app/Settings.java @@ -46,10 +46,10 @@ public class Settings { * parses properly, we need to be able to get back to a clean version of that * setting so we can recover. */ - HashMap defaults; + Map defaults; /** Table of attributes/values. */ - HashMap table = new HashMap();; + Map table = new HashMap<>(); /** Associated file for this settings data. */ File file; @@ -63,7 +63,7 @@ public class Settings { } // clone the hash table - defaults = (HashMap) table.clone(); + defaults = new HashMap<>(table); } @@ -74,17 +74,21 @@ public class Settings { public void load(File additions) { String[] lines = PApplet.loadStrings(additions); - for (String line : lines) { - if ((line.length() == 0) || + if (lines != null) { + for (String line : lines) { + if ((line.length() == 0) || (line.charAt(0) == '#')) continue; - // this won't properly handle = signs being in the text - int equals = line.indexOf('='); - if (equals != -1) { - String key = line.substring(0, equals).trim(); - String value = line.substring(equals + 1).trim(); - table.put(key, value); + // this won't properly handle = signs being in the text + int equals = line.indexOf('='); + if (equals != -1) { + String key = line.substring(0, equals).trim(); + String value = line.substring(equals + 1).trim(); + table.put(key, value); + } } + } else { + Messages.loge(additions + " could not be read"); } // check for platform-specific properties in the defaults @@ -165,8 +169,7 @@ public class Settings { try { int v = Integer.parseInt(s.substring(1), 16); parsed = new Color(v); - } catch (Exception e) { - } + } catch (Exception ignored) { } } return parsed; } @@ -198,10 +201,10 @@ public class Settings { String name = pieces[0]; int style = Font.PLAIN; // equals zero - if (pieces[1].indexOf("bold") != -1) { //$NON-NLS-1$ + if (pieces[1].contains("bold")) { //$NON-NLS-1$ style |= Font.BOLD; } - if (pieces[1].indexOf("italic") != -1) { //$NON-NLS-1$ + if (pieces[1].contains("italic")) { //$NON-NLS-1$ style |= Font.ITALIC; } int size = PApplet.parseInt(pieces[2], 12);