From 4ebfc27d0c736932db6be081db8397de3a567724 Mon Sep 17 00:00:00 2001 From: Jonas_Jones <91549607+J-onasJones@users.noreply.github.com> Date: Sat, 25 Jun 2022 00:53:29 +0200 Subject: [PATCH] Reformated awful code --- .../arduinoctrls/config/SimpleConfig.java | 80 +++++++++---------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/src/main/java/me/jonasjones/arduinoctrls/config/SimpleConfig.java b/src/main/java/me/jonasjones/arduinoctrls/config/SimpleConfig.java index 0a2fea9..1dbe4a0 100644 --- a/src/main/java/me/jonasjones/arduinoctrls/config/SimpleConfig.java +++ b/src/main/java/me/jonasjones/arduinoctrls/config/SimpleConfig.java @@ -40,9 +40,9 @@ public class SimpleConfig { private boolean broken = false; public interface DefaultConfig { - String get( String namespace ); + String get(String namespace); - static String empty( String namespace ) { + static String empty(String namespace) { return ""; } } @@ -53,7 +53,7 @@ public class SimpleConfig { private final String filename; private DefaultConfig provider; - private ConfigRequest(File file, String filename ) { + private ConfigRequest(File file, String filename) { this.file = file; this.filename = filename; this.provider = DefaultConfig::empty; @@ -67,7 +67,7 @@ public class SimpleConfig { * @return current config request object * @see DefaultConfig */ - public ConfigRequest provider( DefaultConfig provider ) { + public ConfigRequest provider(DefaultConfig provider) { this.provider = provider; return this; } @@ -79,11 +79,11 @@ public class SimpleConfig { * @see SimpleConfig */ public SimpleConfig request() { - return new SimpleConfig( this ); + return new SimpleConfig(this); } private String getConfig() { - return provider.get( filename ) + "\n"; + return provider.get(filename) + "\n"; } } @@ -95,65 +95,65 @@ public class SimpleConfig { * @param filename - name of the config file * @return new config request object */ - public static ConfigRequest of( String filename ) { + public static ConfigRequest of(String filename) { Path path = FabricLoader.getInstance().getConfigDir(); - return new ConfigRequest( path.resolve( filename + ".properties" ).toFile(), filename ); + return new ConfigRequest(path.resolve(filename + ".properties").toFile(), filename); } private void createConfig() throws IOException { // try creating missing files request.file.getParentFile().mkdirs(); - Files.createFile( request.file.toPath() ); + Files.createFile(request.file.toPath()); // write default config data PrintWriter writer = new PrintWriter(request.file, "UTF-8"); - writer.write( request.getConfig() ); + writer.write(request.getConfig()); writer.close(); } private void loadConfig() throws IOException { - Scanner reader = new Scanner( request.file ); - for( int line = 1; reader.hasNextLine(); line ++ ) { - parseConfigEntry( reader.nextLine(), line ); + Scanner reader = new Scanner(request.file); + for (int line = 1; reader.hasNextLine(); line++) { + parseConfigEntry(reader.nextLine(), line); } } - private void parseConfigEntry( String entry, int line ) { - if( !entry.isEmpty() && !entry.startsWith( "#" ) ) { + private void parseConfigEntry(String entry, int line) { + if (!entry.isEmpty() && !entry.startsWith("#")) { String[] parts = entry.split("=", 2); - if( parts.length == 2 ) { + if (parts.length == 2) { //Recognise comments after a value String temp = parts[1].split(" #")[0]; - config.put( parts[0], temp); - }else{ + config.put(parts[0], temp); + } else { throw new RuntimeException("Syntax error in config file on line " + line + "!"); } } } - private SimpleConfig( ConfigRequest request ) { + private SimpleConfig(ConfigRequest request) { this.request = request; String identifier = "Config '" + request.filename + "'"; - if( !request.file.exists() ) { - ArduinoControls.LOGGER.info( identifier + " is missing, generating default one..." ); + if (!request.file.exists()) { + ArduinoControls.LOGGER.info(identifier + " is missing, generating default one..."); try { createConfig(); } catch (IOException e) { - ArduinoControls.LOGGER.error( identifier + " failed to generate!" ); + ArduinoControls.LOGGER.error(identifier + " failed to generate!"); ArduinoControls.LOGGER.trace(String.valueOf(e)); broken = true; } } - if( !broken ) { + if (!broken) { try { loadConfig(); } catch (Exception e) { - ArduinoControls.LOGGER.error( identifier + " failed to load!" ); + ArduinoControls.LOGGER.error(identifier + " failed to load!"); ArduinoControls.LOGGER.trace(String.valueOf(e)); broken = true; } @@ -165,21 +165,21 @@ public class SimpleConfig { * Queries a value from config, returns `null` if the * key does not exist. * - * @return value corresponding to the given key - * @see SimpleConfig#getOrDefault + * @return value corresponding to the given key + * @see SimpleConfig#getOrDefault */ @Deprecated - public String get( String key ) { - return config.get( key ); + public String get(String key) { + return config.get(key); } /** * Returns string value from config corresponding to the given * key, or the default string if the key is missing. * - * @return value corresponding to the given key, or the default value + * @return value corresponding to the given key, or the default value */ - public String getOrDefault( String key, String def ) { + public String getOrDefault(String key, String def) { String val = get(key); return val == null ? def : val; } @@ -188,11 +188,11 @@ public class SimpleConfig { * Returns integer value from config corresponding to the given * key, or the default integer if the key is missing or invalid. * - * @return value corresponding to the given key, or the default value + * @return value corresponding to the given key, or the default value */ - public int getOrDefault( String key, int def ) { + public int getOrDefault(String key, int def) { try { - return Integer.parseInt( get(key) ); + return Integer.parseInt(get(key)); } catch (Exception e) { return def; } @@ -202,11 +202,11 @@ public class SimpleConfig { * Returns boolean value from config corresponding to the given * key, or the default boolean if the key is missing. * - * @return value corresponding to the given key, or the default value + * @return value corresponding to the given key, or the default value */ - public boolean getOrDefault( String key, boolean def ) { + public boolean getOrDefault(String key, boolean def) { String val = get(key); - if( val != null ) { + if (val != null) { return val.equalsIgnoreCase("true"); } @@ -217,11 +217,11 @@ public class SimpleConfig { * Returns double value from config corresponding to the given * key, or the default string if the key is missing or invalid. * - * @return value corresponding to the given key, or the default value + * @return value corresponding to the given key, or the default value */ - public double getOrDefault( String key, double def ) { + public double getOrDefault(String key, double def) { try { - return Double.parseDouble( get(key) ); + return Double.parseDouble(get(key)); } catch (Exception e) { return def; } @@ -244,7 +244,7 @@ public class SimpleConfig { * @return true if the operation was successful */ public boolean delete() { - VerboseLogger.warn( "Config '" + request.filename + "' was removed from existence! Restart the game to regenerate it." ); + VerboseLogger.warn("Config '" + request.filename + "' was removed from existence! Restart the game to regenerate it."); return request.file.delete(); }