1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.util;
21
22 import java.util.Iterator;
23
24
25
26
27 public abstract class SkipMatchIterator<T> implements Iterator<T>
28 {
29 private Iterator<T> delegate;
30 private T value;
31
32
33 public SkipMatchIterator(Iterator<T> delegate)
34 {
35 this.delegate = delegate;
36 this.value = null;
37 }
38
39 @Override
40 public boolean hasNext()
41 {
42 if (this.value != null)
43 {
44 return true;
45 }
46 if (delegate.hasNext())
47 {
48 do
49 {
50 this.value = delegate.next();
51 if (match(value))
52 {
53
54 value = null;
55 }
56 }
57 while (value == null && delegate.hasNext());
58
59 if (value != null)
60 {
61 return true;
62 }
63 else
64 {
65 return false;
66 }
67 }
68 else
69 {
70 return false;
71 }
72 }
73
74 @Override
75 public T next()
76 {
77 T value = this.value;
78 do
79 {
80 if (value == null)
81 {
82 if (hasNext())
83 {
84 value = null;
85 return this.value;
86 }
87 else
88 {
89 return null;
90 }
91 }
92 else
93 {
94 this.value = null;
95 return value;
96 }
97 }
98 while (value == null);
99 }
100
101 protected abstract boolean match(T instance);
102 }