KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > server > repo > pseudo > PseudoFileList


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17
18 package org.alfresco.filesys.smb.server.repo.pseudo;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.List JavaDoc;
22
23 /**
24  * Pseudo File List Class
25  *
26  * <p>Contains a list of pseudo file list entries for a folder.
27  *
28  * @author gkspencer
29  */

30 public class PseudoFileList
31 {
32     // List of pseudo files
33

34     private List JavaDoc<PseudoFile> m_list;
35     
36     /**
37      * Default constructor
38      */

39     public PseudoFileList()
40     {
41         m_list = new ArrayList JavaDoc<PseudoFile>();
42     }
43     
44     /**
45      * Add a pseudo file to the list
46      *
47      * @param pfile PseudoFile
48      */

49     public final void addFile( PseudoFile pfile)
50     {
51         m_list.add( pfile);
52     }
53     
54     /**
55      * Return the count of files in the list
56      *
57      * @return int
58      */

59     public final int numberOfFiles()
60     {
61         return m_list.size();
62     }
63     
64     /**
65      * Return the file at the specified index in the list
66      *
67      * @param idx int
68      * @return PseudoFile
69      */

70     public final PseudoFile getFileAt(int idx)
71     {
72         if ( idx < m_list.size())
73             return m_list.get(idx);
74         return null;
75     }
76     
77     /**
78      * Search for the specified pseudo file name
79      *
80      * @param fname String
81      * @param caseSensitive boolean
82      * @return PseudoFile
83      */

84     public final PseudoFile findFile( String JavaDoc fname, boolean caseSensitive)
85     {
86         // Check if there are any entries in the list
87

88         if ( m_list == null || m_list.size() == 0)
89             return null;
90         
91         // Search for the name match
92

93         for ( PseudoFile pfile : m_list)
94         {
95             if ( caseSensitive && pfile.getFileName().equals( fname))
96                 return pfile;
97             else if ( pfile.getFileName().equalsIgnoreCase( fname))
98                 return pfile;
99         }
100         
101         // File not found
102

103         return null;
104     }
105     
106     /**
107      * Remove the specified pseudo file from the list
108      *
109      * @param fname String
110      * @param caseSensitive boolean
111      * @return PseudoFile
112      */

113     public final PseudoFile removeFile( String JavaDoc fname, boolean caseSensitive)
114     {
115         // Check if there are any entries in the list
116

117         if ( m_list == null || m_list.size() == 0)
118             return null;
119         
120         // Search for the name match
121

122         for ( int idx = 0; idx < m_list.size(); idx++)
123         {
124             // Get the current pseudo file
125

126             PseudoFile pfile = m_list.get( idx);
127             boolean match = false;
128             
129             if ( caseSensitive && pfile.getFileName().equals( fname))
130                 match = true;
131             else if ( pfile.getFileName().equalsIgnoreCase( fname))
132                 match = true;
133             
134             // If we found the matching pseudo file remove it from the list
135

136             if ( match)
137             {
138                 m_list.remove( idx);
139                 return pfile;
140             }
141         }
142         
143         // File not found
144

145         return null;
146     }
147 }
148
Popular Tags