Commits

mquigley committed 54eca08

Fixed issues involving absolute paths.

  • Participants
  • Parent commits 8975126
  • Branches Dev_0.0.3

Comments (0)

Files changed (2)

File src/main/java/com/quigley/filesystem/FilesystemPath.java

         for(int i = 0; i < source.size(); i++) {
             elements.add(source.get(i));
         }
-        isAbsolute = source.isAbsolute();
+        isAbsolute = source.isAbsolute;
     }
     
     public FilesystemPath(List<String> elements) {
      * Absolute
      */
 
-    public FilesystemPath toAbsolute() {
-    	FilesystemPath absolutePath = new FilesystemPath(this.asFile().getAbsolutePath());
-    	if(absolutePath.getLast().equals(".")) {
-    		absolutePath = absolutePath.removeLast();
-    	}
+    public FilesystemPath makeAbsolute() {
+    	FilesystemPath absolutePath = new FilesystemPath(this.asFile().getAbsolutePath()).setAbsolute(true);
     	return absolutePath;
     }
     
     public boolean isAbsolute() {
         return isAbsolute;
     }
-    public void setAbsolute(boolean absolute) {
-        isAbsolute = absolute;
+    public FilesystemPath setAbsolute(boolean absolute) {
+        FilesystemPath absolutePath = new FilesystemPath(elements);
+        absolutePath.isAbsolute = true;
+        return absolutePath;
     }
 
     /*
         elementsCopy.add(element);
         
         FilesystemPath pathCopy = new FilesystemPath(elementsCopy);
-        pathCopy.setAbsolute(isAbsolute);
+        pathCopy.isAbsolute = isAbsolute;
         
         return pathCopy;
     }
         }
 
         FilesystemPath pathCopy = new FilesystemPath(elementsCopy);
-        pathCopy.setAbsolute(isAbsolute);
+        pathCopy.isAbsolute = isAbsolute;
         
         return pathCopy;
     }
         elementsCopy.set(idx, component);
 
         FilesystemPath pathCopy = new FilesystemPath(elementsCopy);
-        pathCopy.setAbsolute(isAbsolute);
+        pathCopy.isAbsolute = isAbsolute;
         
         return pathCopy;
     }    
         elementsCopy.remove(idx);
         
         FilesystemPath pathCopy = new FilesystemPath(elementsCopy);
-        pathCopy.setAbsolute(isAbsolute);
+        pathCopy.isAbsolute = isAbsolute;
         
         return pathCopy;
     }
     	elementsCopy.remove(0);
     	
     	FilesystemPath pathCopy = new FilesystemPath(elementsCopy);
+    	pathCopy.isAbsolute = isAbsolute;
     	
     	return pathCopy;
     }
     	elementsCopy = elementsCopy.subList(count, elementsCopy.size());
     	
     	FilesystemPath pathCopy = new FilesystemPath(elementsCopy);
+    	pathCopy.isAbsolute = isAbsolute;
     	
     	return pathCopy;
     }
     	elementsCopy.remove(elements.size() - 1);
     	
     	FilesystemPath pathCopy = new FilesystemPath(elementsCopy);
-    	pathCopy.setAbsolute(isAbsolute);
+    	pathCopy.isAbsolute = isAbsolute;
     	
     	return pathCopy;
     }
     	}
     	
     	FilesystemPath pathCopy = new FilesystemPath(elementsCopy);
-    	pathCopy.setAbsolute(isAbsolute);
+    	pathCopy.isAbsolute = isAbsolute;
     	
     	return pathCopy;
     }
     		outputPath = outputPath.removeFirst();
     		parallelPath = parallelPath.removeFirst();
     	}
+
+    	if(!outputPath.equals(otherPath)) {
+    		outputPath.isAbsolute = false;
+    	}
     	
     	return outputPath;
     }
     			saw = true;
     		}
     	}
-    	return new FilesystemPath(elementsCopy);
+    	FilesystemPath pathCopy = new FilesystemPath(elementsCopy);
+    	pathCopy.isAbsolute = isAbsolute;
+
+    	return pathCopy;
     }
 
     /*
     }    
     
     public FilesystemPath removeExtension() {
-    	return new FilesystemPath(removeExtension(this.toString()));
+    	FilesystemPath pathCopy = new FilesystemPath(removeExtension(this.toString()));
+    	pathCopy.isAbsolute = isAbsolute;
+    	return pathCopy;
     }
     
     public FilesystemPath setExtension(String extension) {
     	FilesystemPath pathCopy = new FilesystemPath(removeExtension(this.toString()));
     	pathCopy = new FilesystemPath(pathCopy.toString() + "." + extension);
+    	pathCopy.isAbsolute = isAbsolute;
     	return pathCopy;
     }
     
     public FilesystemPath addExtension(String extension) {
-    	return new FilesystemPath(this.toString() + "." + extension);
+    	FilesystemPath pathCopy = new FilesystemPath(this.toString() + "." + extension);
+    	pathCopy.isAbsolute = isAbsolute;
+    	return pathCopy;
     }
     
     /*
     
     public static FilesystemPath currentWorkingDirectory() {
     	File cwd = new File(".");
-    	return new FilesystemPath(cwd.getAbsolutePath()).simplify();
+    	return new FilesystemPath(cwd.getAbsolutePath()).setAbsolute(true).simplify();
     }
     
     public static String normalize(String pathString) {

File src/test/java/com/quigley/filesystem/FilesystemPathTest.java

     	assertTrue(source.removeFirst(3).toString().equals(""));
     	
     	source = new FilesystemPath("/a/b/c");
-    	assertTrue(source.removeFirst(3).toString().equals(""));
+    	assertEquals("/", source.removeFirst(3).toString());
     }
     
     @Test
     
     @Test
     public void testToAbsolute1() {
-    	FilesystemPath path = new FilesystemPath(".").toAbsolute();
+    	FilesystemPath path = new FilesystemPath(".").makeAbsolute();
     	System.out.println("Absolute: " + path);
-    	path = new FilesystemPath("src/java").toAbsolute();
+    	path = new FilesystemPath("src/java").makeAbsolute();
     	System.out.println("Absolute: " + path);
     }