All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.softicar.platform.common.code.QualifiedNameParser Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
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);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy