Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * #%L
   * Service Locator Client for CXF
   * %%
   * Copyright (C) 2011 Talend Inc.
   * %%
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * 
  *      http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * #L%
  */
 package org.talend.esb.locator;
 
Representation of ZooKeeper node path. The path is always absolute. As path segments obviously cannot contain the path separator ("/") raw paths are always encoded.
 
 public class NodePath {
 
 	private static final Logger LOG = Logger.getLogger(NodePath.class.getPackage().getName());
 	
 	public static final char SEPARATOR = '/';
 	
 	private String path;

Create an NodePath that consists of the given path segments.

Parameters:
pathSegments the sequence of path segments the NodePath consists of, must not be null or empty
 
 	public NodePath(String... pathSegments) {
 		if (pathSegments == null || pathSegments.length == 0) {
 			.log(."At least one path segment must be defined."); 
 			throw new IllegalArgumentException("At least one path segment must be defined.");
 		}
 		StringBuffer rawPath = new StringBuffer();
 		for (String pathSegment : pathSegments) {
 			checkValidPathSegment(pathSegment);
 			String encodedPathSegment = encode(pathSegment);
 			rawPath.append().append(encodedPathSegment);
 		}
 		 = rawPath.toString();
 	}
 
 	private NodePath(NodePath parentPathString childPathSegment) {
 		checkValidPathSegment(childPathSegment);
 		 = parentPath.path +  + encode(childPathSegment);
 	}

Create a NodePath, which is a child of this one.

Parameters:
childNodeName name of the child node, must not be null
 
 	public NodePath child(String childNodeName) {
 		return new NodePath(thischildNodeName);
 	}
 
 	public boolean equals(Object obj) {
 		if(obj == null || ! (obj instanceof NodePath)) {
 			return false;
 		}
 		return .equals(((NodePath)obj).);
 	}
 
 	public int hashCode() {
 		return .hashCode();
 	}

Encoded String representation of this NodePath.

Returns:
the String representation
 
 	public String toString() {
 		return ;
 	}
 
 	private void checkValidPathSegment(String pathSegment) {
 		if (pathSegment == null || pathSegment.isEmpty()) {
 			throw new IllegalArgumentException("Path segments must not be null and not empty.");
 		}
 	}

Encode the given String. All occurrences of "/" are mapped to "%2A" and all occurrences of "%" to "%2F".

Parameters:
raw the String to encode, must not be null
Returns:
the encoded version
See also:
decode(java.lang.String)
	public static String encode(String raw) {
		String encoded = raw.replace("%""%2A");
		encoded = encoded.replace("/""%2F");
		return encoded;
	}

Decode the given String. It is the inverse operation of encode(java.lang.String). For all Strings s, decode(encode(s)).equals(s) should be true.

Parameters:
encoded the String to decode, must not be null
Returns:
the raw version
See also:
encode(java.lang.String)
	public static String decode(String encoded) {
		String raw = encoded.replace("%2F""/");
		raw = raw.replace("%2A""%");
		return raw;
	}
New to GrepCode? Check out our FAQ X