Skip to content

Commit

Permalink
Use new methods to clean up a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kale-Ko committed Jan 4, 2025
1 parent 1be7f59 commit abb8162
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 309 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.github.kale_ko.ejcl.file.simple;

import com.fasterxml.jackson.core.io.BigDecimalParser;
import com.fasterxml.jackson.core.io.BigIntegerParser;
import io.github.kale_ko.bjsl.elements.ParsedElement;
import io.github.kale_ko.bjsl.elements.ParsedObject;
import io.github.kale_ko.bjsl.elements.ParsedPrimitive;
Expand All @@ -19,7 +17,7 @@
*
* @param <T> The type of the data being stored
*
* @version 5.0.0
* @version 5.1.0
* @since 3.9.0
*/
public class StructuredSimpleFileConfig<T> extends StructuredFileConfig<T> {
Expand Down Expand Up @@ -92,60 +90,7 @@ public void load(boolean save) throws IOException {
ParsedPrimitive.PrimitiveType primitiveType = ParsedPrimitive.PrimitiveType.valueOf(type);
String value = splitLine[2];

ParsedPrimitive element;
switch (primitiveType) {
case STRING: {
element = ParsedPrimitive.fromString(value);
break;
}
case BYTE: {
element = ParsedPrimitive.fromByte(Byte.parseByte(value));
break;
}
case CHAR: {
element = ParsedPrimitive.fromChar((char) Short.parseShort(value));
break;
}
case SHORT: {
element = ParsedPrimitive.fromShort(Short.parseShort(value));
break;
}
case INTEGER: {
element = ParsedPrimitive.fromInteger(Integer.parseInt(value));
break;
}
case LONG: {
element = ParsedPrimitive.fromLong(Long.parseLong(value));
break;
}
case BIGINTEGER: {
element = ParsedPrimitive.fromBigInteger(BigIntegerParser.parseWithFastParser(value));
break;
}
case FLOAT: {
element = ParsedPrimitive.fromFloat(Float.parseFloat(value));
break;
}
case DOUBLE: {
element = ParsedPrimitive.fromDouble(Double.parseDouble(value));
break;
}
case BIGDECIMAL: {
element = ParsedPrimitive.fromBigDecimal(BigDecimalParser.parse(value));
break;
}
case BOOLEAN: {
element = ParsedPrimitive.fromBoolean(Boolean.parseBoolean(value));
break;
}
case NULL: {
element = ParsedPrimitive.fromNull();
break;
}
default: {
throw new RuntimeException();
}
}
ParsedPrimitive element = ParsedPrimitive.from(ParsedPrimitive.fromString(value).to(primitiveType));

PathResolver.updateElement(object, path, element, true);
}
Expand Down Expand Up @@ -182,7 +127,7 @@ public void load(boolean save) throws IOException {
if (key.contains("=")) {
throw new IllegalArgumentException("Key cannot contain '='");
}
data.append(key).append("=").append(element.asPrimitive().getType().name()).append("=").append(!element.asPrimitive().isNull() ? element.asPrimitive().get().toString() : "null");
data.append(key).append("=").append(element.asPrimitive().getType().name()).append("=").append(!element.asPrimitive().isNull() ? element.asPrimitive().get().toString() : "null").append("\n");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.github.kale_ko.ejcl.file.simple;

import com.fasterxml.jackson.core.io.BigDecimalParser;
import com.fasterxml.jackson.core.io.BigIntegerParser;
import io.github.kale_ko.bjsl.elements.ParsedElement;
import io.github.kale_ko.bjsl.elements.ParsedObject;
import io.github.kale_ko.bjsl.elements.ParsedPrimitive;
Expand All @@ -17,7 +15,7 @@
/**
* A Simple Unstructured File Config for storing key/value pairs in a File
*
* @version 5.0.0
* @version 5.1.0
* @since 2.0.0
*/
public class UnstructuredSimpleFileConfig extends UnstructuredFileConfig {
Expand Down Expand Up @@ -80,60 +78,7 @@ public void load(boolean save) throws IOException {
ParsedPrimitive.PrimitiveType primitiveType = ParsedPrimitive.PrimitiveType.valueOf(type);
String value = splitLine[2];

ParsedPrimitive element;
switch (primitiveType) {
case STRING: {
element = ParsedPrimitive.fromString(value);
break;
}
case BYTE: {
element = ParsedPrimitive.fromByte(Byte.parseByte(value));
break;
}
case CHAR: {
element = ParsedPrimitive.fromChar((char) Short.parseShort(value));
break;
}
case SHORT: {
element = ParsedPrimitive.fromShort(Short.parseShort(value));
break;
}
case INTEGER: {
element = ParsedPrimitive.fromInteger(Integer.parseInt(value));
break;
}
case LONG: {
element = ParsedPrimitive.fromLong(Long.parseLong(value));
break;
}
case BIGINTEGER: {
element = ParsedPrimitive.fromBigInteger(BigIntegerParser.parseWithFastParser(value));
break;
}
case FLOAT: {
element = ParsedPrimitive.fromFloat(Float.parseFloat(value));
break;
}
case DOUBLE: {
element = ParsedPrimitive.fromDouble(Double.parseDouble(value));
break;
}
case BIGDECIMAL: {
element = ParsedPrimitive.fromBigDecimal(BigDecimalParser.parse(value));
break;
}
case BOOLEAN: {
element = ParsedPrimitive.fromBoolean(Boolean.parseBoolean(value));
break;
}
case NULL: {
element = ParsedPrimitive.fromNull();
break;
}
default: {
throw new RuntimeException();
}
}
ParsedPrimitive element = ParsedPrimitive.from(ParsedPrimitive.fromString(value).to(primitiveType));

this.config.set(path, element);
}
Expand Down Expand Up @@ -167,7 +112,7 @@ public void load(boolean save) throws IOException {
if (key.contains("=")) {
throw new IllegalArgumentException("Key cannot contain '='");
}
data.append(key).append("=").append(element.asPrimitive().getType().name()).append("=").append(!element.asPrimitive().isNull() ? element.asPrimitive().get().toString() : "null");
data.append(key).append("=").append(element.asPrimitive().getType().name()).append("=").append(!element.asPrimitive().isNull() ? element.asPrimitive().get().toString() : "null").append("\n");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.github.kale_ko.ejcl.mysql;

import com.fasterxml.jackson.core.io.BigDecimalParser;
import com.fasterxml.jackson.core.io.BigIntegerParser;
import io.github.kale_ko.bjsl.elements.ParsedElement;
import io.github.kale_ko.bjsl.elements.ParsedObject;
import io.github.kale_ko.bjsl.elements.ParsedPrimitive;
Expand Down Expand Up @@ -31,7 +29,7 @@
*
* @param <T> The type of the data being stored
*
* @version 5.0.1
* @version 5.1.0
* @since 1.0.0
*/
public class StructuredMySQLConfig<T> extends StructuredConfig<T> {
Expand Down Expand Up @@ -247,7 +245,7 @@ public void connect() throws IOException {

while (result.next()) {
String name = result.getString("Field");
if (name.equals("type")) {
if ("type".equals(name)) {
typeExists = true;
}
}
Expand Down Expand Up @@ -298,10 +296,6 @@ public void load(boolean save) throws IOException {
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}

if (this.reconnectAttempts > 5) {
throw new MaximumReconnectsException(e);
}
}

if (this.reconnectAttempts > 5) {
Expand All @@ -320,60 +314,7 @@ public void load(boolean save) throws IOException {
ParsedPrimitive.PrimitiveType primitiveType = ParsedPrimitive.PrimitiveType.valueOf(type);
String value = result.getString("value");

ParsedPrimitive element;
switch (primitiveType) {
case STRING: {
element = ParsedPrimitive.fromString(value);
break;
}
case BYTE: {
element = ParsedPrimitive.fromByte(Byte.parseByte(value));
break;
}
case CHAR: {
element = ParsedPrimitive.fromChar((char) Short.parseShort(value));
break;
}
case SHORT: {
element = ParsedPrimitive.fromShort(Short.parseShort(value));
break;
}
case INTEGER: {
element = ParsedPrimitive.fromInteger(Integer.parseInt(value));
break;
}
case LONG: {
element = ParsedPrimitive.fromLong(Long.parseLong(value));
break;
}
case BIGINTEGER: {
element = ParsedPrimitive.fromBigInteger(BigIntegerParser.parseWithFastParser(value));
break;
}
case FLOAT: {
element = ParsedPrimitive.fromFloat(Float.parseFloat(value));
break;
}
case DOUBLE: {
element = ParsedPrimitive.fromDouble(Double.parseDouble(value));
break;
}
case BIGDECIMAL: {
element = ParsedPrimitive.fromBigDecimal(BigDecimalParser.parse(value));
break;
}
case BOOLEAN: {
element = ParsedPrimitive.fromBoolean(Boolean.parseBoolean(value));
break;
}
case NULL: {
element = ParsedPrimitive.fromNull();
break;
}
default: {
throw new RuntimeException();
}
}
ParsedElement element = ParsedPrimitive.from(ParsedPrimitive.fromString(value).to(primitiveType));

PathResolver.updateElement(object, path, element, true);
}
Expand Down Expand Up @@ -418,10 +359,6 @@ public void save() throws IOException {
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}

if (this.reconnectAttempts > 5) {
throw new MaximumReconnectsException(e);
}
}

if (this.reconnectAttempts > 5) {
Expand Down Expand Up @@ -453,7 +390,7 @@ public void save() throws IOException {
if (!((value.isNull() && oldValue.isNull()) || (!value.isNull() && (valueObj == oldValueObj || valueObj.equals(oldValueObj))))) {
queryArgs.add(key);
queryArgs.add(value.getType().name());
queryArgs.add(valueObj != null ? valueObj.toString() : "null");
queryArgs.add(!value.isNull() ? valueObj.toString() : "null");
}
}
}
Expand Down
Loading

0 comments on commit abb8162

Please sign in to comment.