org.apache.commons.clazz.reflect.common
Class ReflectedList

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractList
          extended byorg.apache.commons.clazz.reflect.common.ReflectedList
All Implemented Interfaces:
Collection, List

public class ReflectedList
extends AbstractList

This is an implementation of the List interface that is based on a List property. Whenever possible, it uses concrete methods on the owner of the property to manipulate the list or array.

Consider the following example:

      List list = (List)clazz.getProperty("fooList").get(instance);
      Object value = list.get(3);
 
If instance has a getFoo(int index) method, this code will implicitly invoke it like this: getFoo(3), otherwise it will obtain the whole list or array and extract the requested element.

Version:
$Id: ReflectedList.java,v 1.6 2004/02/19 23:58:39 scolebourne Exp $
Author:
Dmitri Plotnikov

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ReflectedList(Object instance, ReflectedListProperty property)
          Constructor for ReflectedList.
 
Method Summary
 void add(int index, Object element)
          Will perform the following steps: If the instance has an add(index,element), calls that method. Othewise, if the instance has an add(element) method and index == size(), calls that method. Othewise, if the instance has a List getFoo [plural suffix]() method, calls that and inserts the element into the list. Othewise, if the instance has a Foo[] getFoo[plural suffix] () method as well as a setFoo[plural suffix] (Foo[]) method, calls the read method, copies the array into a new, one-longer, array inserting the additional element and calls the write method to assign the new array to the property.
 boolean add(Object element)
          Will perform the following steps: If the instance has an addFoo(element), calls that method. Otherwise, if the instance has an add(index,element), computes the size of the list and calls add(size(),element) . Othewise, if the instance has a List getFoo[plural suffix] () method, calls that and adds the element to the list. Othewise, if the instance has a Foo[] getFoo[plural suffix] () method as well as a setFoo[plural suffix] (Foo[]) method, calls the read method, copies the array into a new array with an additional element and calls the write method to assign the new array to the property.
 Object get(int index)
           
 Object getPropertyValue()
           
 Iterator iterator()
           
 ListIterator listIterator()
           
 ListIterator listIterator(int index)
           
 Object remove(int index)
          Will perform the following steps: If the instance has a remove(index), calls that method.
 boolean remove(Object element)
          Will perform the following steps: If the instance has an removeFoo(element), calls that method. Otherwise, if iterates over elements of the collection until it finds one equal to the supplied value.
 Object set(int index, Object element)
           
 void setPropertyValue(Object value)
           
 int size()
           
 
Methods inherited from class java.util.AbstractList
addAll, clear, equals, hashCode, indexOf, lastIndexOf, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, removeAll, retainAll, toArray, toArray
 

Constructor Detail

ReflectedList

public ReflectedList(Object instance,
                     ReflectedListProperty property)
Constructor for ReflectedList.

Method Detail

getPropertyValue

public Object getPropertyValue()

setPropertyValue

public void setPropertyValue(Object value)

size

public int size()
See Also:
Collection.size()

get

public Object get(int index)
See Also:
List.get(int)

iterator

public Iterator iterator()
See Also:
Collection.iterator()

listIterator

public ListIterator listIterator()
See Also:
List.listIterator()

listIterator

public ListIterator listIterator(int index)
See Also:
List.listIterator(int)

set

public Object set(int index,
                  Object element)
See Also:
List.set(int, java.lang.Object)

add

public boolean add(Object element)
Will perform the following steps:
  1. If the instance has an addFoo(element), calls that method.
  2. Otherwise, if the instance has an add(index,element), computes the size of the list and calls add(size(),element) .
  3. Othewise, if the instance has a List getFoo[plural suffix] () method, calls that and adds the element to the list.
  4. Othewise, if the instance has a Foo[] getFoo[plural suffix] () method as well as a setFoo[plural suffix] (Foo[]) method, calls the read method, copies the array into a new array with an additional element and calls the write method to assign the new array to the property.

See Also:
Collection.add(java.lang.Object)

add

public void add(int index,
                Object element)
Will perform the following steps:
  1. If the instance has an add(index,element), calls that method.
  2. Othewise, if the instance has an add(element) method and index == size(), calls that method.
  3. Othewise, if the instance has a List getFoo [plural suffix]() method, calls that and inserts the element into the list.
  4. Othewise, if the instance has a Foo[] getFoo[plural suffix] () method as well as a setFoo[plural suffix] (Foo[]) method, calls the read method, copies the array into a new, one-longer, array inserting the additional element and calls the write method to assign the new array to the property.

See Also:
List.add(int, java.lang.Object)

remove

public boolean remove(Object element)
Will perform the following steps:
  1. If the instance has an removeFoo(element), calls that method.
  2. Otherwise, if iterates over elements of the collection until it finds one equal to the supplied value. Then it removes it by calling remove(index)

See Also:
Collection.remove(java.lang.Object)

remove

public Object remove(int index)
Will perform the following steps:
  1. If the instance has a remove(index), calls that method.
  2. Othewise, if the instance has an add(element) method and index == size(), calls that method.
  3. Othewise, if the instance has a List getFoo [plural suffix]() method, calls that and removes the element from the list.
  4. Othewise, if the instance has a Foo[] getFoo[plural suffix] () method as well as a setFoo[plural suffix] (Foo[]) method, calls the read method, copies the array into a new, one-shorter, array removing the supplied element and calls the write method to assign the new array to the property.

See Also:
List.add(int, java.lang.Object)


Copyright © 2002-2005 The Apache Software Foundation. All Rights Reserved.