%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.om.page.psml.FilteredFragmentList |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | package org.apache.jetspeed.om.page.psml; |
|
18 | ||
19 | import java.util.AbstractList; |
|
20 | import java.util.List; |
|
21 | import java.util.ListIterator; |
|
22 | ||
23 | /** |
|
24 | * FragmentList |
|
25 | * |
|
26 | * @author <a href="mailto:rwatler@apache.org">Randy Watler</a> |
|
27 | * @version $Id$ |
|
28 | */ |
|
29 | class FilteredFragmentList extends AbstractList |
|
30 | { |
|
31 | private FragmentImpl fragment; |
|
32 | private List filteredList; |
|
33 | ||
34 | FilteredFragmentList(FragmentImpl fragment, List filteredList) |
|
35 | { |
|
36 | 0 | super(); |
37 | 0 | this.fragment = fragment; |
38 | 0 | this.filteredList = filteredList; |
39 | 0 | } |
40 | ||
41 | /* (non-Javadoc) |
|
42 | * @see java.util.List#add(int,java.lang.Object) |
|
43 | */ |
|
44 | public void add(int index, Object element) |
|
45 | { |
|
46 | // implement for modifiable AbstractList |
|
47 | 0 | filteredList.add(index, element); |
48 | // add object to persistent list |
|
49 | 0 | fragment.accessFragments().add(element); |
50 | // maintain page implementation reference |
|
51 | 0 | if ((fragment.getPage() != null) && (element instanceof FragmentImpl)) |
52 | { |
|
53 | 0 | ((FragmentImpl)element).setPage(fragment.getPage()); |
54 | } |
|
55 | 0 | } |
56 | ||
57 | /* (non-Javadoc) |
|
58 | * @see java.util.List#get(int) |
|
59 | */ |
|
60 | public Object get(int index) |
|
61 | { |
|
62 | // implement for modifiable AbstractList |
|
63 | 0 | return filteredList.get(index); |
64 | } |
|
65 | ||
66 | /* (non-Javadoc) |
|
67 | * @see java.util.List#remove(int) |
|
68 | */ |
|
69 | public Object remove(int index) |
|
70 | { |
|
71 | // implement for modifiable AbstractList |
|
72 | 0 | Object o = filteredList.remove(index); |
73 | // remove removed object from persistent list |
|
74 | 0 | if (o != null) |
75 | { |
|
76 | 0 | ListIterator iter = fragment.accessFragments().listIterator(); |
77 | 0 | while (iter.hasNext()) |
78 | { |
|
79 | 0 | if (iter.next() == o) |
80 | { |
|
81 | 0 | iter.remove(); |
82 | 0 | break; |
83 | } |
|
84 | } |
|
85 | } |
|
86 | 0 | return o; |
87 | } |
|
88 | ||
89 | /* (non-Javadoc) |
|
90 | * @see java.util.List#set(int,java.lang.Object) |
|
91 | */ |
|
92 | public Object set(int index, Object element) |
|
93 | { |
|
94 | // implement for modifiable AbstractList |
|
95 | 0 | Object o = filteredList.set(index, element); |
96 | // replace replaced object in persistent list |
|
97 | 0 | if (o != null) |
98 | { |
|
99 | 0 | ListIterator iter = fragment.accessFragments().listIterator(); |
100 | 0 | while (iter.hasNext()) |
101 | { |
|
102 | 0 | if (iter.next() == o) |
103 | { |
|
104 | 0 | iter.set(element); |
105 | 0 | break; |
106 | } |
|
107 | } |
|
108 | } |
|
109 | // maintain page implementation reference |
|
110 | 0 | if ((fragment.getPage() != null) && (element instanceof FragmentImpl)) |
111 | { |
|
112 | 0 | ((FragmentImpl)element).setPage(fragment.getPage()); |
113 | } |
|
114 | 0 | return o; |
115 | } |
|
116 | ||
117 | /* (non-Javadoc) |
|
118 | * @see java.util.List#size() |
|
119 | */ |
|
120 | public int size() |
|
121 | { |
|
122 | // implement for modifiable AbstractList |
|
123 | 0 | return filteredList.size(); |
124 | } |
|
125 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |