Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FilterArtifacts |
|
| 1.5714285714285714;1.571 |
1 | package org.apache.maven.shared.artifact.filter.collection; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | /** | |
23 | * | |
24 | */ | |
25 | ||
26 | import java.util.ArrayList; | |
27 | import java.util.Iterator; | |
28 | import java.util.Set; | |
29 | ||
30 | /** | |
31 | * @author <a href="mailto:brianf@apache.org">Brian Fox</a> | |
32 | * @version $Id: FilterArtifacts.java 661727 2008-05-30 14:21:49Z bentmann $ | |
33 | */ | |
34 | public class FilterArtifacts | |
35 | { | |
36 | 6 | private ArrayList filters = new ArrayList(); |
37 | ||
38 | public FilterArtifacts() | |
39 | 6 | { |
40 | 6 | filters = new ArrayList(); |
41 | 6 | } |
42 | ||
43 | /** | |
44 | * Removes all of the elements from this list. The list will be empty after this call returns. | |
45 | */ | |
46 | public void clearFilters() | |
47 | { | |
48 | 2 | filters.clear(); |
49 | 2 | } |
50 | ||
51 | /** | |
52 | * Appends the specified element to the end of this list. | |
53 | * | |
54 | * @param filter element to be appended to this list. | |
55 | */ | |
56 | public void addFilter( ArtifactsFilter filter ) | |
57 | { | |
58 | 10 | if ( filter != null ) |
59 | { | |
60 | 8 | filters.add( filter ); |
61 | } | |
62 | 10 | } |
63 | ||
64 | /** | |
65 | * Inserts the specified element at the specified position in this list. Shifts the element currently at that | |
66 | * position (if any) and any subsequent elements to the right (adds one to their indices). | |
67 | * | |
68 | * @param index index at which the specified element is to be inserted. | |
69 | * @param element element to be inserted. | |
70 | * @throws IndexOutOfBoundsException if index is out of range <tt>(index < 0 || index > size())</tt>. | |
71 | */ | |
72 | public void addFilter( int index, ArtifactsFilter filter ) | |
73 | { | |
74 | 2 | if ( filter != null ) |
75 | { | |
76 | 2 | filters.add( index, filter ); |
77 | } | |
78 | 2 | } |
79 | ||
80 | public Set filter( Set artifacts ) | |
81 | throws ArtifactFilterException | |
82 | { | |
83 | // apply filters | |
84 | 10 | Iterator filterIterator = filters.iterator(); |
85 | 20 | while ( filterIterator.hasNext() ) |
86 | { | |
87 | // log(artifacts,log); | |
88 | 10 | ArtifactsFilter filter = (ArtifactsFilter) filterIterator.next(); |
89 | try | |
90 | { | |
91 | 10 | artifacts = filter.filter( artifacts ); |
92 | } | |
93 | 4 | catch ( NullPointerException e ) |
94 | { | |
95 | // don't do anything, just skip this. | |
96 | 4 | continue; |
97 | 6 | } |
98 | 6 | } |
99 | ||
100 | 10 | return artifacts; |
101 | } | |
102 | ||
103 | /** | |
104 | * @return Returns the filters. | |
105 | */ | |
106 | public ArrayList getFilters() | |
107 | { | |
108 | 34 | return this.filters; |
109 | } | |
110 | ||
111 | /** | |
112 | * @param filters The filters to set. | |
113 | */ | |
114 | public void setFilters( ArrayList filters ) | |
115 | { | |
116 | 4 | this.filters = filters; |
117 | 4 | } |
118 | } |