ElementsParser Class — spring-boot Architecture
Architecture documentation for the ElementsParser class in ConfigurationPropertyName.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java lines 983–1142
private static class ElementsParser {
private static final int DEFAULT_CAPACITY = 6;
private final CharSequence source;
private final char separator;
private int size;
private int[] start;
private int[] end;
private ElementType[] type;
private CharSequence @Nullable [] resolved;
ElementsParser(CharSequence source, char separator) {
this(source, separator, DEFAULT_CAPACITY);
}
ElementsParser(CharSequence source, char separator, int capacity) {
this.source = source;
this.separator = separator;
this.start = new int[capacity];
this.end = new int[capacity];
this.type = new ElementType[capacity];
}
Elements parse() {
return parse(null);
}
Elements parse(@Nullable Function<CharSequence, CharSequence> valueProcessor) {
int length = this.source.length();
int openBracketCount = 0;
int start = 0;
ElementType type = ElementType.EMPTY;
for (int i = 0; i < length; i++) {
char ch = this.source.charAt(i);
if (ch == '[') {
if (openBracketCount == 0) {
add(start, i, type, valueProcessor);
start = i + 1;
type = ElementType.NUMERICALLY_INDEXED;
}
openBracketCount++;
}
else if (ch == ']') {
openBracketCount--;
if (openBracketCount == 0) {
add(start, i, type, valueProcessor);
start = i + 1;
type = ElementType.EMPTY;
}
}
else if (!type.isIndexed() && ch == this.separator) {
add(start, i, type, valueProcessor);
start = i + 1;
type = ElementType.EMPTY;
}
else {
type = updateType(type, ch, i - start);
}
}
if (openBracketCount != 0) {
type = ElementType.NON_UNIFORM;
}
add(start, length, type, valueProcessor);
return new Elements(this.source, this.size, this.start, this.end, this.type, null, this.resolved);
}
private ElementType updateType(ElementType existingType, char ch, int index) {
if (existingType.isIndexed()) {
if (existingType == ElementType.NUMERICALLY_INDEXED && !isNumeric(ch)) {
return ElementType.INDEXED;
}
return existingType;
}
if (existingType == ElementType.EMPTY && isValidChar(ch, index)) {
return (index == 0) ? ElementType.UNIFORM : ElementType.NON_UNIFORM;
}
if (existingType == ElementType.UNIFORM && ch == '-') {
return ElementType.DASHED;
}
if (!isValidChar(ch, index)) {
if (existingType == ElementType.EMPTY && !isValidChar(Character.toLowerCase(ch), index)) {
return ElementType.EMPTY;
}
return ElementType.NON_UNIFORM;
}
return existingType;
}
private void add(int start, int end, ElementType type,
@Nullable Function<CharSequence, CharSequence> valueProcessor) {
if ((end - start) < 1 || type == ElementType.EMPTY) {
return;
}
if (this.start.length == this.size) {
this.start = expand(this.start);
this.end = expand(this.end);
this.type = expand(this.type);
this.resolved = expand(this.resolved);
}
if (valueProcessor != null) {
if (this.resolved == null) {
this.resolved = new CharSequence[this.start.length];
}
CharSequence resolved = valueProcessor.apply(this.source.subSequence(start, end));
Elements resolvedElements = new ElementsParser(resolved, '.').parse();
Assert.state(resolvedElements.getSize() == 1, "Resolved element must not contain multiple elements");
this.resolved[this.size] = resolvedElements.get(0);
type = resolvedElements.getType(0);
}
this.start[this.size] = start;
this.end[this.size] = end;
this.type[this.size] = type;
this.size++;
}
private int[] expand(int[] src) {
int[] dest = new int[src.length + DEFAULT_CAPACITY];
System.arraycopy(src, 0, dest, 0, src.length);
return dest;
}
private ElementType[] expand(ElementType[] src) {
ElementType[] dest = new ElementType[src.length + DEFAULT_CAPACITY];
System.arraycopy(src, 0, dest, 0, src.length);
return dest;
}
private CharSequence @Nullable [] expand(CharSequence @Nullable [] src) {
if (src == null) {
return null;
}
CharSequence[] dest = new CharSequence[src.length + DEFAULT_CAPACITY];
System.arraycopy(src, 0, dest, 0, src.length);
return dest;
}
static boolean isValidChar(char ch, int index) {
return isAlpha(ch) || isNumeric(ch) || (index != 0 && ch == '-');
}
static boolean isAlphaNumeric(char ch) {
return isAlpha(ch) || isNumeric(ch);
}
private static boolean isAlpha(char ch) {
return ch >= 'a' && ch <= 'z';
}
private static boolean isNumeric(char ch) {
return ch >= '0' && ch <= '9';
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free