当前位置: 首页>>代码示例>>Java>>正文


Java SimpleCommentedConfigurationNode类代码示例

本文整理汇总了Java中ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode的典型用法代码示例。如果您正苦于以下问题:Java SimpleCommentedConfigurationNode类的具体用法?Java SimpleCommentedConfigurationNode怎么用?Java SimpleCommentedConfigurationNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SimpleCommentedConfigurationNode类属于ninja.leaping.configurate.commented包,在下文中一共展示了SimpleCommentedConfigurationNode类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: save

import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void save(@NotNull Object object) throws DataHandlingException {
    try {
        String header = getComments(object.getClass(), true);

        CommentedConfigurationNode node = SimpleCommentedConfigurationNode.root(ConfigurationOptions.defaults().setHeader(header));
        Object serialized = SerializableConfig.serialize(object, serializerSet);
        node = node.setValue(serialized);

        if (commentsEnabled) {
            node = addComments(FieldMapper.getFieldMap(object.getClass()), node);
        }

        getLoader().save(node);
    } catch (IOException e) {
        throw new DataHandlingException(e);
    }
}
 
开发者ID:dumptruckman,项目名称:dtmlibs,代码行数:20,代码来源:AbstractDataSource.java

示例2: getDefaultConfig

import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode; //导入依赖的package包/类
private ConfigurationNode getDefaultConfig() {
    CommentedConfigurationNode node = SimpleCommentedConfigurationNode.root();
    node.getNode("database-engine").setValue("sqlite").setComment("The DB engine to use. Valid options are \"sqlite\", \"h2\" and \"mysql\". The required JDBC driver must be on the classpath.");
    node.getNode("mysql").setComment("This section is only required if MySQL is selected for the database engine.");
    node.getNode("mysql", "host").setValue("localhost").setComment("The location of the database");
    node.getNode("mysql", "port").setValue(3306).setComment("The port for the database");
    node.getNode("mysql", "database").setValue("hammer").setComment("The name of the database to connect to.");
    node.getNode("mysql", "username").setValue("username").setComment("The username for the database connection");
    node.getNode("mysql", "password").setValue("password").setComment("The password for the database connection");
    node.getNode("server", "id").setValue(1).setComment("A unique integer id to represent this server");
    node.getNode("server", "name").setValue("New Server").setComment("A display name for this server when using Hammer");
    node.getNode("notifyAllOnBan").setValue(true).setComment("If set to false, only those with the 'hammer.notify' permission will be notified when someone is banned.");
    node.getNode("pollBans", "enable").setValue(true).setComment("If set to true, Hammer will check the database periodically to see if any online player have recieved a global ban and will ban them accordingly.");
    node.getNode("pollBans", "period").setValue(60).setComment("How often, in seconds, Hammer will check the database for new bans");
    node.getNode("audit").setComment("Whether or not an audit log should be kept.");
    node.getNode("audit", "database").setComment("Keep an audit log in the database.").setValue(true);
    node.getNode("audit", "flatfile").setComment("Keep an audit log in flat file.").setValue(false);
    node.getNode("appendBanReasons").setComment("If this is true, and a ban is applied on top of a previous (lesser) ban, the previous ban reason will be appeneded to the new one. " +
            "Otherwise, ban reasons will be replaced.").setValue(true);
    return node;
}
 
开发者ID:dualspiral,项目名称:Hammer,代码行数:22,代码来源:HammerConfiguration.java

示例3: save

import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode; //导入依赖的package包/类
/***
 * Saves the serialized config to file
 */
public void save() {
	try {
		SimpleCommentedConfigurationNode out = SimpleCommentedConfigurationNode.root();
		this.configMapper.serialize(out);
		this.loader.save(out);
	} catch (ObjectMappingException | IOException e) {
		logger.error(String.format("Failed to save config.\r\n %s", e.getMessage()));
	}
}
 
开发者ID:DevOnTheRocks,项目名称:StickyChunk,代码行数:13,代码来源:ConfigManager.java

示例4: testTestIsNotAltered

import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode; //导入依赖的package包/类
@Test
public void testTestIsNotAltered() throws Exception {
    System.setProperty("neutrino.test2", "true");
    CommentedConfigurationNode ccn = SimpleCommentedConfigurationNode.root();
    ccn.getNode("test").setValue("ok");
    ccn.getNode("def").setValue("ok");
    ccn.getNode("updated").setValue("ok");

    TestConf sut = NeutrinoObjectMapperFactory.getInstance().getMapper(TestConf.class).bindToNew().populate(ccn);
    Assert.assertEquals("not", sut.test);
    Assert.assertEquals("def", sut.def);
    Assert.assertEquals("ok", sut.updated);
}
 
