/** * Return an empty node of the most appropriate type for this loader, using the default options. * * @return The appropriate node type */ default NodeType createEmptyNode() { return createEmptyNode(getDefaultOptions()); }
/** * Return an empty node of the most appropriate type for this loader, using the default options. * * @return The appropriate node type */ @NonNull default NodeType createEmptyNode() { return createEmptyNode(getDefaultOptions()); }
/** * Return an empty node of the most appropriate type for this loader, using the default options. * * @return The appropriate node type */ @NonNull default NodeType createEmptyNode() { return createEmptyNode(getDefaultOptions()); }
public static <T extends BaseConfig> T load(Path path, T defaultConfig) { ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder() .setPath(path) .build(); CommentedConfigurationNode node; try { node = loader.load(); } catch (IOException e) { e.printStackTrace(); node = loader.createEmptyNode(); } T config = null; try { config = (T)node.getValue(TypeToken.of(defaultConfig.getClass())); } catch (ObjectMappingException e) { e.printStackTrace(); } if (config == null) { config = defaultConfig; } config.setLoader(loader); config.setNode(node); config.save(); return config; } }
@Test @Disabled("Gson currently makes it rather difficult to get the correct number type") public void testRoundtrippingLong(@TempDirectory.TempDir Path tempDir) throws IOException { final Path tempFile = tempDir.resolve("text5.txt"); ConfigurationLoader<ConfigurationNode> loader = GsonConfigurationLoader.builder().setPath(tempFile).build(); ConfigurationNode start = loader.createEmptyNode(); start.getNode("long-num").setValue(TEST_LONG_VAL); loader.save(start); System.out.println(Files.readAllLines(tempFile)); ConfigurationNode ret = loader.load(); System.out.println(ret.getNode("long-num").getValue().getClass()); assertEquals(TEST_LONG_VAL, ret.getNode("long-num").getValue()); } }
private void testRoundtripValue(Path tempDir, Object value) throws IOException { final Path tempFile = tempDir.resolve("text2.txt"); ConfigurationLoader<ConfigurationNode> loader = JSONConfigurationLoader.builder().setPath(tempFile).build(); ConfigurationNode start = loader.createEmptyNode(); start.getNode("value").setValue(value); loader.save(start); ConfigurationNode ret = loader.load(); assertEquals(value, ret.getNode("value").getValue()); }
defaultConfig.getParentFile().mkdirs(); defaultConfig.createNewFile(); rootNode = configManager.createEmptyNode(ConfigurationOptions.defaults()); Prism.getInstance().getLogger().info("Creating new config at mods/Prism/Prism.conf"); } else {