Skip to content

Commit

Permalink
Merge pull request #63 from A5H73Y/master
Browse files Browse the repository at this point in the history
Small performance improvements
  • Loading branch information
KotlinFactory authored Nov 12, 2021
2 parents 94aa30d + 3581c1b commit 0883de1
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 47 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
<artifactId>lombok</artifactId>
<groupId>org.projectlombok</groupId>
<scope>provided</scope>
<version>1.18.20</version>
<version>1.18.22</version>
</dependency>

<!-- JetBrains Annotations -->
Expand All @@ -166,7 +166,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.0</version>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/de/leonhard/storage/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
@SuppressWarnings({"unused"})
public class Config extends Yaml {

private List<String> header;

public Config(@NonNull final Config config) {
super(config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ default <T> T getOrSetDefault(final String key, final T def) {
set(key, def);
return def;
} else {
return (T) ClassWrapper.getFromDef(raw, def);
return ClassWrapper.getFromDef(raw, def);
}
}
}
17 changes: 8 additions & 9 deletions src/main/java/de/leonhard/storage/internal/FileData.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,13 @@ public Set<String> keySet(final String key) {
*/
private Set<String> multiLayerKeySet(final Map<String, Object> map) {
final Set<String> out = new HashSet<>();
for (final String key : map.keySet()) {
if (map.get(key) instanceof Map) {
for (final String tempKey : multiLayerKeySet(
(Map<String, Object>) map.get(key))) {
out.add(key + "." + tempKey);
for (final Map.Entry<String, Object> entry : map.entrySet()) {
if (entry.getValue() instanceof Map) {
for (final String tempKey : multiLayerKeySet((Map<String, Object>) entry.getValue())) {
out.add(entry.getKey() + "." + tempKey);
}
} else {
out.add(key);
out.add(entry.getKey());
}
}
return out;
Expand Down Expand Up @@ -307,9 +306,9 @@ public void putAll(final Map<String, Object> map) {

private int size(final Map<String, Object> map) {
int size = map.size();
for (final String key : map.keySet()) {
if (map.get(key) instanceof Map) {
size += size((Map<String, Object>) map.get(key));
for (final Map.Entry<String, Object> entry : map.entrySet()) {
if (entry.getValue() instanceof Map) {
size += size((Map<String, Object>) entry.getValue());
}
}
return size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,9 @@ private Map<String, Object> nextTableContent() {
}

private Object nextNumberOrDate(final char first) {
boolean maybeDouble = true, maybeInteger = true, maybeDate = true;
boolean maybeDouble = true;
boolean maybeInteger = true;
boolean maybeDate = true;
final StringBuilder sb = new StringBuilder();
sb.append(first);
char c;
Expand Down Expand Up @@ -614,7 +616,8 @@ private String nextBasicString() {

private String nextBasicMultilineString() {
final StringBuilder sb = new StringBuilder();
boolean first = true, escape = false;
boolean first = true;
boolean escape = false;
while (hasNext()) {
final char c = next();
if (first && (c == '\r' || c == '\n')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,39 @@ public class LightningProviders {
private ExceptionHandler exceptionHandler;

public MapProvider mapProvider() {

if (mapProvider != null) {
return mapProvider;
if (mapProvider == null) {
mapProvider = new MapProvider() {};
}

return mapProvider = new MapProvider() {
};
return mapProvider;
}

public YamlConfig yamlConfig() {
if (yamlConfig != null) {
return yamlConfig;
if (yamlConfig == null) {
final YamlConfig config = new YamlConfig();
// Use unicode
config.writeConfig.setEscapeUnicode(false);
// Don't use anchors
config.writeConfig.setAutoAnchor(false);
// Never use write the classname above keys
config.writeConfig.setWriteClassname(YamlConfig.WriteClassName.NEVER);
yamlConfig = config;
}
final YamlConfig config = new YamlConfig();
// Use unicode
config.writeConfig.setEscapeUnicode(false);
// Don't use anchors
config.writeConfig.setAutoAnchor(false);
// Never use write the classname above keys
config.writeConfig.setWriteClassname(YamlConfig.WriteClassName.NEVER);
return yamlConfig = config;
return yamlConfig;
}

public InputStreamProvider inputStreamProvider() {
if (inputStreamProvider != null) {
return inputStreamProvider;
if (inputStreamProvider == null) {
inputStreamProvider = new InputStreamProvider() {};
}

return inputStreamProvider = new InputStreamProvider() {
};
return inputStreamProvider;
}

public ExceptionHandler exceptionHandler() {
if (exceptionHandler != null) {
return exceptionHandler;
if (exceptionHandler == null) {
exceptionHandler = new ExceptionHandler() {};
}

return exceptionHandler = new ExceptionHandler() {
};
return exceptionHandler;
}
}
1 change: 0 additions & 1 deletion src/main/java/de/leonhard/storage/util/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/de/leonhard/storage/ConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void testSet() {

@AfterAll
@Test
static void tearDown() {
void tearDown() {
config.clear();
Assertions.assertTrue(config.getFile().delete());
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/de/leonhard/storage/JsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void testSet() {

@AfterAll
@Test
static void tearDown() {
void tearDown() {
json.clear();
Assertions.assertTrue(json.getFile().delete());
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/de/leonhard/storage/TomlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void setUp() {

@Test
void testGetDataType() {
Assertions.assertEquals(toml.getDataType(), DataType.SORTED);
Assertions.assertEquals(DataType.SORTED, toml.getDataType());
}

@Test
Expand Down Expand Up @@ -69,7 +69,7 @@ void testSet() {

@AfterAll
@Test
static void tearDown() {
void tearDown() {
toml.clear();
Assertions.assertTrue(toml.getFile().delete());
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/de/leonhard/storage/YamlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void setUp() {

@Test
void testGetDataType() {
Assertions.assertEquals(yaml.getDataType(), DataType.SORTED);
Assertions.assertEquals(DataType.SORTED, yaml.getDataType());
}

@Test
Expand Down Expand Up @@ -79,7 +79,7 @@ void testSet() {

@AfterAll
@Test
static void tearDown() {
void tearDown() {
yaml.clear();
Assertions.assertTrue(yaml.getFile().delete());
}
Expand Down

0 comments on commit 0883de1

Please sign in to comment.