package ee.shy.core;

import java.util.ArrayList;
import java.util.List;

public class TreePath implements Comparable<TreePath> {
    private final List<String> pathStrings = new ArrayList<>();

    TreePath(String stringPath) {
        for(String s : stringPath.split("/"))
            pathStrings.add(s);
    }

    public void resolve(String str) {
        new TreePath(this.toString() + str);
    }

    List<String> getPathStrings() {
        return pathStrings;
    }

    public String toString() {
        String stringPath = "";
        for (String s : pathStrings) {
            stringPath += "/" + s;
        }
        return stringPath;
    }

    @Override
    public int compareTo(TreePath o) {
        List<String> oStringList = o.getPathStrings();
        if(oStringList.size() < pathStrings.size()) {
            return 1;
        }
        else if(oStringList.size() > pathStrings.size()) {
            return -1;
        }

        int iterCount = Math.min(pathStrings.size(), oStringList.size());
        
        for(int i = 0; i < iterCount; i++) {
            int strCompareResult = oStringList.get(i).compareTo(pathStrings.get(i));
            if(strCompareResult != 0) {
                return strCompareResult;
            }
        }
        return 0;
    }
}

@@ -15,16 +15,61 @@
 .core;%0A%0A
+import org.apache.commons.lang3.ArrayUtils;%0A%0A
 import j
@@ -186,28 +186,24 @@
 e final 
-List%3C
 String
-%3E
+%5B%5D
  pathStr
@@ -210,34 +210,21 @@
 ings
- = new ArrayList%3C%3E();%0A%0A   
+;%0A%0A    public
  Tre
@@ -262,22 +262,21 @@
     
-for(
+path
 String
- 
 s 
-:
+=
  str
@@ -297,130 +297,93 @@
 %22/%22)
-)%0A            pathStrings.add(s);%0A    %7D%0A%0A    public void resolve(String str) %7B%0A        new TreePath(
+;%0A    %7D%0A%0A    public TreePath(String%5B%5D treePath) %7B%0A        
 this.
-to
+path
 String
-() + str)
+s = treePath
 ;%0A  
@@ -395,36 +395,42 @@
     
-List%3CString%3E getPath
+public TreePath resolve(
 String
-s(
+ str
 ) %7B%0A
@@ -448,200 +448,152 @@
 urn 
-pathStrings;%0A    %7D%0A%0A    public String toString() %7B%0A        String stringPath = %22%22;%0A        for (String s : pathStrings) %7B%0A            stringPath += %22/%22 + s;%0A        %7D%0A        return stringPath
+new TreePath(ArrayUtils.addAll(pathStrings, str.split(%22/%22)));%0A    %7D%0A%0A    public String toString() %7B%0A        return String.join(%22/%22, pathStrings)
 ;%0A  
@@ -662,20 +662,16 @@
     
-List%3C
 String
-%3E
+%5B%5D
  oSt
@@ -687,203 +687,20 @@
 = o.
-getPathStrings();%0A        if(oStringList.size() %3C pathStrings.size()) %7B%0A            return 1;%0A        %7D%0A        else if(oStringList.size() %3E pathStrings.size()) %7B%0A            return -1;%0A        %7D
+pathStrings;
 %0A%0A  
@@ -742,22 +742,22 @@
 Strings.
-size()
+length
 , oStrin
@@ -766,14 +766,14 @@
 ist.
-size()
+length
 );%0A 
@@ -791,16 +791,17 @@
      for
+ 
 (int i =
@@ -872,23 +872,19 @@
 ringList
-.get(i)
+%5Bi%5D
 .compare
@@ -901,15 +901,11 @@
 ings
-.get(i)
+%5Bi%5D
 );%0A 
@@ -1000,32 +1000,33 @@
     %7D%0A        %7D%0A
+%0A
         return 0
@@ -1024,17 +1024,55 @@
  return 
-0
+oStringList.length - pathStrings.length
 ;%0A    %7D%0A

Refactor TreePath to optimize resolve method