Class ConfigurationPropertyName
java.lang.Object
org.springframework.boot.context.properties.source.ConfigurationPropertyName
- All Implemented Interfaces:
Comparable<ConfigurationPropertyName>
public final class ConfigurationPropertyName
extends Object
implements Comparable<ConfigurationPropertyName>
A configuration property name composed of elements separated by dots. User created
names may contain the characters "
a-z
" "0-9
") and "-
", they
must be lower-case and must start with an alpha-numeric character. The "-
" is
used purely for formatting, i.e. "foo-bar
" and "foobar
" are considered
equivalent.
The "[
" and "]
" characters may be used to indicate an associative
index(i.e. a Map
key or a Collection
index). Indexes names are not
restricted and are considered case-sensitive.
Here are some typical examples:
spring.main.banner-mode
server.hosts[0].name
log[org.springboot].level
- Since:
- 2.0.0
- Author:
- Phillip Webb, Madhura Bhave
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
The various forms that a non-indexed element value can take. -
Field Summary
Modifier and TypeFieldDescriptionstatic final ConfigurationPropertyName
An emptyConfigurationPropertyName
. -
Method Summary
Modifier and TypeMethodDescriptionstatic ConfigurationPropertyName
adapt
(CharSequence name, char separator) Create aConfigurationPropertyName
by adapting the given source.Create a newConfigurationPropertyName
by appending the given suffix.append
(ConfigurationPropertyName suffix) Create a newConfigurationPropertyName
by appending the given suffix.chop
(int size) Return a newConfigurationPropertyName
by chopping this name to the givensize
.int
boolean
getElement
(int elementIndex, ConfigurationPropertyName.Form form) Return an element in the name in the given form.Return the last element in the name in the given form.int
Return the total number of elements in the name.Return the parent of thisConfigurationPropertyName
orEMPTY
if there is no parent.int
hashCode()
boolean
Returntrue
if any element in the name is indexed.boolean
Returnstrue
if this element is an ancestor (immediate or nested parent) of the specified name.boolean
isEmpty()
Returnstrue
if thisConfigurationPropertyName
is empty.boolean
Return if the last element in the name is indexed.boolean
isNumericIndex
(int elementIndex) Return if the element in the name is indexed and numeric.boolean
Returnstrue
if this element is an immediate parent of the specified name.static boolean
isValid
(CharSequence name) Returns if the given name is valid.static ConfigurationPropertyName
of
(CharSequence name) Return aConfigurationPropertyName
for the specified string.static ConfigurationPropertyName
ofIfValid
(CharSequence name) Return aConfigurationPropertyName
for the specified string ornull
if the name is not valid.subName
(int offset) Return a newConfigurationPropertyName
by based on this name offset by specific element index.toString()
-
Field Details
-
EMPTY
An emptyConfigurationPropertyName
.
-
-
Method Details
-
isEmpty
public boolean isEmpty()Returnstrue
if thisConfigurationPropertyName
is empty.- Returns:
true
if the name is empty
-
isLastElementIndexed
public boolean isLastElementIndexed()Return if the last element in the name is indexed.- Returns:
true
if the last element is indexed
-
hasIndexedElement
public boolean hasIndexedElement()Returntrue
if any element in the name is indexed.- Returns:
- if the element has one or more indexed elements
- Since:
- 2.2.10
-
isNumericIndex
public boolean isNumericIndex(int elementIndex) Return if the element in the name is indexed and numeric.- Parameters:
elementIndex
- the index of the element- Returns:
true
if the element is indexed and numeric
-
getLastElement
Return the last element in the name in the given form.- Parameters:
form
- the form to return- Returns:
- the last element
-
getElement
Return an element in the name in the given form.- Parameters:
elementIndex
- the element indexform
- the form to return- Returns:
- the last element
-
getNumberOfElements
public int getNumberOfElements()Return the total number of elements in the name.- Returns:
- the number of elements
-
append
Create a newConfigurationPropertyName
by appending the given suffix.- Parameters:
suffix
- the elements to append- Returns:
- a new
ConfigurationPropertyName
- Throws:
InvalidConfigurationPropertyNameException
- if the result is not valid
-
append
Create a newConfigurationPropertyName
by appending the given suffix.- Parameters:
suffix
- the elements to append- Returns:
- a new
ConfigurationPropertyName
- Since:
- 2.5.0
-
getParent
Return the parent of thisConfigurationPropertyName
orEMPTY
if there is no parent.- Returns:
- the parent name
-
chop
Return a newConfigurationPropertyName
by chopping this name to the givensize
. For example,chop(1)
on the namefoo.bar
will returnfoo
.- Parameters:
size
- the size to chop- Returns:
- the chopped name
-
subName
Return a newConfigurationPropertyName
by based on this name offset by specific element index. For example,chop(1)
on the namefoo.bar
will returnbar
.- Parameters:
offset
- the element offset- Returns:
- the sub name
- Since:
- 2.5.0
-
isParentOf
Returnstrue
if this element is an immediate parent of the specified name.- Parameters:
name
- the name to check- Returns:
true
if this name is an ancestor
-
isAncestorOf
Returnstrue
if this element is an ancestor (immediate or nested parent) of the specified name.- Parameters:
name
- the name to check- Returns:
true
if this name is an ancestor
-
compareTo
- Specified by:
compareTo
in interfaceComparable<ConfigurationPropertyName>
-
equals
-
hashCode
public int hashCode() -
toString
-
isValid
Returns if the given name is valid. If this method returnstrue
then the name may be used withof(CharSequence)
without throwing an exception.- Parameters:
name
- the name to test- Returns:
true
if the name is valid
-
of
Return aConfigurationPropertyName
for the specified string.- Parameters:
name
- the source name- Returns:
- a
ConfigurationPropertyName
instance - Throws:
InvalidConfigurationPropertyNameException
- if the name is not valid
-
ofIfValid
Return aConfigurationPropertyName
for the specified string ornull
if the name is not valid.- Parameters:
name
- the source name- Returns:
- a
ConfigurationPropertyName
instance - Since:
- 2.3.1
-
adapt
Create aConfigurationPropertyName
by adapting the given source. Seeadapt(CharSequence, char, Function)
for details.- Parameters:
name
- the name to parseseparator
- the separator used to split the name- Returns:
- a
ConfigurationPropertyName
-