]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/ListAdapter.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils.datastructures / src / org / simantics / utils / datastructures / ListAdapter.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.utils.datastructures;
13
14 import java.util.Collection;
15 import java.util.List;
16 import java.util.ListIterator;
17
18 public class ListAdapter<Domain,Range,C extends List<Domain>> 
19     extends CollectionAdapter<Domain,Range,C>
20     implements List<Range> {
21
22     public ListAdapter(Converter<Domain,Range> converter, C collection) {
23         super(converter, collection);
24     }
25     
26     @Override
27     public void add(int index, Range element) {
28         collection.add(index, converter.convertFrom(element));        
29     }
30
31     @SuppressWarnings("unchecked")
32     @Override
33     public boolean addAll(int index, Collection<? extends Range> c) {
34         return collection.addAll(index, new CollectionAdapter<Range, Domain, Collection<Range>>(inverseConverter(converter), (Collection<Range>)c));
35     }
36
37     @Override
38     public Range get(int index) {
39         return converter.convertTo(collection.get(index));        
40     }
41
42     @SuppressWarnings("unchecked")
43     @Override
44     public int indexOf(Object o) {
45         return collection.indexOf(converter.convertFrom((Range)o));
46     }
47
48     @SuppressWarnings("unchecked")
49     @Override
50     public int lastIndexOf(Object o) {
51         return collection.lastIndexOf(converter.convertFrom((Range)o));
52     }
53     
54     @Override
55     public ListIterator<Range> listIterator() {
56         return new ListIteratorAdapter<Domain, Range, ListIterator<Domain>>
57             (converter, collection.listIterator());
58     }
59
60     @Override
61     public ListIterator<Range> listIterator(int index) {
62         return new ListIteratorAdapter<Domain, Range, ListIterator<Domain>>
63             (converter, collection.listIterator(index));                
64     }
65
66     @Override
67     public Range remove(int index) {
68         return converter.convertTo(collection.remove(index));
69     }
70
71     @Override
72     public Range set(int index, Range element) {
73         return converter.convertTo(collection.set(index, converter.convertFrom(element)));
74     }
75
76     @Override
77     public List<Range> subList(int fromIndex, int toIndex) {
78         return new ListAdapter<Domain,Range,List<Domain>>(converter, collection.subList(fromIndex, toIndex)); 
79     }    
80
81 }