##### Coverage Report - org.owasp.dependencycheck.utils.Filter

Classes in this File | Line Coverage | Branch Coverage | Complexity
Filter |
100% | 4/4
N/A | N/A
| 1.6666666666666667;1.667
Filter$1 |
100% | 2/2
N/A | N/A
| 1.6666666666666667;1.667
Filter$FilterIterator |
90% | 18/20
80% | 8/10
| 1.6666666666666667;1.667

1 |  |
     package org.owasp.dependencycheck.utils;
2 |  |
3 |  |
     import java.util.Iterator;
4 |  |
     import java.util.NoSuchElementException;
5 |  |
6 |  |
     /*
7 |  |
      * This is an abstract filter that can be used to filter iterable list.
8 |  |
      *
9 |  |
      * This Filter class was copied from:
10 |  |
      * http://erikras.com/2008/01/18/the-filter-pattern-java-conditional-abstraction-with-iterables/
11 |  |
      *
12 |  |
      * Erik Rasmussen - © 2006 - 2012 All Rights Reserved. @author Erik Rasmussen
13 |  |
      * https://plus.google.com/115403795880834599019/?rel=author
14 |  |
      */
15 | 6 |
     public abstract class Filter<T> {
16 |  |
17 |  |
         public abstract boolean passes(T object);
18 |  |
19 |  |
         public Iterator<T> filter(Iterator<T> iterator) {
20 | 1884 |
             return new FilterIterator(iterator);
21 |  |
         }
22 |  |
23 |  |
         public Iterable<T> filter(final Iterable<T> iterable) {
24 | 1884 |
             return new Iterable<T>() {
25 |  |
26 |  |
                 public Iterator<T> iterator() {
27 | 1884 |
                     return filter(iterable.iterator());
28 |  |
                 }
29 |  |
             };
30 |  |
         }
31 |  |
32 | 6 |
         private class FilterIterator implements Iterator<T> {
33 |  |
34 |  |
             private final Iterator<T> iterator;
35 |  |
             private T next;
36 |  |
37 | 1884 |
             private FilterIterator(Iterator<T> iterator) {
38 | 1884 |
                 this.iterator = iterator;
39 | 1884 |
                 toNext();
40 | 1884 |
             }
41 |  |
42 |  |
             public boolean hasNext() {
43 | 8053 |
                 return next != null;
44 |  |
             }
45 |  |
46 |  |
             public T next() {
47 | 6674 |
                 if (next == null) {
48 | 0 |
                     throw new NoSuchElementException();
49 |  |
                 }
50 | 6674 |
                 T returnValue = next;
51 | 6674 |
                 toNext();
52 | 6674 |
                 return returnValue;
53 |  |
             }
54 |  |
55 |  |
             public void remove() {
56 | 0 |
                 throw new UnsupportedOperationException();
57 |  |
             }
58 |  |
59 |  |
             private void toNext() {
60 | 8558 |
                 next = null;
61 | 12714 |
                 while (iterator.hasNext()) {
62 | 11221 |
                     T item = iterator.next();
63 | 11221 |
                     if (item != null && passes(item)) {
64 | 7065 |
                         next = item;
65 | 7065 |
                         break;
66 |  |
                     }
67 | 4156 |
                 }
68 | 8558 |
             }
69 |  |
         }
70 |  |
     }