ConfigurationPropertyName class final

A property name split into its elements (app, read-timeout) and compared the relaxed way, so app.readTimeout, app.read_timeout and app.read-timeout are the same name.

Config files, environment variables and command lines spell the same property differently, and @ConfigurationProperties binding must still match them to one field. The binder and the config data loader compare names through this class. Applications do not use it; it is for code that walks the configuration itself, such as a starter that binds a map of clients by name.

Canonical names (ConfigurationPropertyName.of) are lower case with - between words and [index] for list elements and map keys: app.read-timeout, app.hosts[0].name, app.headers[X-Shop]. Names as they appear in property sources are read with ConfigurationPropertyName.adapt. Outside [...], comparison ignores case and every character that is not a letter or digit; [...] elements compare exactly, and a.b.0 equals a.b[0].

final name = ConfigurationPropertyName.of('app.read-timeout');
name == ConfigurationPropertyName.adapt('app.readTimeout', '.'); // true
ConfigurationPropertyName.of('app').isParentOf(name); // true
ConfigurationPropertyName.isValid('app.readTimeout'); // false

Spring (Java):

var name = ConfigurationPropertyName.of("app.read-timeout");
name.equals(ConfigurationPropertyName.adapt("app.readTimeout", '.'));
ConfigurationPropertyName.of("app").isParentOf(name);
ConfigurationPropertyName.isValid("app.readTimeout"); // false

Constructors

ConfigurationPropertyName.adapt(String name, String separator)
Reads name as a source wrote it, split at separator and at [...]. Any case and any character is accepted; elements without a letter or digit are dropped. Use it for keys found in property sources, which need not be canonical.
factory
ConfigurationPropertyName.of(String name)
Parses name, which must be canonical, such as a prefix written in code. Throws InvalidConfigurationPropertyNameException when it is not: upper-case letters, _, a leading or trailing ., an empty element, unbalanced brackets. The empty string is the empty name.
factory

Properties

hashCode → int
The hash code for this object.
no setteroverride
isEmpty → bool
Whether this is the empty name.
no setter
isLastElementIndexed → bool
Whether the last element was written in brackets.
no setter
numberOfElements → int
How many elements the name has (app.hosts[0] has three).
no setter
parent → ConfigurationPropertyName
The name without its last element (empty for a single element).
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

append(String suffix) → ConfigurationPropertyName
A new name: this one followed by suffix, a canonical name or an [index]. Throws InvalidConfigurationPropertyNameException for a suffix that is not canonical.
chop(int size) → ConfigurationPropertyName
A new name with only the first size elements (this name when it has no more).
getElement(int index, {ConfigurationPropertyNameForm form = ConfigurationPropertyNameForm.original}) → String
The text of the element at index in the given form (as written unless given). A [...] element is returned as written, without the brackets.
isAncestorOf(ConfigurationPropertyName name) → bool
Whether name is below this name at any depth: app is an ancestor of app.db.port.
isIndexed(int index) → bool
Whether the element at index was written in brackets (a list index or a map key).
isNumericIndex(int index) → bool
Whether the element at index is a bracketed list index of digits only, such as [0].
isParentOf(ConfigurationPropertyName name) → bool
Whether name is this name plus exactly one element: app is the parent of app.port, not of app.db.port.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
The canonical text: elements in the dashed form joined with ., bracketed elements in brackets (app.read-timeout, app.hosts[0]).
override

Operators

operator ==(Object other) → bool
Whether other has the same elements, compared the relaxed way: case and non-alphanumeric characters ignored outside brackets, exact inside them.
override

Static Properties

empty → ConfigurationPropertyName
The name with no elements, the root above every property.
final

Static Methods

isValid(String name) → bool
Whether name is canonical, so ConfigurationPropertyName.of accepts it.
ofIfValid(String name) → ConfigurationPropertyName?
Parses name like ConfigurationPropertyName.of, but returns null instead of throwing when it is not canonical.