add size
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 30 May 2008 06:16:27 +0000 (08:16 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 30 May 2008 06:16:27 +0000 (08:16 +0200)
src/net/pterodactylus/jsite/project/Project.java
src/net/pterodactylus/jsite/project/ProjectFile.java

index 7a6ee10..265eeff 100644 (file)
@@ -289,7 +289,7 @@ public class Project extends AbstractBean {
                if (!basePathFile.exists() || !basePathFile.isDirectory()) {
                        return null;
                }
-               ProjectFileImpl rootProjectFile = new ProjectFileImpl(null, "", true, false);
+               ProjectFileImpl rootProjectFile = new ProjectFileImpl(null, "", 0, true, false);
                scanDirectory(basePathFile, rootProjectFile);
                return rootProjectFile;
        }
@@ -313,7 +313,7 @@ public class Project extends AbstractBean {
                        return;
                }
                for (File file: directory.listFiles()) {
-                       ProjectFileImpl projectFileChild = projectFile.addFile(file.getName(), file.isDirectory(), file.isHidden());
+                       ProjectFileImpl projectFileChild = projectFile.addFile(file.getName(), file.length(), file.isDirectory(), file.isHidden());
                        if (file.isDirectory()) {
                                scanDirectory(file, projectFileChild);
                        }
@@ -334,6 +334,9 @@ public class Project extends AbstractBean {
                /** The name of this project file. */
                private final String name;
 
+               /** The size of the file. */
+               private final long size;
+
                /** Whether this project file is a directory. */
                private final boolean directory;
 
@@ -351,6 +354,8 @@ public class Project extends AbstractBean {
                 *            the new project file does not have a parent
                 * @param name
                 *            The name of the project file
+                * @param size
+                *            The size of the file
                 * @param isDirectory
                 *            <code>true</code> if this project file is a directory,
                 *            <code>false</code> otherwise
@@ -358,9 +363,10 @@ public class Project extends AbstractBean {
                 *            <code>true</code> if this project file is hidden,
                 *            <code>false</code> otherwise
                 */
-               ProjectFileImpl(ProjectFileImpl parentProjectFile, String name, boolean isDirectory, boolean isHidden) {
+               ProjectFileImpl(ProjectFileImpl parentProjectFile, String name, long size, boolean isDirectory, boolean isHidden) {
                        this.parentProjectFile = parentProjectFile;
                        this.name = name;
+                       this.size = size;
                        this.directory = isDirectory;
                        this.hidden = isHidden;
                }
@@ -377,6 +383,13 @@ public class Project extends AbstractBean {
                }
 
                /**
+                * {@inheritDoc}
+                */
+               public long getSize() {
+                       return size;
+               }
+
+               /**
                 * @see net.pterodactylus.jsite.project.ProjectFile#getParents()
                 */
                public List<ProjectFile> getParents() {
@@ -439,6 +452,8 @@ public class Project extends AbstractBean {
                 * 
                 * @param name
                 *            The name of the file
+                * @param size
+                *            The size of the file
                 * @param isDirectory
                 *            <code>true</code> if the new file is a directory,
                 *            <code>false</code> otherwise
@@ -447,8 +462,8 @@ public class Project extends AbstractBean {
                 *            <code>false</code> otherwise
                 * @return The created project file
                 */
-               public ProjectFileImpl addFile(String name, boolean isDirectory, boolean isHidden) {
-                       ProjectFileImpl newProjectFile = new ProjectFileImpl(this, name, isDirectory, isHidden);
+               public ProjectFileImpl addFile(String name, long size, boolean isDirectory, boolean isHidden) {
+                       ProjectFileImpl newProjectFile = new ProjectFileImpl(this, name, size, isDirectory, isHidden);
                        childProjectFiles.add(newProjectFile);
                        return newProjectFile;
                }
index 1a8738a..53a7b5b 100644 (file)
@@ -57,6 +57,15 @@ public interface ProjectFile {
        public String getCompletePath();
 
        /**
+        * Returns the size of the file. If this file is a directory, the returned
+        * value is unspecified.
+        * 
+        * @see File#length()
+        * @return The size of the file
+        */
+       public long getSize();
+
+       /**
         * Returns whether this file is a directory.
         * 
         * @return <code>true</code> if this file is a directory,