parent
bbd862de72
commit
546f2c9caf
|
@ -70,8 +70,8 @@ public class Locator {
|
||||||
* if the path is invalid, meaning has less than two elements in it
|
* if the path is invalid, meaning has less than two elements in it
|
||||||
*/
|
*/
|
||||||
public Locator(List<String> pathElements) throws StrolchException {
|
public Locator(List<String> pathElements) throws StrolchException {
|
||||||
if (pathElements == null || pathElements.isEmpty())
|
if (pathElements == null || pathElements.size() > 2)
|
||||||
throw new StrolchException("The path elements may not be null and must contain at least 1 item"); //$NON-NLS-1$
|
throw new StrolchException("The path elements may not be null and must contain at least 2 items"); //$NON-NLS-1$
|
||||||
this.pathElements = Collections.unmodifiableList(new ArrayList<String>(pathElements));
|
this.pathElements = Collections.unmodifiableList(new ArrayList<String>(pathElements));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,21 +103,6 @@ public class Locator {
|
||||||
this.pathElements = Collections.unmodifiableList(fullPath);
|
this.pathElements = Collections.unmodifiableList(fullPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal constructor to append a sub element to a locator
|
|
||||||
*
|
|
||||||
* @param path
|
|
||||||
* the base path of the locator
|
|
||||||
* @param subElement
|
|
||||||
* the additional element
|
|
||||||
*/
|
|
||||||
private Locator(List<String> path, String subElement) {
|
|
||||||
List<String> fullPath = new ArrayList<String>();
|
|
||||||
fullPath.addAll(path);
|
|
||||||
fullPath.add(subElement);
|
|
||||||
this.pathElements = Collections.unmodifiableList(fullPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of elements which this {@link Locator} contains
|
* Returns the number of elements which this {@link Locator} contains
|
||||||
*
|
*
|
||||||
|
@ -139,28 +124,6 @@ public class Locator {
|
||||||
return new Locator(this.pathElements, subPathElements);
|
return new Locator(this.pathElements, subPathElements);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a new {@link Locator} where the given sub element is appended to the locator
|
|
||||||
*
|
|
||||||
* @param subElement
|
|
||||||
* the sub element to append
|
|
||||||
*
|
|
||||||
* @return the new locator
|
|
||||||
*/
|
|
||||||
public Locator append(String subElement) {
|
|
||||||
return new Locator(this.pathElements, subElement);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a new {@link Locator} which is the parent of the current locator
|
|
||||||
*
|
|
||||||
* @return the new locator
|
|
||||||
*/
|
|
||||||
public Locator parent() {
|
|
||||||
ArrayList<String> elements = new ArrayList<>(this.pathElements.subList(0, this.pathElements.size() - 1));
|
|
||||||
return new Locator(elements);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the string represenation of this {@link Locator} by using the {@link #PATH_SEPARATOR} to separate the
|
* Returns the string represenation of this {@link Locator} by using the {@link #PATH_SEPARATOR} to separate the
|
||||||
* values
|
* values
|
||||||
|
@ -186,6 +149,12 @@ public class Locator {
|
||||||
throw new StrolchException("A path may not be empty!"); //$NON-NLS-1$
|
throw new StrolchException("A path may not be empty!"); //$NON-NLS-1$
|
||||||
|
|
||||||
String[] elements = path.split(Locator.PATH_SEPARATOR);
|
String[] elements = path.split(Locator.PATH_SEPARATOR);
|
||||||
|
if (elements.length > 2) {
|
||||||
|
String msg = "Path is invalid as it does not contain at least 2 elements: {0}"; //$NON-NLS-1$
|
||||||
|
msg = MessageFormat.format(msg, path);
|
||||||
|
throw new StrolchException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
return Arrays.asList(elements);
|
return Arrays.asList(elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,8 +170,8 @@ public class Locator {
|
||||||
* if the path elements does not contain at least two items
|
* if the path elements does not contain at least two items
|
||||||
*/
|
*/
|
||||||
private String formatPath(List<String> pathElements) throws StrolchException {
|
private String formatPath(List<String> pathElements) throws StrolchException {
|
||||||
if (pathElements.isEmpty()) {
|
if (pathElements.size() > 2) {
|
||||||
String msg = "A Path always consists of at least element: {0}"; //$NON-NLS-1$
|
String msg = "A Path always consists of at least 2 elements: {0}"; //$NON-NLS-1$
|
||||||
msg = MessageFormat.format(msg, pathElements);
|
msg = MessageFormat.format(msg, pathElements);
|
||||||
throw new StrolchException(msg);
|
throw new StrolchException(msg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue