Skip to content

Commit

Permalink
raw value as String
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Nov 1, 2024
1 parent 8929929 commit 3cec9ae
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

public interface FlatNumberEntryConverter<K> extends FlatEntryConverter<K, Double> {
@Override
default Double toValue(Object object) {
default Double toValue(String object) {
try {
return Double.parseDouble(String.valueOf(object));
return Double.parseDouble(object);
} catch (Exception e) {
return null;
}
}

@Override
default Object toRawValue(Double object) {
return object;
default String toRawValue(Double object) {
return Double.toString(object);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public interface FlatEntryConverter<K, V> {

String toRawKey(K key);

V toValue(Object object);
V toValue(String value);

Object toRawValue(V object);
String toRawValue(V object);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.hsgamer.topper.agent.storage.simple.supplier;

import me.hsgamer.topper.agent.storage.DataStorage;
import me.hsgamer.topper.core.DataHolder;

public interface DataStorageSupplier<K, V> {
DataStorage<K, V> getStorage(String name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Map<K, V> load() {
Map<K, V> map = new HashMap<>();
properties.forEach((key, value) -> {
K k = converter.toKey(key.toString());
V v = converter.toValue(value);
V v = converter.toValue(value.toString());
map.put(k, v);
});
return map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import me.hsgamer.hscore.logger.provider.LoggerProvider;
import me.hsgamer.topper.agent.storage.DataStorage;
import me.hsgamer.topper.agent.storage.simple.converter.SqlEntryConverter;
import me.hsgamer.topper.core.DataHolder;
import org.intellij.lang.annotations.Language;

import java.sql.Connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Map<K, V> load() {
Map<String[], Object> values = config.getValues(false);
Map<K, V> map = new HashMap<>();
values.forEach((path, value) -> {
V finalValue = converter.toValue(value);
V finalValue = converter.toValue(String.valueOf(value));
if (finalValue != null) {
K finalKey = converter.toKey(path[0]);
map.put(finalKey, finalValue);
Expand All @@ -69,7 +69,7 @@ public CompletableFuture<Void> save(Map<K, V> map, boolean urgent) {
@Override
public CompletableFuture<Optional<V>> load(K key, boolean urgent) {
return CompletableFuture.supplyAsync(
() -> Optional.ofNullable(config.get(converter.toRawKey(key))).map(converter::toValue),
() -> Optional.ofNullable(config.get(converter.toRawKey(key))).map(String::valueOf).map(converter::toValue),
urgent ? Runnable::run : mainThreadExecutor
);
}
Expand Down

0 comments on commit 3cec9ae

Please sign in to comment.