本文整理汇总了Java中org.apache.commons.lang3.builder.ToStringBuilder.setDefaultStyle方法的典型用法代码示例。如果您正苦于以下问题:Java ToStringBuilder.setDefaultStyle方法的具体用法?Java ToStringBuilder.setDefaultStyle怎么用?Java ToStringBuilder.setDefaultStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.builder.ToStringBuilder
的用法示例。
在下文中一共展示了ToStringBuilder.setDefaultStyle方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTypes
import org.apache.commons.lang3.builder.ToStringBuilder; //导入方法依赖的package包/类
@Test
public void testTypes() throws Exception
{
SerializationTest.prepareSerialization();
ToStringBuilder.setDefaultStyle(ToStringStyle.SHORT_PREFIX_STYLE);
ConfigTemplate<TypeTestConfig> configTemplate = this.configManager.getConfigFile(TypeTestConfig.class);
Assert.assertNotNull(configTemplate);
Assert.assertEquals(TypeTestConfig.class.getSimpleName(), configTemplate.getName());
Assert.assertEquals(StandardCharsets.UTF_8, configTemplate.getDefaultDecoder().charset());
Assert.assertEquals(StandardCharsets.UTF_8, configTemplate.getDefaultEncoder().charset());
System.out.println("[ConfigTypeTest] creating config instance.");
TypeTestConfig cfg = configTemplate.create();
Assert.assertNotNull(cfg);
Assert.assertSame(1, cfg.getCopyTest()[0]);
cfg.getCopyTest()[0] = 2;
Assert.assertSame(1, cfg.getCopyTest()[0]);
Assert.assertSame(1, cfg.getNonCopyTest()[0]);
cfg.getNonCopyTest()[0] = 2;
Assert.assertSame(2, cfg.getNonCopyTest()[0]);
cfg.save(System.out);
// check if all data is still valid after reload of config.
StringBuilderWriter writer = new StringBuilderWriter(500);
cfg.save(writer);
Files.write(new File("target/yaml-test-file.yml").toPath(), writer.toString().getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
TypeTestConfig cfgCopy = configTemplate.create();
cfg.forEach(cfgCopy::set);
cfgCopy.bindFile(new File("target/yaml-test-file.yml"));
cfgCopy.save();
cfgCopy.load();
cfgCopy.save();
cfgCopy.load();
cfgCopy.bindFile(null);
Assert.assertEquals(cfg, cfgCopy);
}
示例2: contextInitialized
import org.apache.commons.lang3.builder.ToStringBuilder; //导入方法依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
ToStringBuilder.setDefaultStyle(ToStringStyle.SHORT_PREFIX_STYLE);
DOMConfigurator.configure("../data/conf/log4j.xml");
}
示例3: test
import org.apache.commons.lang3.builder.ToStringBuilder; //导入方法依赖的package包/类
public void test() throws Exception
{
SerializationTest.prepareSerialization();
ToStringBuilder.setDefaultStyle(ToStringStyle.SHORT_PREFIX_STYLE);
ConfigTemplate<SomeConfig> configTemplate = this.configManager.getConfigFile(SomeConfig.class);
Assert.assertNotNull(configTemplate);
Assert.assertEquals(SomeConfig.class.getSimpleName(), configTemplate.getName());
Assert.assertEquals(StandardCharsets.UTF_8, configTemplate.getDefaultDecoder().charset());
Assert.assertEquals(StandardCharsets.UTF_8, configTemplate.getDefaultEncoder().charset());
System.out.println("[ConfigTest] creating config instance.");
SomeConfig someConfig = configTemplate.create();
Assert.assertNotNull(someConfig);
//
this.testNicknames(someConfig);
Assert.assertNotNull(someConfig.getSpecialData());
someConfig.setStorage(SerializationTest.prepareObject());
//
someConfig.save(System.out);
//
// try
// {
// someConfig.getSpecialData().clear();
// Assert.assertTrue("This should never happen, special data should be immutable.", false);
// }
// catch (UnsupportedOperationException e)
// {
// }
// MetaObject snowflake = new MetaObject("snowflake", new MetaValue("so special", 25));
// someConfig.putInSpecialData(snowflake);
// Assert.assertEquals(List.of(snowflake), someConfig.getSpecialData());
//
// UUID randomUUID = UUID.randomUUID();
// someConfig.putInEvenMoreSpecialData(randomUUID, snowflake);
// Assert.assertEquals(1, someConfig.getEvenMoreSpecialData().size());
//
// System.out.println("\n====================\n");
// someConfig.save(System.out);
//
// Assert.assertEquals(snowflake, someConfig.removeFromEvenMoreSpecialData(randomUUID));
// Assert.assertTrue(someConfig.getEvenMoreSpecialData().isEmpty());
//
//
// // check if all data is still valid after reload of config.
// StringBuilderWriter writer = new StringBuilderWriter(500);
// someConfig.save(writer);
// Assert.assertEquals(someConfig, configTemplate.load(new StringReader(writer.toString())));
}
示例4: test
import org.apache.commons.lang3.builder.ToStringBuilder; //导入方法依赖的package包/类
@Test
public void test() throws Exception
{
SerializationTest.prepareSerialization();
ToStringBuilder.setDefaultStyle(ToStringStyle.SHORT_PREFIX_STYLE);
ConfigTemplate<SomeConfigNoSpecial> configTemplate = this.configManager.getConfigFile(SomeConfigNoSpecial.class);
Assert.assertNotNull(configTemplate);
Assert.assertEquals(SomeConfigNoSpecial.class.getSimpleName(), configTemplate.getName());
Assert.assertEquals(StandardCharsets.UTF_8, configTemplate.getDefaultDecoder().charset());
Assert.assertEquals(StandardCharsets.UTF_8, configTemplate.getDefaultEncoder().charset());
System.out.println("[ConfigTest] creating config instance.");
SomeConfigNoSpecial someConfig = configTemplate.create();
Assert.assertNotNull(someConfig);
this.testNicknames(someConfig);
Assert.assertNotNull(someConfig.getSpecialData());
someConfig.setStorage(SerializationTest.prepareObject());
someConfig.save(System.out);
try
{
someConfig.getSpecialData().clear();
Assert.assertTrue("This should never happen, special data should be immutable.", false);
}
catch (UnsupportedOperationException e)
{
}
MetaObject snowflake = new MetaObject("snowflake", new MetaValue("so special", 25));
someConfig.putInSpecialData(snowflake);
Assert.assertEquals(ImmutableList.of(snowflake), someConfig.getSpecialData());
UUID randomUUID = UUID.randomUUID();
someConfig.putInEvenMoreSpecialData(randomUUID, snowflake);
Assert.assertEquals(1, someConfig.getEvenMoreSpecialData().size());
System.out.println("\n====================\n");
someConfig.save(System.out);
Assert.assertEquals(snowflake, someConfig.removeFromEvenMoreSpecialData(randomUUID));
Assert.assertTrue(someConfig.getEvenMoreSpecialData().isEmpty());
// check if all data is still valid after reload of config.
StringBuilderWriter writer = new StringBuilderWriter(500);
someConfig.save(writer);
Assert.assertEquals(someConfig, configTemplate.load(new StringReader(writer.toString())));
}
示例5: test
import org.apache.commons.lang3.builder.ToStringBuilder; //导入方法依赖的package包/类
@Test
public void test() throws Exception
{
SerializationTest.prepareSerialization();
ToStringBuilder.setDefaultStyle(ToStringStyle.SHORT_PREFIX_STYLE);
ConfigTemplate<SomeConfig> configTemplate = this.configManager.getConfigFile(SomeConfig.class);
Assert.assertNotNull(configTemplate);
Assert.assertEquals(SomeConfig.class.getSimpleName(), configTemplate.getName());
Assert.assertEquals(StandardCharsets.UTF_8, configTemplate.getDefaultDecoder().charset());
Assert.assertEquals(StandardCharsets.UTF_8, configTemplate.getDefaultEncoder().charset());
System.out.println("[ConfigTest] creating config instance.");
SomeConfig someConfig = configTemplate.create();
Assert.assertNotNull(someConfig);
Assert.assertNull(someConfig.metadata().get("meta"));
Assert.assertEquals("1", someConfig.getSomething());
Assert.assertNull(someConfig.get("something"));
Assert.assertEquals("meta value", someConfig.metadata().get("meta"));
Assert.assertNotNull(someConfig.getEnumValue());
someConfig.setEnumValue(TestEnum.C);
Assert.assertSame(TestEnum.C, someConfig.getEnumValue());
this.testNicknames(someConfig);
Assert.assertNotNull(someConfig.getSpecialData());
someConfig.setStorage(SerializationTest.prepareObject());
someConfig.save(System.out);
try
{
someConfig.getSpecialData().clear();
Assert.assertTrue("This should never happen, special data should be immutable.", false);
}
catch (UnsupportedOperationException e)
{
}
MetaObject snowflake = new MetaObject("snowflake", new MetaValue("so special", 25));
someConfig.putInSpecialData(snowflake);
Assert.assertEquals(ImmutableList.of(snowflake), someConfig.getSpecialData());
UUID randomUUID = UUID.randomUUID();
someConfig.putInEvenMoreSpecialData(randomUUID, snowflake);
Assert.assertEquals(1, someConfig.getEvenMoreSpecialData().size());
System.out.println("\n====================\n");
someConfig.save(System.out);
Assert.assertEquals(snowflake, someConfig.removeFromEvenMoreSpecialData(randomUUID));
Assert.assertTrue(someConfig.getEvenMoreSpecialData().isEmpty());
someConfig.putInEvenMoreSpecialData(randomUUID, snowflake);
Assert.assertEquals(1, someConfig.getEvenMoreSpecialData().size());
Assert.assertTrue(someConfig.removeFromEvenMoreSpecialDataIf((key, value) -> key.equals(randomUUID)));
Assert.assertTrue(someConfig.getEvenMoreSpecialData().isEmpty());
someConfig.putInEvenMoreSpecialData(randomUUID, snowflake);
Assert.assertEquals(1, someConfig.getEvenMoreSpecialData().size());
Assert.assertTrue(someConfig.removeFromEvenMoreSpecialDataIf((key, value) -> value.equals(snowflake)));
Assert.assertTrue(someConfig.getEvenMoreSpecialData().isEmpty());
someConfig.putInEvenMoreSpecialData(randomUUID, snowflake);
Assert.assertEquals(1, someConfig.getEvenMoreSpecialData().size());
Assert.assertTrue(someConfig.removeFromEvenMoreSpecialDataIf((entry) -> entry.getValue().equals(snowflake)));
Assert.assertTrue(someConfig.getEvenMoreSpecialData().isEmpty());
someConfig.putInEvenMoreSpecialData(randomUUID, snowflake);
Assert.assertEquals(1, someConfig.getEvenMoreSpecialData().size());
someConfig.putInEvenMoreSpecialData(randomUUID, snowflake);
Assert.assertEquals(1, someConfig.getEvenMoreSpecialData().size());
// check if all data is still valid after reload of config.
StringBuilderWriter writer = new StringBuilderWriter(500);
someConfig.save(writer);
Assert.assertEquals(someConfig, configTemplate.load(new StringReader(writer.toString())));
}