|
@@ -20,6 +20,8 @@ package org.apache.hadoop.net;
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
import org.apache.hadoop.classification.InterfaceStability;
|
|
import org.apache.hadoop.classification.InterfaceStability;
|
|
|
|
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
+
|
|
/** A base class that implements interface Node
|
|
/** A base class that implements interface Node
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
@@ -38,6 +40,7 @@ public class NodeBase implements Node {
|
|
protected String location; //string representation of this node's location
|
|
protected String location; //string representation of this node's location
|
|
protected int level; //which level of the tree the node resides
|
|
protected int level; //which level of the tree the node resides
|
|
protected Node parent; //its parent
|
|
protected Node parent; //its parent
|
|
|
|
+ private static final Pattern SLASHES = Pattern.compile("/+");
|
|
|
|
|
|
/** Default constructor */
|
|
/** Default constructor */
|
|
public NodeBase() {
|
|
public NodeBase() {
|
|
@@ -160,12 +163,15 @@ public class NodeBase implements Node {
|
|
if (path.length() == 0) {
|
|
if (path.length() == 0) {
|
|
return ROOT;
|
|
return ROOT;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (path.charAt(0) != PATH_SEPARATOR) {
|
|
if (path.charAt(0) != PATH_SEPARATOR) {
|
|
throw new IllegalArgumentException(
|
|
throw new IllegalArgumentException(
|
|
"Network Location path does not start with "
|
|
"Network Location path does not start with "
|
|
+PATH_SEPARATOR_STR+ ": "+path);
|
|
+PATH_SEPARATOR_STR+ ": "+path);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // Remove duplicated slashes.
|
|
|
|
+ path = SLASHES.matcher(path).replaceAll("/");
|
|
|
|
|
|
int len = path.length();
|
|
int len = path.length();
|
|
if (path.charAt(len-1) == PATH_SEPARATOR) {
|
|
if (path.charAt(len-1) == PATH_SEPARATOR) {
|