1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections4.set;
18
19 import java.util.Iterator;
20 import java.util.NavigableSet;
21
22 import org.apache.commons.collections4.Predicate;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 public class PredicatedNavigableSet<E> extends PredicatedSortedSet<E> implements NavigableSet<E> {
45
46
47 private static final long serialVersionUID = 20150528L;
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 public static <E> PredicatedNavigableSet<E> predicatedNavigableSet(final NavigableSet<E> set,
64 final Predicate<? super E> predicate) {
65 return new PredicatedNavigableSet<>(set, predicate);
66 }
67
68
69
70
71
72
73
74
75
76
77
78
79 protected PredicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate) {
80 super(set, predicate);
81 }
82
83 @Override
84 public E ceiling(final E e) {
85 return decorated().ceiling(e);
86 }
87
88
89
90
91
92
93 @Override
94 protected NavigableSet<E> decorated() {
95 return (NavigableSet<E>) super.decorated();
96 }
97
98 @Override
99 public Iterator<E> descendingIterator() {
100 return decorated().descendingIterator();
101 }
102
103 @Override
104 public NavigableSet<E> descendingSet() {
105 return predicatedNavigableSet(decorated().descendingSet(), predicate);
106 }
107
108 @Override
109 public E floor(final E e) {
110 return decorated().floor(e);
111 }
112
113 @Override
114 public NavigableSet<E> headSet(final E toElement, final boolean inclusive) {
115 final NavigableSet<E> head = decorated().headSet(toElement, inclusive);
116 return predicatedNavigableSet(head, predicate);
117 }
118
119 @Override
120 public E higher(final E e) {
121 return decorated().higher(e);
122 }
123
124 @Override
125 public E lower(final E e) {
126 return decorated().lower(e);
127 }
128
129 @Override
130 public E pollFirst() {
131 return decorated().pollFirst();
132 }
133
134 @Override
135 public E pollLast() {
136 return decorated().pollLast();
137 }
138
139 @Override
140 public NavigableSet<E> subSet(final E fromElement, final boolean fromInclusive, final E toElement,
141 final boolean toInclusive) {
142 final NavigableSet<E> sub = decorated().subSet(fromElement, fromInclusive, toElement, toInclusive);
143 return predicatedNavigableSet(sub, predicate);
144 }
145
146 @Override
147 public NavigableSet<E> tailSet(final E fromElement, final boolean inclusive) {
148 final NavigableSet<E> tail = decorated().tailSet(fromElement, inclusive);
149 return predicatedNavigableSet(tail, predicate);
150 }
151
152 }