开发者ID:NucleusPowered,项目名称:Neutrino,代码行数:14,代码来源:RequiresPropertyTests.java

示例5: testNodeIsNotAltered

import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode; //导入依赖的package包/类
@Test
public void testNodeIsNotAltered() throws Exception {
    System.setProperty("neutrino.test2", "true");
    CommentedConfigurationNode ccn = SimpleCommentedConfigurationNode.root();
    ccn.getNode("test").setValue("ok");
    ccn.getNode("def").setValue("ok");
    ccn.getNode("updated").setValue("ok");

    TestConf sut = new TestConf();
    NeutrinoObjectMapperFactory.getInstance().getMapper(TestConf.class).bind(sut).serialize(ccn);
    Assert.assertEquals("ok", ccn.getNode("test").getString());
    Assert.assertEquals("ok", ccn.getNode("def").getString());
    Assert.assertEquals("not", ccn.getNode("updated").getString());
}
 
开发者ID:NucleusPowered,项目名称:Neutrino,代码行数:15,代码来源:RequiresPropertyTests.java

示例6: NucleusMixinConfig

import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode; //导入依赖的package包/类
private NucleusMixinConfig() {
    Config config;
    try {
        Path path = Paths.get("config", "nucleus", "mixins.conf");
        ConfigurationLoader<CommentedConfigurationNode> ccn = HoconConfigurationLoader.builder().setPath(path).build();
        CommentedConfigurationNode node = ccn.load();
        node.mergeValuesFrom(SimpleCommentedConfigurationNode.root().setValue(TypeToken.of(Config.class), new Config()));
        ccn.save(node);
        config = node.getValue(TypeToken.of(Config.class));
    } catch (Exception e) {
        config = new Config();
    }

    this.config = config;
}
 
开发者ID:NucleusPowered,项目名称:NucleusMixins,代码行数:16,代码来源:NucleusMixinConfig.java

示例7: ConfigBase

import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode; //导入依赖的package包/类
/**
 * Creates a new config object.
 * 
 * @param path The config file path
 * @param options The config options
 */
