View Javadoc

1   /*
2    * Copyright 2004-2005 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * 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, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package net.sf.morph.wrap;
17  
18  import java.util.Iterator;
19  
20  /**
21   * A wrapper around 'container-like' structures. A 'container-like' structure
22   * contains a certain number of objects, each of which has a particular type.
23   * Examples of 'container-like' objects include arrays and
24   * java.util.Collections.
25   * 
26   * @author Matt Sgarlata
27   * @since Jan 16, 2005
28   */
29  public interface Container extends Wrapper {
30  	
31  	/**
32  	 * Returns the type of the elements that are contained in this container.
33  	 * For example, if this container wraps an array of
34  	 * <code>int</code>s, <code>Integer.TYPE</code> should be returned.
35  	 * 
36  	 * @param clazz
37  	 *            the container's type
38  	 * @return the type of the elements that are container by the given object
39  	 * @throws WrapperException
40  	 *             if <code>container</code> is null or <br>
41  	 *             the type of the elements that are container could not be
42  	 *             determined
43  	 */
44  	public Class getContainedType() throws WrapperException;
45  
46  	/**
47  	 * Exposes an iterator over the contents of the container. Note that in many
48  	 * cases, an Iterator may only be used once and is then considered invalid.
49  	 * If you need to loop through the contents of the iterator multiple times,
50  	 * you will have to copy the contents of the iterator to some other
51  	 * structure, such as a java.util.List.
52  	 * 
53  	 * @return an Iterator over the elements in the container
54  	 * @throws WrapperException
55  	 *             if <code>container</code> is <code>null</code> or <br>
56  	 *             the Iterator could not be created for some reason
57  	 */
58  	public Iterator getIterator() throws WrapperException;
59  	
60  }