- Converting to new repo

This commit is contained in:
2025-09-24 21:20:00 +02:00
parent d94e8dd8b9
commit f7c3654f02
87 changed files with 905 additions and 279 deletions

View File

@@ -0,0 +1,127 @@
/*
* Copyright (C) 2025 UnlegitDqrk - All Rights Reserved
*
* You are unauthorized to remove this copyright.
* You have to give Credits to the Author in your project and link this GitHub site: https://github.com/UnlegitDqrk
* See LICENSE-File if exists
*/
package dev.unlegitdqrk.unlegitlibrary.file;
import dev.unlegitdqrk.unlegitlibrary.utils.DefaultMethodsOverrider;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
public class ConfigurationManager extends DefaultMethodsOverrider {
private final Properties properties = new Properties();
private final File configFile;
public ConfigurationManager(File configFile) {
this.configFile = configFile;
}
public final boolean isSet(String key) {
return properties.containsKey(key);
}
public final void loadProperties() throws IOException {
try (FileInputStream in = new FileInputStream(configFile)) {
properties.load(in);
}
}
public final void saveProperties() throws IOException {
try (FileOutputStream out = new FileOutputStream(configFile)) {
properties.store(out, null);
}
}
public final long getLong(String key) {
return Long.parseLong(properties.getProperty(key));
}
public final double getDouble(String key) {
return Double.parseDouble(properties.getProperty(key));
}
public final float getFloat(String key) {
return Float.parseFloat(properties.getProperty(key));
}
public final int getInt(String key) {
return Integer.parseInt(properties.getProperty(key));
}
public final Object getObject(String key) {
return properties.getProperty(key);
}
public Map<String, String> getMap(String key) {
String value = properties.getProperty(key);
Map<String, String> map = new HashMap<>();
if (value != null) {
String[] entries = value.split(",");
for (String entry : entries) {
String[] pair = entry.split("=");
if (pair.length == 2) map.put(pair[0], pair[1]);
}
}
return map;
}
public final String getString(String key) {
return properties.getProperty(key);
}
public final List<String> getList(String key) {
String value = properties.getProperty(key);
if (value != null) return Arrays.asList(value.split(","));
else return new ArrayList<>();
}
public final void set(String key, long value) {
properties.setProperty(key, String.valueOf(value));
}
public final void set(String key, int value) {
properties.setProperty(key, String.valueOf(value));
}
public final void set(String key, double value) {
properties.setProperty(key, String.valueOf(value));
}
public final void set(String key, float value) {
properties.setProperty(key, String.valueOf(value));
}
public final void set(String key, Object value) {
properties.setProperty(key, String.valueOf(value));
}
public final void set(String key, String value) {
properties.setProperty(key, value);
}
public final void set(String key, Map<String, String> map) {
String value = map.entrySet().stream()
.map(entry -> entry.getKey() + "=" + entry.getValue())
.collect(Collectors.joining(","));
properties.setProperty(key, value);
}
public final void set(String key, List<String> list) {
String value = list.stream().collect(Collectors.joining(","));
properties.setProperty(key, value);
}
}