Java Doc for LazyDynaList.java in  » Library » Apache-commons-beanutils-1.8.0-BETA-src » org » apache » commons » beanutils » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache commons beanutils 1.8.0 BETA src » org.apache.commons.beanutils 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.util.ArrayList
   org.apache.commons.beanutils.LazyDynaList

LazyDynaList
public class LazyDynaList extends ArrayList (Code)

Lazy DynaBean List.

There are two main purposes for this class:

  • To provide Lazy List behaviour - automatically growing and populating the List with either DynaBean, java.util.Map or POJO Beans.
  • To provide a straight forward way of putting a Collection or Array into the lazy list and a straight forward way to get it out again at the end.

All elements added to the List are stored as DynaBean's:

  • java.util.Map elements are "wrapped" in a LazyDynaMap.
  • POJO Bean elements are "wrapped" in a WrapDynaBean.
  • DynaBean's are stored un-changed.

toArray()

The toArray() method returns an array of the elements of the appropriate type. If the LazyDynaList is populated with java.util.Map objects a Map[] array is returned. If the list is populated with POJO Beans an appropriate array of the POJO Beans is returned. Otherwise a DynaBean[] array is returned.

toDynaBeanArray()

The toDynaBeanArray() method returns a DynaBean[] array of the elements in the List.

N.B.All the elements in the List must be the same type. If the DynaClass or Class of the LazyDynaList's elements is not specified, then it will be automatically set to the type of the first element populated.

Example 1

If you have an array of java.util.Map[] - you can put that into a LazyDynaList.


 TreeMap[] myArray = .... // your Map[]
 List lazyList = new LazyDynaList(myArray);
 

New elements of the appropriate Map type are automatically populated:


 // get(index) automatically grows the list
 DynaBean newElement = (DynaBean)lazyList.get(lazyList.size());
 newElement.put("someProperty", "someValue");
 

Once you've finished you can get back an Array of the elements of the appropriate type:


 // Retrieve the array from the list
 TreeMap[] myArray = (TreeMap[])lazyList.toArray());
 

Example 2

Alternatively you can create an empty List and specify the Class for List's elements. The LazyDynaList uses the Class to automatically populate elements:


 // e.g. For Maps
 List lazyList = new LazyDynaList(TreeMap.class);
 // e.g. For POJO Beans
 List lazyList = new LazyDynaList(MyPojo.class);
 // e.g. For DynaBeans
 List lazyList = new LazyDynaList(MyDynaBean.class);
 

Example 3

Alternatively you can create an empty List and specify the DynaClass for List's elements. The LazyDynaList uses the DynaClass to automatically populate elements:


 // e.g. For Maps
 DynaClass dynaClass = new LazyDynaMap(new HashMap());
 List lazyList = new LazyDynaList(dynaClass);
 // e.g. For POJO Beans
 DynaClass dynaClass = (new WrapDynaBean(myPojo)).getDynaClass();
 List lazyList = new LazyDynaList(dynaClass);
 // e.g. For DynaBeans
 DynaClass dynaClass = new BasicDynaClass(properties);
 List lazyList = new LazyDynaList(dynaClass);
 

N.B. You may wonder why control the type using a DynaClass rather than the Class as in the previous example - the reason is that some DynaBean implementations don't have a default empty constructor and therefore need to be instantiated using the DynaClass.newInstance() method.

Example 4

A slight variation - set the element type using either the setElementType(Class) method or the setElementDynaClass(DynaClass) method - then populate with the normal java.util.List methods(i.e. add(), addAll() or set()).


 // Create a new LazyDynaList (100 element capacity)
 LazyDynaList lazyList = new LazyDynaList(100);
 // Either Set the element type...
 lazyList.setElementType(TreeMap.class);
 // ...or the element DynaClass...
 lazyList.setElementDynaClass(new MyCustomDynaClass());
 // Populate from a collection
 lazyList.addAll(myCollection);
 

author:
   Niall Pemberton
version:
   $Revision: 555824 $ $Date: 2007-07-13 01:27:15 +0100 (Fri, 13 Jul 2007) $



Constructor Summary
public  LazyDynaList()
     Default Constructor.
public  LazyDynaList(int capacity)
     Construct a LazyDynaList with the specified capacity.
public  LazyDynaList(DynaClass elementDynaClass)
     Construct a LazyDynaList with a specified DynaClass for its elements.
public  LazyDynaList(Class elementType)
     Construct a LazyDynaList with a specified type for its elements.
public  LazyDynaList(Collection collection)
     Construct a LazyDynaList populated with the elements of a Collection.
public  LazyDynaList(Object[] array)
     Construct a LazyDynaList populated with the elements of an Array.

Method Summary
public  voidadd(int index, Object element)
    
public  booleanadd(Object element)
    

Add an element to the List.


Parameters:
  element - The new element to add.
public  booleanaddAll(Collection collection)
    

Add all the elements from a Collection to the list.
Parameters:
  collection - The Collection of new elements.

public  booleanaddAll(int index, Collection collection)
    

Insert all the elements from a Collection into the list at a specified position.

If the index position is greater than the current size of the List, then the List is automatically grown to the appropriate size.


Parameters:
  collection - The Collection of new elements.
Parameters:
  index - The index position to insert the new elements at.
public  Objectget(int index)
    

Return the element at the specified position.

If the position requested is greater than the current size of the List, then the List is automatically grown (and populated) to the appropriate size.


Parameters:
  index - The index position to insert the new elements at.
public  Objectset(int index, Object element)
    

Set the element at the specified position.

If the position requested is greater than the current size of the List, then the List is automatically grown (and populated) to the appropriate size.


