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.reflect;
17  
18  /**
19   * A reflector for 'container-like' structures that have a logical ordering
20   * which can be used to retrieve elements at a specific index within the
21   * structure.  Lists, SortedSets, and arrays are good examples of indexed
22   * structures.  Note that some indexed structures will have O(1) methods for
23   * retrieving objects at a given index (ArrayList, TreeSet, array) and others
24   * will have O(n) methods for retrieving objects at a given index (LinkedList).
25   * 
26   * @author Matt Sgarlata
27   * @since Nov 14, 2004
28   */
29  public interface IndexedContainerReflector extends ContainerReflector, SizableReflector {
30  
31  	/**
32  	 * Gets the element at the specified index. Valid indexes range between 0
33  	 * and one less than the container object's size, inclusive.
34  	 * 
35  	 * @param container
36  	 *            the container object
37  	 * @param index
38  	 *            a number indiciating which element should be retrieved
39  	 * @return the object at the specified index
40  	 * @throws ReflectionException
41  	 *             if <code>container</code> is null or <br>
42  	 *             <code>index</code> is not a valid index for the given
43  	 *             container object or <br>
44  	 *             the object at the specified index could not be retrieved for
45  	 *             some reason
46  	 */
47  	public Object get(Object container, int index) throws ReflectionException;
48  
49  }