You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by bf...@apache.org on 2011/06/03 01:38:16 UTC

svn commit: r1130875 - in /oodt/branches/protocol/protocol-api/src: main/java/org/apache/oodt/cas/protocol/ProtocolFile.java test/org/apache/oodt/cas/protocol/TestProtocolFile.java

Author: bfoster
Date: Thu Jun  2 23:38:15 2011
New Revision: 1130875

URL: http://svn.apache.org/viewvc?rev=1130875&view=rev
Log:

- cleanup

---------------
OODT-194

Modified:
    oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/ProtocolFile.java
    oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/TestProtocolFile.java

Modified: oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/ProtocolFile.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/ProtocolFile.java?rev=1130875&r1=1130874&r2=1130875&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/ProtocolFile.java (original)
+++ oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/ProtocolFile.java Thu Jun  2 23:38:15 2011
@@ -21,101 +21,109 @@ import java.io.File;
 
 //APACHE imports
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.Validate;
 
 /**
- * A path representing a file/directory over some {@link Protocol} 
+ * A path representing a file/directory over some {@link Protocol}
  * 
  * @author bfoster
  */
 public class ProtocolFile {
 
-    public static final ProtocolFile ROOT = new ProtocolFile(File.separator, true);
-    public static final ProtocolFile HOME = new ProtocolFile(new File("").getAbsolutePath(), true);
-
-    private String path;
-    private boolean isDir;
-
-    public ProtocolFile(String path, boolean isDir) {
-        this.isDir = isDir;
-		this.path = path.length() > 0 && !path.equals(File.separator) ? StringUtils
-				.chomp(path, File.separator) : path;
-    }
-
-    /**
-     * True is this path is a directory.
-     * 
-     * @return True if directory, false otherwise
-     */
-    public boolean isDir() {
-        return isDir;
-    }
-    
-    /**
-     * Gets the {@link String} representation of this path.
-     * 
-     * @return The {@link String} representation of this path
-     */
-    public String getPath() {
-        return path;
-    }
-
-    /**
-     * Gets the name of this file this path represents (i.e. '/path/to/file' will return 'file')
-     * 
-     * @return The name of the file this path represents
-     */
-    public String getName() {
-    	if (this.equals(ROOT) || !path.contains(File.separator)) {
-    		return path;
-    	} else {
-    		return path.substring(path.lastIndexOf(File.separator) + 1);
-    	}
-    }
-
-    /**
-     * True if this path is a relative path (i.e. does not start with {@link File.separator}).
-     * 
-     * @return True is this a relative path, false otherwise
-     */
-    public boolean isRelative() {
-        return !path.startsWith(File.separator);
-    }
-    
-    /**
-     * Gets the parent {@link ProtocolFile} for this path.
-     * 
-     * @return The parent {@link ProtocolFile}
-     */
-    public ProtocolFile getParent() {
-    	if (this.equals(ROOT) || !path.contains(File.separator)) {
-    		return null;
-    	} else {
-    		return new ProtocolFile(path.substring(0, path.lastIndexOf(File.separator)), true);
-    	}
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public int hashCode() {
-    	return this.getPath().hashCode();
-    }
-    
-    /**
-     * {@inheritDoc}
-     */
-    public boolean equals(Object path) {
-        if (path instanceof ProtocolFile) {
-        	ProtocolFile p = (ProtocolFile) path;
-            return (p.getPath().equals(this.getPath()) && p.isDir() == this.isDir());
-        }
-        return false;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public String toString() {
-    	return path;
-    }
+	public static final String SEPARATOR = "/";
+	
+	public static final ProtocolFile ROOT = new ProtocolFile(SEPARATOR, true);
+	public static final ProtocolFile HOME = new ProtocolFile(
+			new File("").getAbsolutePath(), true);
+
+	private String path;
+	private boolean isDir;
+
+	public ProtocolFile(String path, boolean isDir) {
+		this.isDir = isDir;
+		Validate.notNull(path, "ProtocolFile's path cannot be NULL");
+		this.path = path.length() > 0 && !path.equals(SEPARATOR) ? StringUtils
+				.chomp(path, SEPARATOR) : path;
+	}
+
+	/**
+	 * True is this path is a directory.
+	 * 
+	 * @return True if directory, false otherwise
+	 */
+	public boolean isDir() {
+		return isDir;
+	}
+
+	/**
+	 * Gets the {@link String} representation of this path.
+	 * 
+	 * @return The {@link String} representation of this path
+	 */
+	public String getPath() {
+		return path;
+	}
+
+	/**
+	 * Gets the name of this file this path represents (i.e. '/path/to/file' will
+	 * return 'file')
+	 * 
+	 * @return The name of the file this path represents
+	 */
+	public String getName() {
+		if (this.equals(ROOT) || !path.contains(SEPARATOR)) {
+			return path;
+		} else {
+			return path.substring(path.lastIndexOf(SEPARATOR) + 1);
+		}
+	}
+
+	/**
+	 * True if this path is a relative path (i.e. does not start with
+	 * {@link SEPARATOR}).
+	 * 
+	 * @return True is this a relative path, false otherwise
+	 */
+	public boolean isRelative() {
+		return !path.startsWith(SEPARATOR);
+	}
+
+	/**
+	 * Gets the parent {@link ProtocolFile} for this path.
+	 * 
+	 * @return The parent {@link ProtocolFile}
+	 */
+	public ProtocolFile getParent() {
+		if (this.equals(ROOT) || !path.contains(SEPARATOR)) {
+			return null;
+		} else {
+			return new ProtocolFile(path.substring(0,
+					path.lastIndexOf(SEPARATOR)), true);
+		}
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public int hashCode() {
+		return this.getPath().hashCode();
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean equals(Object path) {
+		if (path instanceof ProtocolFile) {
+			ProtocolFile p = (ProtocolFile) path;
+			return (p.getPath().equals(this.getPath()) && p.isDir() == this.isDir());
+		}
+		return false;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public String toString() {
+		return path;
+	}
 }

Modified: oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/TestProtocolFile.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/TestProtocolFile.java?rev=1130875&r1=1130874&r2=1130875&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/TestProtocolFile.java (original)
+++ oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/TestProtocolFile.java Thu Jun  2 23:38:15 2011
@@ -30,7 +30,7 @@ import junit.framework.TestCase;
 public class TestProtocolFile extends TestCase {
 
 	public void testInitialState() {
-		String filePath = File.separator + "path" + File.separator + "to" + File.separator + "file";
+		String filePath = ProtocolFile.SEPARATOR + "path" + ProtocolFile.SEPARATOR + "to" + ProtocolFile.SEPARATOR + "file";
 		ProtocolFile pFile = new ProtocolFile(filePath, false);
 		assertEquals(filePath, pFile.getPath());
 		assertEquals(pFile.getPath(), pFile.toString());
@@ -39,7 +39,7 @@ public class TestProtocolFile extends Te
 		assertFalse(pFile.isRelative());
 		
 		// Test Parent file
-		String parentPath = File.separator + "path" + File.separator + "to";
+		String parentPath = ProtocolFile.SEPARATOR + "path" + ProtocolFile.SEPARATOR + "to";
 		assertEquals(parentPath, pFile.getParent().getPath());
 		assertEquals(pFile.getParent().getPath(), pFile.getParent().toString());
 		assertEquals("to", pFile.getParent().getName());
@@ -48,7 +48,7 @@ public class TestProtocolFile extends Te
 	}
 	
 	public void testRoot() {
-		assertEquals(File.separator, ProtocolFile.ROOT.getPath());
+		assertEquals(ProtocolFile.SEPARATOR, ProtocolFile.ROOT.getPath());
 		assertNull(ProtocolFile.ROOT.getParent());
 		assertEquals(ProtocolFile.ROOT.getPath(), ProtocolFile.ROOT.getName());
 		assertEquals(ProtocolFile.ROOT.getPath(), ProtocolFile.ROOT.toString());