Parameters:
  index - The index position to insert the new element at.
Parameters:
  element - The new element.
public  voidsetElementDynaClass(DynaClass elementDynaClass)
    
public  voidsetElementType(Class elementType)
    
public  Object[]toArray()
    
public  Object[]toArray(Object[] model)
    
public  DynaBean[]toDynaBeanArray()
    


Constructor Detail
LazyDynaList
public LazyDynaList()(Code)
Default Constructor.



LazyDynaList
public LazyDynaList(int capacity)(Code)
Construct a LazyDynaList with the specified capacity.
Parameters:
  capacity - The initial capacity of the list.



LazyDynaList
public LazyDynaList(DynaClass elementDynaClass)(Code)
Construct a LazyDynaList with a specified DynaClass for its elements.
Parameters:
  elementDynaClass - The DynaClass of the List's elements.



LazyDynaList
public LazyDynaList(Class elementType)(Code)
Construct a LazyDynaList with a specified type for its elements.
Parameters:
  elementType - The Type of the List's elements.



LazyDynaList
public LazyDynaList(Collection collection)(Code)
Construct a LazyDynaList populated with the elements of a Collection.
Parameters:
  collection - The Collection to poulate the List from.



LazyDynaList
public LazyDynaList(Object[] array)(Code)
Construct a LazyDynaList populated with the elements of an Array.
Parameters:
  array - The Array to poulate the List from.




Method Detail
add
public void add(int index, Object element)(Code)

Insert an element at the specified index position.

If the index position is greater than the current size of the List, then the List is automatically grown to the appropriate size.


Parameters:
  index - The index position to insert the new element.
Parameters:
  element - The new element to add.



add
public boolean add(Object element)(Code)

Add an element to the List.


Parameters:
  element - The new element to add. true.



addAll
public boolean addAll(Collection collection)(Code)

Add all the elements from a Collection to the list.
Parameters:
  collection - The Collection of new elements. true if elements were added.




addAll
public boolean addAll(int index, Collection collection)(Code)

Insert all the elements from a Collection into the list at a specified position.

If the index position is greater than the current size of the List, then the List is automatically grown to the appropriate size.


Parameters:
  collection - The Collection of new elements.
Parameters:
  index - The index position to insert the new elements at. true if elements were added.



get
public Object get(int index)(Code)

Return the element at the specified position.

If the position requested is greater than the current size of the List, then the List is automatically grown (and populated) to the appropriate size.


Parameters:
  index - The index position to insert the new elements at. The element at the specified position.



set
public Object set(int index, Object element)(Code)

Set the element at the specified position.

If the position requested is greater than the current size of the List, then the List is automatically grown (and populated) to the appropriate size.


Parameters:
  index - The index position to insert the new element at.
Parameters:
  element - The new element. The new element.



setElementDynaClass
public void setElementDynaClass(DynaClass elementDynaClass)(Code)

Set the element Type and DynaClass.


Parameters:
  elementDynaClass - The DynaClass of the elements.
exception:
  IllegalArgumentException - if the List alreadycontains elements or the DynaClass is null.



setElementType
public void setElementType(Class elementType)(Code)

Set the element Type and DynaClass.


Parameters:
  elementType - The type of the elements.
exception:
  IllegalArgumentException - if the List alreadycontains elements or the DynaClass is null.



toArray
public Object[] toArray()(Code)

Converts the List to an Array.

The type of Array created depends on the contents of the List:

  • If the List contains only LazyDynaMap type elements then a java.util.Map[] array will be created.
  • If the List contains only elements which are "wrapped" DynaBeans then an Object[] of the most suitable type will be created.
  • ...otherwise a DynaBean[] will be created.
  • An Array of the elements in this List.



toArray
public Object[] toArray(Object[] model)(Code)

Converts the List to an Array of the specified type.


Parameters:
  model - The model for the type of array to return An Array of the elements in this List.



toDynaBeanArray
public DynaBean[] toDynaBeanArray()(Code)

Converts the List to an DynaBean Array.

A DynaBean[] of the elements in this List.



Methods inherited from java.util.ArrayList
public boolean add(E e)(Code)(Java Doc)
public void add(int index, E element)(Code)(Java Doc)
public boolean addAll(Collection<? extends E> c)(Code)(Java Doc)
public boolean addAll(int index, Collection<? extends E> c)(Code)(Java Doc)
public void clear()(Code)(Java Doc)
public Object clone()(Code)(Java Doc)
public boolean contains(Object o)(Code)(Java Doc)
public void ensureCapacity(int minCapacity)(Code)(Java Doc)
public E get(int index)(Code)(Java Doc)
public int indexOf(Object o)(Code)(Java Doc)
public boolean isEmpty()(Code)(Java Doc)
public Iterator<E> iterator()(Code)(Java Doc)
public int lastIndexOf(Object o)(Code)(Java Doc)
public ListIterator<E> listIterator(int index)(Code)(Java Doc)
public ListIterator<E> listIterator()(Code)(Java Doc)
public E remove(int index)(Code)(Java Doc)
public boolean remove(Object o)(Code)(Java Doc)
public boolean removeAll(Collection c)(Code)(Java Doc)
protected void removeRange(int fromIndex, int toIndex)(Code)(Java Doc)
public boolean retainAll(Collection c)(Code)(Java Doc)
public E set(int index, E element)(Code)(Java Doc)
public int size()(Code)(Java Doc)
public List<E> subList(int fromIndex, int toIndex)(Code)(Java Doc)
public Object[] toArray()(Code)(Java Doc)
public T[] toArray(T[] a)(Code)(Java Doc)
public void trimToSize()(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.