001 /*
002
003 $Id: FileCollection.java,v 1.7 2003/05/02 20:29:47 culdesac Exp $
004
005 */
006
007 package sharpster.common;
008
009 import sharpster.common.SharedFile;
010 import java.util.LinkedList;
011 import java.io.Serializable;
012
013 /**
014 * A collection of File objects. The class is used both by modules
015 * in the local client and in the daemon.
016 */
017 public class FileCollection implements Serializable {
018
019 /**
020 * Contains the file objects.
021 */
022 private LinkedList files;
023
024 public FileCollection() {
025 files = new LinkedList();
026 }
027
028 /**
029 * Returns the number of File objects in the collection.
030 */
031 public int getFileCount() {
032 return files.size();
033 }
034
035 /**
036 * Removes all files from the collection.
037 */
038 public void removeAllFiles() {
039 files.clear();
040 }
041
042 /**
043 * Adds a new File object to the collection.
044 */
045 public void addFile(SharedFile file) {
046 files.add(file);
047 }
048
049 /**
050 * Appends a FileCollection to this collection.
051 */
052 public void appendCollection(FileCollection collection) {
053 files.addAll(collection.files);
054 }
055
056 public FileCollection createDuplicate() {
057 FileCollection newFiles = new FileCollection();
058 for(int i=0;i<files.size();i++) {
059 newFiles.addFile(new SharedFile((SharedFile)files.get(i)));
060 }
061 return newFiles;
062 }
063
064 /**
065 * Removes all plugin data from the files, used to
066 * prepare the file to be transported to a remote user.
067 * This is because there is no garantee that the remote
068 * user has this plugin type thus may not be able to
069 * handle the plugin data.
070 */
071 public void removeAllPluginData() {
072 for(int i=0;i<files.size();i++) {
073 SharedFile file = (SharedFile)files.get(i);
074 file.setPluginData(null);
075 }
076 }
077
078 /**
079 * Returns a specified file.
080 */
081 public SharedFile getFile(int index) {
082 SharedFile retval = null;
083 try {
084 retval = (SharedFile)files.get(index);
085 } catch (Exception e) {
086 retval = null;
087 }
088 return retval;
089 }
090
091 /**
092 *
093 */
094 public String toString() {
095 String msg = new String();
096
097 msg += "File Collection: ";
098 for(int i=0;i<files.size();i++) {
099 SharedFile file = (SharedFile)files.get(i);
100 msg += file.toString() + "\n ";
101 }
102 msg += "\r";
103
104 return msg;
105 }
106 }
107
108
109
110
111
112