private String configProperty(String componentCode, Property<?> property) { return String.format("%s.%s", componentCode, property.getName()); }
/** * Includes the given property and its value in the builder, without Property-Value type-enforcement. * * @param property The property to set. * @param value The value of the property. * @return This instance. */ public ConfigBuilder<T> withUnsafe(Property<?> property, Object value) { String key = String.format("%s.%s", this.namespace, property.getName()); this.properties.setProperty(key, value.toString()); return this; }
/** * Includes the given property and its value in the builder. * * @param property The property to set. * @param value The value of the property. This must be of the same type as accepted by the Property. * In case a `null` value is sent, the value of the property will be set to empty string. * @param <V> Type of the property. * @return This instance. */ public <V> ConfigBuilder<T> with(Property<V> property, V value) { String key = String.format("%s.%s", this.namespace, property.getName()); this.properties.setProperty(key, value == null ? "" : value.toString()); return this; }
private static void printUsage() { System.out.println("SelfTest arguments (set via System Properties):"); System.out.println("- Any property defined in TestConfig or other *Config classes in SegmentStore."); System.out.println(String.format("- %s: Load up configuration from this file.", TestConfig.CONFIG_FILE_PROPERTY_NAME)); System.out.println("- Shortcuts:"); Shortcuts.forEach(s -> System.out.println(String.format("\t-%s: %s", s.key, s.property.getName()))); System.out.println("At least one shortcut or a reference to a config file is required for the test."); }
private <T> T tryGet(Property<T> property, Function<String, T> converter) { String fullKeyName = this.keyPrefix + property.getName(); // Get value from config. String value = this.properties.getProperty(fullKeyName, null); if (value == null) { // 2. Nothing in the configuration for this Property. if (property.hasDefaultValue()) { return property.getDefaultValue(); } else { throw new MissingPropertyException(fullKeyName); } } try { return converter.apply(value.trim()); } catch (IllegalArgumentException ex) { throw new InvalidPropertyValueException(fullKeyName, value, ex); } }