Now the component provides read-only access to the interfaces.
[utils] / system / general / src / main / java / org / wamblee / system / core / ReadWriteNamedInterfaces.java
1 /*
2  * Copyright 2008 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */ 
16 package org.wamblee.system.core;
17
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.Iterator;
21 import java.util.List;
22
23 public class ReadWriteNamedInterfaces<T extends NamedInterface> implements Iterable<T> {
24     
25     protected List<T> _interfaces; 
26
27     public ReadWriteNamedInterfaces() {
28         _interfaces = new ArrayList<T>(); 
29     }
30     
31     public ReadWriteNamedInterfaces(T[] aInterfaces) { 
32         _interfaces = new ArrayList<T>();
33         _interfaces.addAll(Arrays.asList(aInterfaces));
34     }
35     
36     public int size() { 
37         return _interfaces.size();
38     }
39     
40     public T get(int aIndex) { 
41         return _interfaces.get(aIndex);
42     }
43     
44     public T get(String aName) { 
45         for (T intf: _interfaces) { 
46             if ( intf.getName().equals(aName)) { 
47                 return intf; 
48             }
49         }
50         return null; 
51     }
52     
53     public void add(T aInterface) { 
54         _interfaces.add(aInterface);
55     }
56     
57     @Override
58     public Iterator<T> iterator() {
59         return _interfaces.iterator();
60     }
61
62 }