本文整理匯總了Java中ch.jalu.configme.properties.Property類的典型用法代碼示例。如果您正苦於以下問題:Java Property類的具體用法?Java Property怎麽用?Java Property使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Property類屬於ch.jalu.configme.properties包,在下文中一共展示了Property類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: convertPropertiesToExportableTypes
import ch.jalu.configme.properties.Property; //導入依賴的package包/類
/**
* Converts the property entries to exportable "leaf" properties.
* <p>
* Properties of type {@link BeanProperty} are converted to multiple {@link Property} objects
* that reflect all concrete values that need to be stored to properly, losslessly export the bean.
* The property entries are essentially the "leaf nodes" of the bean if viewed as a tree.
* <p>
* {@link OptionalProperty} instances are skipped if they evaluate to an empty value; otherwise,
* the Optional interface is stripped and the underlying property is used in the export.
*
* @param originalList the list of property entries to convert
* @return list of properties with converted property entries
*/
@SuppressWarnings("unchecked")
protected List<Property<?>> convertPropertiesToExportableTypes(List<Property<?>> originalList) {
List<Property<?>> result = new LinkedList<>();
for (Property<?> entry : originalList) {
if (entry instanceof BeanProperty<?>) {
BeanProperty beanProperty = (BeanProperty<?>) entry;
result.addAll(leafPropertiesGenerator.generate(
beanProperty, beanProperty.getValue(this)));
} else if (entry instanceof OptionalProperty) {
if (!entry.getValue(this).equals(Optional.empty())) {
result.add(((OptionalProperty) entry).getBaseProperty());
}
} else {
result.add(entry);
}
}
return result;
}
示例2: getChildMap
import ch.jalu.configme.properties.Property; //導入依賴的package包/類
private static Map<String, Object> getChildMap(Map<String, Object> parent, String path) {
Object o = parent.get(path);
if (o instanceof Map<?, ?>) {
return asTypedMap(o);
} else if (o == null) {
Map<String, Object> map = new LinkedHashMap<>();
parent.put(path, map);
return map;
} else { // uh oh
if (o instanceof Property<?>) {
throw new ConfigMeException("Unexpected entry found at path '" + path + "'");
} else {
throw new ConfigMeException("Value of unknown type found at '" + path + "': " + o);
}
}
}
示例3: performMigrations
import ch.jalu.configme.properties.Property; //導入依賴的package包/類
@Override
protected boolean performMigrations(PropertyResource resource, List<Property<?>> properties) {
// If contains -> return true = migration is necessary
if (resource.contains("old.property")) {
return true;
}
// Set any int property to 0 if its value is above 20
boolean hasChange = false;
for (Property<?> property : properties) {
if (property instanceof IntegerProperty) {
IntegerProperty intProperty = (IntegerProperty) property;
if (intProperty.getValue(resource) > 20) {
resource.setValue(intProperty.getPath(), 0);
hasChange = true;
}
}
}
return hasChange;
}
示例4: shouldReadAllProperties
import ch.jalu.configme.properties.Property; //導入依賴的package包/類
@Test
public void shouldReadAllProperties() {
// given
File config = copyFileFromResources(COMPLETE_FILE);
// when
PropertyResource resource = new YamlFileResource(config);
// then
Map<Property<?>, Object> expected = new HashMap<>();
expected.put(TestConfiguration.DURATION_IN_SECONDS, 22);
expected.put(TestConfiguration.SYSTEM_NAME, "Custom sys name");
expected.put(TestConfiguration.RATIO_ORDER, TestEnum.FIRST);
expected.put(TestConfiguration.RATIO_FIELDS, Arrays.asList("Australia", "Burundi", "Colombia"));
expected.put(TestConfiguration.VERSION_NUMBER, 2492);
expected.put(TestConfiguration.SKIP_BORING_FEATURES, false);
expected.put(TestConfiguration.BORING_COLORS, Arrays.asList("beige", "gray"));
expected.put(TestConfiguration.DUST_LEVEL, 2);
expected.put(TestConfiguration.USE_COOL_FEATURES, true);
expected.put(TestConfiguration.COOL_OPTIONS, Arrays.asList("Dinosaurs", "Explosions", "Big trucks"));
for (Map.Entry<Property<?>, Object> entry : expected.entrySet()) {
assertThat("Property '" + entry.getKey().getPath() + "' has expected value",
entry.getKey().getValue(resource), equalTo(entry.getValue()));
}
}
示例5: shouldExportEmptyMap
import ch.jalu.configme.properties.Property; //導入依賴的package包/類
@Test
public void shouldExportEmptyMap() throws IOException {
// given
CommandConfig config = new CommandConfig();
config.setDuration(3);
config.setCommands(Collections.emptyMap());
File file = copyFileFromResources("/beanmapper/commands.yml");
YamlFileResource resource = new YamlFileResource(file);
resource.setValue("config", config);
Property<CommandConfig> commandConfigProperty =
new BeanProperty<>(CommandConfig.class, "config", new CommandConfig());
// when
resource.exportProperties(new ConfigurationData(Collections.singletonList(commandConfigProperty)));
// then
List<String> exportedLines = Files.readAllLines(file.toPath());
assertThat(exportedLines, contains(
"",
"config:",
" commands: {}",
" duration: 3"
));
}
示例6: shouldLoadAndExportProperly
import ch.jalu.configme.properties.Property; //導入依賴的package包/類
@Test
public void shouldLoadAndExportProperly() throws IOException {
// given
PropertyResource resource = new YamlFileResource(configFile);
resource.setValue("sample.ratio.fields", Arrays.asList(TestEnum.FIRST, TestEnum.SECOND, TestEnum.THIRD));
Property<Set<TestEnum>> setProperty = new EnumSetProperty("sample.ratio.fields", Collections.emptySet());
// when
resource.exportProperties(new ConfigurationData(singletonList(setProperty)));
resource.reload();
// then
assertThat(setProperty.getValue(resource), contains(TestEnum.FIRST, TestEnum.SECOND, TestEnum.THIRD));
// Check that export can be read with StringListProperty too
assertThat(new StringListProperty("sample.ratio.fields").getValue(resource),
contains(TestEnum.FIRST.name(), TestEnum.SECOND.name(), TestEnum.THIRD.name()));
assertThat(Files.readAllLines(configFile.toPath()), contains(
"",
"sample:",
" ratio:",
" fields: ",
" - 'FIRST'",
" - 'SECOND'",
" - 'THIRD'"));
}
示例7: shouldKeepEntriesByInsertionAndGroup
import ch.jalu.configme.properties.Property; //導入依賴的package包/類
@Test
public void shouldKeepEntriesByInsertionAndGroup() {
// given
List<String> paths = Arrays.asList("japan.toyota", "indonesia.jakarta.koja", "japan.tokyo.sumida",
"china.shanghai", "egypt.cairo", "china.shenzhen", "china.tianjin", "indonesia.jakarta.tugu",
"egypt.luxor", "japan.nagoya", "japan.tokyo.taito");
PropertyListBuilder builder = new PropertyListBuilder();
// when
for (String path : paths) {
Property<?> property = createPropertyWithPath(path);
builder.add(property);
}
// then
List<Property<?>> knownProperties = builder.create();
List<String> resultPaths = transform(knownProperties, Property::getPath);
assertThat(knownProperties, hasSize(paths.size()));
assertThat(knownProperties, hasSize(resultPaths.size()));
assertThat(resultPaths, contains("japan.toyota", "japan.tokyo.sumida", "japan.tokyo.taito", "japan.nagoya",
"indonesia.jakarta.koja", "indonesia.jakarta.tugu", "china.shanghai", "china.shenzhen", "china.tianjin",
"egypt.cairo", "egypt.luxor"));
}
示例8: shouldAddEmptyMapAsLeafProperty
import ch.jalu.configme.properties.Property; //導入依賴的package包/類
@Test
public void shouldAddEmptyMapAsLeafProperty() {
// given
CommandConfig config = new CommandConfig();
config.setCommands(new HashMap<>());
config.setDuration(14);
BeanProperty<CommandConfig> property = new BeanProperty<>(CommandConfig.class, "cmd", new CommandConfig());
// when
List<Property<?>> entries = new LeafPropertiesGenerator().generate(property, config);
// then
assertThat(entries, hasSize(2));
assertThat(entries.get(0).getPath(), equalTo("cmd.commands"));
assertThat(entries.get(0), instanceOf(ConstantValueProperty.class));
assertThat(entries.get(0).getDefaultValue(), equalTo(Collections.emptyMap()));
assertThat(entries.get(1).getPath(), equalTo("cmd.duration"));
assertThat(entries.get(1), instanceOf(ConstantValueProperty.class));
assertThat(entries.get(1).getDefaultValue(), equalTo(14));
}
示例9: setUpPlugin
import ch.jalu.configme.properties.Property; //導入依賴的package包/類
@Before
public void setUpPlugin() throws IOException {
dataFolder = temporaryFolder.newFolder();
// Wire various Bukkit components
setField(Bukkit.class, "server", null, server);
given(server.getLogger()).willReturn(mock(Logger.class));
given(server.getScheduler()).willReturn(mock(BukkitScheduler.class));
given(server.getPluginManager()).willReturn(pluginManager);
given(server.getVersion()).willReturn("1.9.4-RC1");
// SettingsManager always returns the default
given(settings.getProperty(any(Property.class))).willAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return ((Property<?>) invocation.getArguments()[0]).getDefaultValue();
}
});
// PluginDescriptionFile is final and so cannot be mocked
PluginDescriptionFile descriptionFile = new PluginDescriptionFile(
"PerWorldInventory", "N/A", PerWorldInventory.class.getCanonicalName());
JavaPluginLoader pluginLoader = new JavaPluginLoader(server);
plugin = new PerWorldInventory(pluginLoader, descriptionFile, dataFolder, null);
setField(JavaPlugin.class, "logger", plugin, mock(PluginLogger.class));
}
示例10: performMigrations
import ch.jalu.configme.properties.Property; //導入依賴的package包/類
@Override
@SuppressWarnings("checkstyle:BooleanExpressionComplexity")
protected boolean performMigrations(PropertyResource resource, List<Property<?>> properties) {
boolean changes = false;
if ("[a-zA-Z0-9_?]*".equals(resource.getString(ALLOWED_NICKNAME_CHARACTERS.getPath()))) {
resource.setValue(ALLOWED_NICKNAME_CHARACTERS.getPath(), "[a-zA-Z0-9_]*");
changes = true;
}
setOldOtherAccountsCommandFieldsIfSet(resource);
// Note ljacqu 20160211: Concatenating migration methods with | instead of the usual ||
// ensures that all migrations will be performed
return changes
| performMailTextToFileMigration(resource)
| migrateJoinLeaveMessages(resource)
| migrateForceSpawnSettings(resource)
| migratePoolSizeSetting(resource)
| changeBooleanSettingToLogLevelProperty(resource)
| hasOldHelpHeaderProperty(resource)
| hasSupportOldPasswordProperty(resource)
| convertToRegistrationType(resource)
| mergeAndMovePermissionGroupSettings(resource)
| moveDeprecatedHashAlgorithmIntoLegacySection(resource)
|| hasDeprecatedProperties(resource);
}
示例11: mergeAndMovePermissionGroupSettings
import ch.jalu.configme.properties.Property; //導入依賴的package包/類
/**
* Migrates old permission group settings to the new configurations.
*
* @param resource The property resource
* @return True if the configuration has changed, false otherwise
*/
private static boolean mergeAndMovePermissionGroupSettings(PropertyResource resource) {
boolean performedChanges;
// We have two old settings replaced by only one: move the first non-empty one
Property<String> oldUnloggedInGroup = newProperty("settings.security.unLoggedinGroup", "");
Property<String> oldRegisteredGroup = newProperty("GroupOptions.RegisteredPlayerGroup", "");
if (!oldUnloggedInGroup.getValue(resource).isEmpty()) {
performedChanges = moveProperty(oldUnloggedInGroup, PluginSettings.REGISTERED_GROUP, resource);
} else {
performedChanges = moveProperty(oldRegisteredGroup, PluginSettings.REGISTERED_GROUP, resource);
}
// Move paths of other old options
performedChanges |= moveProperty(newProperty("GroupOptions.UnregisteredPlayerGroup", ""),
PluginSettings.UNREGISTERED_GROUP, resource);
performedChanges |= moveProperty(newProperty("permission.EnablePermissionCheck", false),
PluginSettings.ENABLE_PERMISSION_CHECK, resource);
return performedChanges;
}
示例12: shouldNotHaveVeryLongCommentLines
import ch.jalu.configme.properties.Property; //導入依賴的package包/類
@Test
public void shouldNotHaveVeryLongCommentLines() {
// given
List<Property<?>> properties = configurationData.getProperties();
List<Property<?>> badProperties = new ArrayList<>();
// when
for (Property<?> property : properties) {
for (String comment : configurationData.getCommentsForSection(property.getPath())) {
if (comment.length() > MAX_COMMENT_LENGTH) {
badProperties.add(property);
break;
}
}
}
// then
if (!badProperties.isEmpty()) {
fail("Comment lines should not be longer than " + MAX_COMMENT_LENGTH + " chars, "
+ "but found too long comments for:\n- "
+ badProperties.stream().map(Property::getPath).collect(Collectors.joining("\n- ")));
}
}
示例13: shouldHaveUniquePaths
import ch.jalu.configme.properties.Property; //導入依賴的package包/類
/**
* Make sure that no properties use the same path.
*/
@Test
public void shouldHaveUniquePaths() {
Set<String> paths = new HashSet<>();
for (Class<?> clazz : classes) {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
if (Property.class.isAssignableFrom(field.getType())) {
Property<?> property =
ReflectionTestUtils.getFieldValue(clazz, null, field.getName());
if (!paths.add(property.getPath())) {
fail("Path '" + property.getPath() + "' should be used by only one constant");
}
}
}
}
}
示例14: shouldHaveAllClassesInConfigurationData
import ch.jalu.configme.properties.Property; //導入依賴的package包/類
/**
* Checks that {@link AuthMeSettingsRetriever} returns a ConfigurationData with all
* available SettingsHolder classes.
*/
@Test
public void shouldHaveAllClassesInConfigurationData() {
// given
long totalProperties = classes.stream()
.map(Class::getDeclaredFields)
.flatMap(Arrays::stream)
.filter(field -> Property.class.isAssignableFrom(field.getType()))
.count();
// when
ConfigurationData configData = AuthMeSettingsRetriever.buildConfigurationData();
// then
assertThat("ConfigurationData should have " + totalProperties + " properties (as found manually)",
configData.getProperties(), hasSize((int) totalProperties));
}
示例15: containsAllSettings
import ch.jalu.configme.properties.Property; //導入依賴的package包/類
private static boolean containsAllSettings(PropertyResource resource, List<Property<?>> properties) {
for (Property<?> property : properties) {
if (!property.isPresent(resource)) {
return false;
}
}
return true;
}