20 package net.sf.gridarta.model.mapmodel;
22 import org.jetbrains.annotations.NotNull;
23 import org.jetbrains.annotations.Nullable;
57 throw new IllegalArgumentException(
"map file is empty");
59 if (name.contains(
"/")) {
60 throw new IllegalArgumentException(
"map file contains '/': " + name);
62 if (name.equals(
".")) {
64 }
else if (name.equals(
"..")) {
65 if (parent.path.isEmpty()) {
67 }
else if (parent.path.endsWith(
"/..") || parent.path.equals(
"..")) {
68 path = parent.path +
"/..";
70 final int index = parent.path.lastIndexOf(
'/');
74 path = parent.path.substring(0, index);
78 if (parent.path.isEmpty()) {
81 path = parent.path +
"/" + name;
93 final String[] source =
MapPath.
SEPARATOR.split(sourceMapPath.getPath(), -1);
94 final String[] destination =
MapPath.
SEPARATOR.split(destinationMapPath.getPath(), -1);
96 while (begin < source.length && begin < destination.length && source[begin].equals(destination[begin])) {
99 if (begin == destination.length && begin > 0) {
102 final StringBuilder sb =
new StringBuilder();
103 int i = source.length - 1;
108 while (i < destination.length) {
109 sb.append(
"/").append(destination[i]);
112 path = sb.length() > 0 ? sb.substring(1) :
"";
130 return path.compareTo(o.path);
134 public boolean equals(@Nullable
final Object obj) {
135 if (obj == null || getClass() != obj.getClass()) {
144 return path.hashCode();
RelativeMapPath(@NotNull final AbsoluteMapPath sourceMapPath, @NotNull final AbsoluteMapPath destinationMapPath)
Creates a new instance as the difference between two absolute map paths.
A MapPath that is absolute, that is, it starts with a "/".
Pattern SEPARATOR
A Pattern to split a map path's string representation into components.
RelativeMapPath(@NotNull final RelativeMapPath parent, @NotNull final String name)
Creates a new map path based on a parent map path.
Represents a maps directory local map path.
boolean equals(@Nullable final Object obj)
String getPath()
Returns the map path information.
int compareTo(@NotNull final RelativeMapPath o)
static final long serialVersionUID
The serial versionUID,.
RelativeMapPath()
Creates a new instance.
Represents a maps directory local map path.
String getMapComponent()
Returns the initial path component of a map path.
final String path
The map path information.