View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2006 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
16   */
17  package ch.elca.el4j.util.collections.impl;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  import java.util.NoSuchElementException;
22  
23  import ch.elca.el4j.util.codingsupport.CollectionUtils;
24  import ch.elca.el4j.util.collections.ExtendedWritableList;
25  import ch.elca.el4j.util.collections.FilteredList;
26  import ch.elca.el4j.util.collections.TransformedList;
27  import ch.elca.el4j.util.collections.helpers.Filter;
28  import ch.elca.el4j.util.collections.helpers.Function;
29  
30  /**
31   * A default implementation of the ExtendedWritableList interface.
32   *
33   * @param <T> the member type
34   *
35   * @svnLink $Revision: 3875 $;$Date: 2009-08-04 14:35:53 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/core/src/main/java/ch/elca/el4j/util/collections/impl/ExtendedArrayList.java $
36   *
37   * @author Adrian Moos (AMS)
38   */
39  public class ExtendedArrayList<T> extends ArrayList<T>
40  	implements ExtendedWritableList<T> {
41  	
42  	/** creates an empty list. */
43  	public ExtendedArrayList() { }
44  	
45  	/** creates a list containing the arguments.
46  	 * @param ts .
47  	 */
48  	public ExtendedArrayList(T... ts) {
49  		add(ts);
50  	}
51  	
52  	/** Creates a list by shallow-copying {@code iter}.
53  	 * @param iter the iterable to copy.
54  	 */
55  	public ExtendedArrayList(Iterable<T> iter) {
56  		for (T t : iter) {
57  			add(t);
58  		}
59  	}
60  	
61  	/**
62  	 * {@inheritDoc}
63  	 */
64  	public void add(T... ts) {
65  		for (T t : ts) {
66  			add(t);
67  		}
68  	}
69  	
70  	/**
71  	 * {@inheritDoc}
72  	 */
73  	public void remove(T... ts) {
74  		for (T t : ts) {
75  			remove(t);
76  		}
77  	}
78  	
79  	/**
80  	 * {@inheritDoc}
81  	 */
82  	public void swap(int i, int j) {
83  		T t = get(i);
84  		set(i, get(j));
85  		set(j, t);
86  	}
87  
88  	/**
89  	 * {@inheritDoc}
90  	 */
91  	public void orderLike(List<? extends T> example)
92  		throws NoSuchElementException {
93  		
94  		CollectionUtils.orderLike(this, example);
95  	}
96  
97  	/**
98  	 * {@inheritDoc}
99  	 */
100 	public T[] toArray(Class<T> c) {
101 		return CollectionUtils.toArray(this, c);
102 	}
103 
104 	/**
105 	 * {@inheritDoc}
106 	 */
107 	public <O> TransformedList<T, O> mapped(Function<? super T, O> function) {
108 		return new DefaultTransformedList<T, O>(this, function);
109 	}
110 
111 	/** {@inheritDoc} */
112 	public FilteredList<T> filtered(Filter<? super T> filter) {
113 		return new DefaultFilteredList<T>(this, filter);
114 	}
115 }