|
|
|
@ -20,8 +20,10 @@ import java.util.ArrayList; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Locale; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.function.Function; |
|
|
|
import java.util.function.Function; |
|
|
|
|
|
|
|
import java.util.function.IntFunction; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
@ -63,10 +65,14 @@ public final class ConfigurationPropertyName implements Comparable<Configuration |
|
|
|
|
|
|
|
|
|
|
|
private final CharSequence[] uniformElements; |
|
|
|
private final CharSequence[] uniformElements; |
|
|
|
|
|
|
|
|
|
|
|
private String string; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int hashCode; |
|
|
|
private int hashCode; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String[] string = new String[ToStringFormat.values().length]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Boolean hasDashedElement; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ConfigurationPropertyName systemEnvironmentLegacyName; |
|
|
|
|
|
|
|
|
|
|
|
private ConfigurationPropertyName(Elements elements) { |
|
|
|
private ConfigurationPropertyName(Elements elements) { |
|
|
|
this.elements = elements; |
|
|
|
this.elements = elements; |
|
|
|
this.uniformElements = new CharSequence[elements.getSize()]; |
|
|
|
this.uniformElements = new CharSequence[elements.getSize()]; |
|
|
|
@ -525,15 +531,41 @@ public final class ConfigurationPropertyName implements Comparable<Configuration |
|
|
|
return hashCode; |
|
|
|
return hashCode; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ConfigurationPropertyName asSystemEnvironmentLegacyName() { |
|
|
|
|
|
|
|
ConfigurationPropertyName name = this.systemEnvironmentLegacyName; |
|
|
|
|
|
|
|
if (name == null) { |
|
|
|
|
|
|
|
name = ConfigurationPropertyName |
|
|
|
|
|
|
|
.ofIfValid(buildSimpleToString('.', (i) -> getElement(i, Form.DASHED).replace('-', '.'))); |
|
|
|
|
|
|
|
this.systemEnvironmentLegacyName = (name != null) ? name : EMPTY; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return (name != EMPTY) ? name : null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
public String toString() { |
|
|
|
if (this.string == null) { |
|
|
|
return toString(ToStringFormat.DEFAULT); |
|
|
|
this.string = buildToString(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return this.string; |
|
|
|
|
|
|
|
|
|
|
|
String toString(ToStringFormat format) { |
|
|
|
|
|
|
|
String string = this.string[format.ordinal()]; |
|
|
|
|
|
|
|
if (string == null) { |
|
|
|
|
|
|
|
string = buildToString(format); |
|
|
|
|
|
|
|
this.string[format.ordinal()] = string; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return string; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String buildToString(ToStringFormat format) { |
|
|
|
|
|
|
|
return switch (format) { |
|
|
|
|
|
|
|
case DEFAULT -> buildDefaultToString(); |
|
|
|
|
|
|
|
case SYSTEM_ENVIRONMENT -> |
|
|
|
|
|
|
|
buildSimpleToString('_', (i) -> getElement(i, Form.UNIFORM).toUpperCase(Locale.ENGLISH)); |
|
|
|
|
|
|
|
case LEGACY_SYSTEM_ENVIRONMENT -> buildSimpleToString('_', |
|
|
|
|
|
|
|
(i) -> getElement(i, Form.ORIGINAL).replace('-', '_').toUpperCase(Locale.ENGLISH)); |
|
|
|
|
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String buildToString() { |
|
|
|
private String buildDefaultToString() { |
|
|
|
if (this.elements.canShortcutWithSource(ElementType.UNIFORM, ElementType.DASHED)) { |
|
|
|
if (this.elements.canShortcutWithSource(ElementType.UNIFORM, ElementType.DASHED)) { |
|
|
|
return this.elements.getSource().toString(); |
|
|
|
return this.elements.getSource().toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -556,6 +588,32 @@ public final class ConfigurationPropertyName implements Comparable<Configuration |
|
|
|
return result.toString(); |
|
|
|
return result.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String buildSimpleToString(char joinChar, IntFunction<String> elementConverter) { |
|
|
|
|
|
|
|
StringBuilder result = new StringBuilder(); |
|
|
|
|
|
|
|
for (int i = 0; i < getNumberOfElements(); i++) { |
|
|
|
|
|
|
|
if (!result.isEmpty()) { |
|
|
|
|
|
|
|
result.append(joinChar); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
result.append(elementConverter.apply(i)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return result.toString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean hasDashedElement() { |
|
|
|
|
|
|
|
Boolean hasDashedElement = this.hasDashedElement; |
|
|
|
|
|
|
|
if (hasDashedElement != null) { |
|
|
|
|
|
|
|
return hasDashedElement; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 0; i < getNumberOfElements(); i++) { |
|
|
|
|
|
|
|
if (getElement(i, Form.DASHED).indexOf('-') != -1) { |
|
|
|
|
|
|
|
this.hasDashedElement = true; |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.hasDashedElement = false; |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns if the given name is valid. If this method returns {@code true} then the |
|
|
|
* Returns if the given name is valid. If this method returns {@code true} then the |
|
|
|
* name may be used with {@link #of(CharSequence)} without throwing an exception. |
|
|
|
* name may be used with {@link #of(CharSequence)} without throwing an exception. |
|
|
|
@ -1132,4 +1190,13 @@ public final class ConfigurationPropertyName implements Comparable<Configuration |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Formats for {@code toString}. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
enum ToStringFormat { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFAULT, SYSTEM_ENVIRONMENT, LEGACY_SYSTEM_ENVIRONMENT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|