com.softicar.platform.common.code.QualifiedNameParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.code;
import java.util.ArrayList;
import java.util.List;
public class QualifiedNameParser {
private final String delimiter;
private List segments;
public QualifiedNameParser() {
this(QualifiedName.DEFAULT_DELIMITER);
}
public QualifiedNameParser(String delimiter) {
this.delimiter = delimiter;
if (delimiter.isEmpty()) {
throw new IllegalArgumentException("The delimiter may not be empty.");
}
}
public QualifiedName parse(String canonicalName) {
return new QualifiedName(parseSegments(canonicalName));
}
public List parseSegments(String canonicalName) {
this.segments = new ArrayList<>();
int startIndex = 0;
while (startIndex <= canonicalName.length()) {
int delimiterIndex = canonicalName.indexOf(delimiter, startIndex);
if (delimiterIndex < 0) {
delimiterIndex = canonicalName.length();
}
addSegment(canonicalName.substring(startIndex, delimiterIndex));
startIndex = delimiterIndex + delimiter.length();
}
return segments;
}
private void addSegment(String segment) {
segments.add(segment);
}
}