From b98dc48989ee78251103c13f9fb48a100febacf5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 30 May 2008 08:16:27 +0200 Subject: [PATCH] add size --- src/net/pterodactylus/jsite/project/Project.java | 25 +++++++++++++++++----- .../pterodactylus/jsite/project/ProjectFile.java | 9 ++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/net/pterodactylus/jsite/project/Project.java b/src/net/pterodactylus/jsite/project/Project.java index 7a6ee10..265eeff 100644 --- a/src/net/pterodactylus/jsite/project/Project.java +++ b/src/net/pterodactylus/jsite/project/Project.java @@ -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 * true if this project file is a directory, * false otherwise @@ -358,9 +363,10 @@ public class Project extends AbstractBean { * true if this project file is hidden, * false 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 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 * true if the new file is a directory, * false otherwise @@ -447,8 +462,8 @@ public class Project extends AbstractBean { * false 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; } diff --git a/src/net/pterodactylus/jsite/project/ProjectFile.java b/src/net/pterodactylus/jsite/project/ProjectFile.java index 1a8738a..53a7b5b 100644 --- a/src/net/pterodactylus/jsite/project/ProjectFile.java +++ b/src/net/pterodactylus/jsite/project/ProjectFile.java @@ -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 true if this file is a directory, -- 2.7.4