|
1 | 1 | package com.tinkerpop.pipes.filter;
|
2 | 2 |
|
3 |
| -import com.tinkerpop.blueprints.Query; |
| 3 | +import com.tinkerpop.blueprints.Compare; |
| 4 | +import com.tinkerpop.blueprints.Contains; |
4 | 5 | import com.tinkerpop.pipes.AbstractPipe;
|
5 | 6 | import com.tinkerpop.pipes.util.PipeHelper;
|
6 | 7 | import com.tinkerpop.pipes.util.structures.AsMap;
|
|
18 | 19 | public abstract class CollectionFilterPipe<S> extends AbstractPipe<S, S> implements FilterPipe<S> {
|
19 | 20 |
|
20 | 21 | private final Collection<S> storedCollection;
|
21 |
| - private final Query.Compare compare; |
| 22 | + private final Contains contains; |
22 | 23 |
|
23 |
| - public CollectionFilterPipe(final Collection<S> storedCollection, final Query.Compare compare) { |
| 24 | + public CollectionFilterPipe(final Collection<S> storedCollection, final Contains contains) { |
24 | 25 | this.storedCollection = storedCollection;
|
25 |
| - if (compare == Query.Compare.NOT_EQUAL || compare == Query.Compare.EQUAL) { |
26 |
| - this.compare = compare; |
27 |
| - } else { |
28 |
| - throw new IllegalArgumentException("The only legal filters are equals and not equals"); |
29 |
| - } |
| 26 | + this.contains = contains; |
30 | 27 | }
|
31 | 28 |
|
32 |
| - public CollectionFilterPipe(final Query.Compare compare, final AsMap asMap, final String... namedSteps) { |
| 29 | + public CollectionFilterPipe(final Contains contains, final AsMap asMap, final String... namedSteps) { |
33 | 30 | this.storedCollection = new DynamicList<S>(asMap, namedSteps);
|
34 |
| - if (compare == Query.Compare.NOT_EQUAL || compare == Query.Compare.EQUAL) { |
35 |
| - this.compare = compare; |
36 |
| - } else { |
37 |
| - throw new IllegalArgumentException("The only legal filters are equals and not equals"); |
38 |
| - } |
| 31 | + this.contains = contains; |
39 | 32 | }
|
40 | 33 |
|
41 |
| - |
42 |
| - private boolean checkCollection(final S rightObject) { |
43 |
| - if (this.compare == Query.Compare.NOT_EQUAL) { |
44 |
| - return !this.storedCollection.contains(rightObject); |
45 |
| - } else { |
46 |
| - return this.storedCollection.contains(rightObject); |
47 |
| - } |
48 |
| - } |
49 |
| - |
50 |
| - |
51 | 34 | protected S processNextStart() {
|
52 | 35 | while (true) {
|
53 | 36 | final S s = this.starts.next();
|
54 |
| - if (this.checkCollection(s)) { |
| 37 | + if (this.contains.compare(s,storedCollection)) { |
55 | 38 | return s;
|
56 | 39 | }
|
57 | 40 | }
|
58 | 41 | }
|
59 | 42 |
|
60 | 43 | public String toString() {
|
61 | 44 | if (this.storedCollection instanceof DynamicList)
|
62 |
| - return PipeHelper.makePipeString(this, this.compare, ((DynamicList) this.storedCollection).toString()); |
| 45 | + return PipeHelper.makePipeString(this, this.contains, ((DynamicList) this.storedCollection).toString()); |
63 | 46 | else
|
64 |
| - return PipeHelper.makePipeString(this, this.compare); |
| 47 | + return PipeHelper.makePipeString(this, this.contains); |
65 | 48 | }
|
66 | 49 |
|
67 | 50 | private class DynamicList<S> extends ArrayList<S> {
|
|
0 commit comments