public ConfigBase(Path path, ConfigurationOptions options, boolean hocon) throws IOException {
    this.hocon = hocon;
    this.loader = createConfigurationLoader(path, options, hocon);
    try {
        this.configMapper = ObjectMapper.forObject(this);
    } catch (ObjectMappingException e) {
        throw new IOException("Unable to create a config mapper for the object.", e);
    }
    this.root = SimpleCommentedConfigurationNode.root(options);
    this.options = options;
    this.path = path;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:19,代码来源:ConfigBase.java

示例8: testCommentsApplied

import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode; //导入依赖的package包/类
@Test
public void testCommentsApplied() throws ObjectMappingException {
    CommentedConfigurationNode node = SimpleCommentedConfigurationNode.root();
    ObjectMapper<CommentedObject>.BoundInstance mapper = ObjectMapper.forClass(CommentedObject.class).bindToNew();
    CommentedObject obj = mapper.populate(node);
    obj.color = "fuchsia";
    obj.politician = "All of them";
    mapper.serialize(node);
    assertEquals("You look nice today", node.getNode("commented-key").getComment().orElse(null));
    assertEquals("fuchsia", node.getNode("commented-key").getString());
    assertFalse(node.getNode("no-comment").getComment().isPresent());
}
 
开发者ID:SpongePowered,项目名称:configurate,代码行数:13,代码来源:ObjectMapperTest.java

示例9: testNestedObjectWithComments

import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode; //导入依赖的package包/类
@Test
public void testNestedObjectWithComments() throws ObjectMappingException {
    CommentedConfigurationNode node = SimpleCommentedConfigurationNode.root();
    final ObjectMapper<ParentObject>.BoundInstance mapper = ObjectMapper.forObject(new ParentObject());
    mapper.populate(node);
    assertEquals("Comment on parent", node.getNode("inner").getComment().get());
    assertTrue(node.getNode("inner").hasMapChildren());
    assertEquals("Default value", node.getNode("inner", "test").getString());
    assertEquals("Something", node.getNode("inner", "test").getComment().get());
}
 
开发者ID:SpongePowered,项目名称:configurate,代码行数:11,代码来源:ObjectMapperTest.java

示例10: SerializableTransform

import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode; //导入依赖的package包/类
public SerializableTransform(Transform<World> transform) {
    this.transform = transform;
    ConfigurationNode node = SimpleCommentedConfigurationNode.root();
    try {
        ts.serialize(TypeToken.of(Transform.class), transform, node);
    } catch (ObjectMappingException e) {
        //This should never happen
        e.printStackTrace();
    }
    this.node = node;
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:12,代码来源:SerializableTransform.java

示例11: save

import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode; //导入依赖的package包/类
public void save() {
    SpongeEmergencyWhitelist.instance().ifPresent(plugin -> {
        try {
            ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setFile(configFile).build();
            ConfigurationNode config = SimpleCommentedConfigurationNode.root();
            config.getNode(Config.ENABLED).setValue(whitelistEnabled);
            loader.save(config);
            reload();
        }
        catch (IOException e) {
            plugin.getLogger().error(Messages.fileCreateFailed(configFile));
        }
    });
}
 
开发者ID:Musician101,项目名称:EmergencyWhitelist,代码行数:15,代码来源:SpongeConfig.java

示例12: saveAdapterDefaults

import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode; //导入依赖的package包/类
/**
 * Saves default values from the adapter to the config file.
 *
 * @param processNoMergeIfPresent If <code>true</code>, {@link NoMergeIfPresent} annotations will be honoured.
 *
 * @throws IOException Thrown if the configuration could not be saved.
 */
public void saveAdapterDefaults(boolean processNoMergeIfPresent) throws IOException {
    CommentedConfigurationNode n = SimpleCommentedConfigurationNode.root();

    Stack<String> moduleStack = new Stack<>();
    List<Object[]> doNotMerge = Lists.newArrayList();
    moduleConfigAdapters.forEach((k, v) -> {

        // Configurate does something I wasn't expecting. If we set a single value with a key on a node, it seems
        // to be set as the root - which causes havoc! So, we get the parent if it exists, because that's the
        // actual null node we're interested in.
        ConfigurationNode cn = v.getDefaults();
        if (cn.getParent() != null) {
            cn = cn.getParent();
        }

        if (processNoMergeIfPresent) {
            if (v instanceof TypedAbstractConfigAdapter) {
                Object o = ((TypedAbstractConfigAdapter) v).getDefaultObject();
                getDoNotMerge(moduleStack, o.getClass(), doNotMerge);
            }

            if (!doNotMerge.isEmpty()) {
                for (Object[] keys : doNotMerge) {
                    ConfigurationNode toCheck = node.getNode(k).getNode((Object[])keys);
                    if (!toCheck.isVirtual() && toCheck.getValue() != null) {
                        cn.getNode((Object[])keys).setValue(null);
                        cn.getNode((Object[])keys).getParent().removeChild(keys[keys.length - 1]);
                    }
                }

                doNotMerge.clear();
            }
        }

        n.getNode(k.toLowerCase()).setValue(cn);
    });

    node.mergeValuesFrom(n);

    // Now, we do transformations.
    moduleConfigAdapters.forEach((k, v) -> {
        List<AbstractConfigAdapter.Transformation> transformations = v.getTransformations();
        if (!transformations.isEmpty() && v.isAttached()) {
            ConfigurationNode nodeToTransform = node.getNode(k.toLowerCase());

            if (!nodeToTransform.isVirtual()) {
                ConfigurationTransformation.Builder ctBuilder = ConfigurationTransformation.builder();
                transformations.forEach(x -> ctBuilder.addAction(x.getObjectPath(), x.getAction()));
                ctBuilder.build().apply(nodeToTransform);
                node.getNode(k.toLowerCase()).setValue(nodeToTransform);
            }
        }
    });

    save();
}
 
开发者ID:NucleusPowered,项目名称:QuickStartModuleLoader,代码行数:64,代码来源:AbstractAdaptableConfig.java

示例13: createEmptyNode

import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode; //导入依赖的package包/类
@Override
public CommentedConfigurationNode createEmptyNode(ConfigurationOptions options) {
    options = options.setAcceptedTypes(ImmutableSet.of(Map.class, List.class, Double.class, Float.class,
            Long.class, Integer.class, Boolean.class, String.class, byte[].class));
    return SimpleCommentedConfigurationNode.root(options);
}
 
开发者ID:SpongePowered,项目名称:configurate,代码行数:7,代码来源:JSONConfigurationLoader.java

示例14: createEmptyNode

import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode; //导入依赖的package包/类
@Override
public CommentedConfigurationNode createEmptyNode(ConfigurationOptions options) {
    options = options.setAcceptedTypes(ImmutableSet.of(Map.class, List.class, Double.class,
            Long.class, Integer.class, Boolean.class, String.class, Number.class));
    return SimpleCommentedConfigurationNode.root(options);
}
 
开发者ID:SpongePowered,项目名称:configurate,代码行数:7,代码来源:HoconConfigurationLoader.java


注:本文中的ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。