-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b0acec
commit 8e6693f
Showing
3 changed files
with
76 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package turniplabs.halplibe.util; | ||
|
||
import turniplabs.halplibe.util.toml.Toml; | ||
|
||
import java.util.HashMap; | ||
|
||
/** | ||
* Mainly | ||
*/ | ||
public abstract class ConfigUpdater { | ||
Toml updating; | ||
|
||
public static ConfigUpdater fromProperties( | ||
String... text | ||
) { | ||
TomlConverter converter = new TomlConverter(); | ||
for (int i = 0; i < text.length; i += 2) { | ||
converter.conversions.put( | ||
text[i], text[i + 1] | ||
); | ||
} | ||
return converter; | ||
} | ||
|
||
public abstract void update(); | ||
|
||
private static class TomlConverter extends ConfigUpdater { | ||
HashMap<String, String> conversions = new HashMap<>(); | ||
|
||
@Override | ||
public void update() { | ||
// if it's a toml, then there's no point in updating | ||
for (String orderedKey : updating.getOrderedKeys()) { | ||
if (orderedKey.startsWith(".")) | ||
return; | ||
} | ||
|
||
for (String s : conversions.keySet()) { | ||
String str = updating.get(s).toString(); | ||
updating.remove(s); | ||
updating.addEntry(conversions.get(s), str); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters