KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > netbios > NetBIOSNameList


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 package org.alfresco.filesys.netbios;
18
19 import java.util.Vector JavaDoc;
20
21 /**
22  * NetBIOS Name List Class
23  */

24 public class NetBIOSNameList
25 {
26
27     // List of NetBIOS names
28

29     private Vector JavaDoc<NetBIOSName> m_nameList;
30
31     /**
32      * Class constructor
33      */

34     public NetBIOSNameList()
35     {
36         m_nameList = new Vector JavaDoc<NetBIOSName>();
37     }
38
39     /**
40      * Add a name to the list
41      *
42      * @param name NetBIOSName
43      */

44     public final void addName(NetBIOSName name)
45     {
46         m_nameList.add(name);
47     }
48
49     /**
50      * Get a name from the list
51      *
52      * @param idx int
53      * @return NetBIOSName
54      */

55     public final NetBIOSName getName(int idx)
56     {
57         if (idx < m_nameList.size())
58             return m_nameList.get(idx);
59         return null;
60     }
61
62     /**
63      * Return the number of names in the list
64      *
65      * @return int
66      */

67     public final int numberOfNames()
68     {
69         return m_nameList.size();
70     }
71
72     /**
73      * Find names of the specified name of different types and return a subset of the available
74      * names.
75      *
76      * @param name String
77      * @return NetBIOSNameList
78      */

79     public final NetBIOSNameList findNames(String JavaDoc name)
80     {
81
82         // Allocate the sub list and search for required names
83

84         NetBIOSNameList subList = new NetBIOSNameList();
85         for (int i = 0; i < m_nameList.size(); i++)
86         {
87             NetBIOSName nbName = getName(i);
88             if (nbName.getName().compareTo(name) == 0)
89                 subList.addName(nbName);
90         }
91
92         // Return the sub list of names
93

94         return subList;
95     }
96
97     /**
98      * Find the first name of the specified type
99      *
100      * @param typ char
101      * @param group boolean
102      * @return NetBIOSName
103      */

104     public final NetBIOSName findName(char typ, boolean group)
105     {
106
107         // Search for the first name of the required type
108

109         for (int i = 0; i < m_nameList.size(); i++)
110         {
111             NetBIOSName name = getName(i);
112             if (name.getType() == typ && name.isGroupName() == group)
113                 return name;
114         }
115
116         // Name type not found
117

118         return null;
119     }
120
121     /**
122      * Find the specified name and type
123      *
124      * @param name String
125      * @param typ char
126      * @param group boolean
127      * @return NetBIOSName
128      */

129     public final NetBIOSName findName(String JavaDoc name, char typ, boolean group)
130     {
131
132         // Search for the first name of the required type
133

134         for (int i = 0; i < m_nameList.size(); i++)
135         {
136             NetBIOSName nbName = getName(i);
137             if (nbName.getName().equals(name) && nbName.getType() == typ && nbName.isGroupName() == group)
138                 return nbName;
139         }
140
141         // Name/type not found
142

143         return null;
144     }
145
146     /**
147      * Find names of the specified type and return a subset of the available names
148      *
149      * @param typ char
150      * @param group boolean
151      * @return NetBIOSNameList
152      */

153     public final NetBIOSNameList findNames(char typ, boolean group)
154     {
155
156         // Allocate the sub list and search for names of the required type
157

158         NetBIOSNameList subList = new NetBIOSNameList();
159         for (int i = 0; i < m_nameList.size(); i++)
160         {
161             NetBIOSName name = getName(i);
162             if (name.getType() == typ && name.isGroupName() == group)
163                 subList.addName(name);
164         }
165
166         // Return the sub list of names
167

168         return subList;
169     }
170
171     /**
172      * Remove a name from the list
173      *
174      * @param name NetBIOSName
175      * @return NetBIOSName
176      */

177     public final NetBIOSName removeName(NetBIOSName name)
178     {
179         for (int i = 0; i < m_nameList.size(); i++)
180         {
181             NetBIOSName curName = getName(i);
182             if (curName.equals(name))
183             {
184                 m_nameList.removeElementAt(i);
185                 return curName;
186             }
187         }
188         return null;
189     }
190
191     /**
192      * Delete all names from the list
193      */

194     public final void removeAllNames()
195     {
196         m_nameList.removeAllElements();
197     }
198 }
199
Popular Tags