2 * Copyright 2008 the original author or authors.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.wamblee.system.core;
18 import java.lang.reflect.Array;
19 import java.util.Arrays;
20 import java.util.Collections;
21 import java.util.Iterator;
22 import java.util.List;
25 * A set of interfaces that cannot be changed with useful added functionality.
27 * @author Erik Brakkee
31 public class ReadOnlyNamedInterfaces<T extends NamedInterface> implements Iterable<T> {
33 private Class<T> _type;
34 private List<T> _interfaces;
36 public ReadOnlyNamedInterfaces(Class<T> aType, List<T> aInterfaces) {
38 _interfaces = Collections.unmodifiableList(aInterfaces);
42 * @return Number of interfaces.
45 return _interfaces.size();
49 * Gets the interface at a given index.
50 * @param aIndex Index of the interface to return.
53 public T get(int aIndex) {
54 return _interfaces.get(aIndex);
58 * Gets the interface with a specific name.
59 * @param aName Interface name.
62 public T get(String aName) {
63 for (T intf: _interfaces) {
64 if ( intf.getName().equals(aName)) {
72 public Iterator<T> iterator() {
73 return _interfaces.iterator();
77 * Converts the interfaces to an array.
78 * @return List of interfaces in an array.
80 public T[] toArray() {
81 T[] storage = (T[])Array.newInstance(_type, _interfaces.size());
82 return _interfaces.toArray(storage);