package org.apache.mesos.elasticsearch.scheduler.state;

import org.apache.log4j.Logger;

import java.io.IOException;
import java.security.InvalidParameterException;

/**
 * Path utilities
 */
public class StatePath {
    private static final Logger LOGGER = Logger.getLogger(StatePath.class);
    private SerializableState zkState;
    public StatePath(SerializableState zkState) {
        this.zkState = zkState;
    }

    /**
     * Creates the zNode if it does not exist. Will create parent directories.
     * @param key the zNode path
     */
    public void mkdir(String key) throws IOException {
        key = key.replace(" ", "");
        if (key.endsWith("/") && !key.equals("/")) {
            throw new InvalidParameterException("Trailing slash not allowed in zookeeper path");
        }
        String[] split = key.split("/");
        StringBuilder builder = new StringBuilder();
        for (String s : split) {
            builder.append(s);
            if (!s.isEmpty() && !exists(builder.toString())) {
                zkState.set(builder.toString(), null);
            }
            builder.append("/");
        }
    }

    public Boolean exists(String key) throws IOException {
        Boolean exists = true;
        Object value = zkState.get(key);
        if (value == null) {
            exists = false;
        }
        return exists;
    }

    public void rm(String key) throws IOException {
        key = key.replace(" ", "");
        zkState.delete(key);
    }
}

@@ -54,41 +54,8 @@
 e;%0A%0A
-import org.apache.log4j.Logger;%0A%0A
 impo
@@ -182,84 +182,8 @@
 h %7B%0A
-    private static final Logger LOGGER = Logger.getLogger(StatePath.class);%0A
     
@@ -1253,24 +1253,166 @@
 %0A    %7D%0A%0A    
+/**%0A     * Remove a zNode or zFolder.%0A     *%0A     * @param key the path to remove.%0A     * @throws IOException If unable to remove%0A     */%0A    
 public void 
@@ -1450,44 +1450,8 @@
 on %7B
-%0A        key = key.replace(%22 %22, %22%22);
 %0A   

Add comments. Remove space removal.