PredefinedBucketsFacetExtractor.java
2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.RepositoryException
* javax.jcr.Value
* javax.jcr.ValueFactory
*/
package com.day.cq.search.facets.extractors;
import com.day.cq.search.facets.Bucket;
import com.day.cq.search.facets.Facet;
import com.day.cq.search.facets.buckets.PredefinedBucket;
import com.day.cq.search.facets.extractors.FacetImpl;
import com.day.cq.search.facets.extractors.PropertyFacetExtractor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
public class PredefinedBucketsFacetExtractor
extends PropertyFacetExtractor {
private List<PredefinedBucket> buckets = new ArrayList<PredefinedBucket>();
private Facet facet = null;
public PredefinedBucketsFacetExtractor(String propertyRelPath) {
super(propertyRelPath);
}
public PredefinedBucketsFacetExtractor(String propertyRelPath, Collection<? extends PredefinedBucket> buckets) {
super(propertyRelPath);
this.buckets.addAll(buckets);
}
public void addPredefinedBucket(PredefinedBucket bucket) {
this.buckets.add(bucket);
}
@Override
protected void handleValue(Value value) throws RepositoryException {
for (PredefinedBucket bucket : this.buckets) {
bucket.acceptValue(value);
}
}
@Override
public Facet getFacet() {
if (this.facet == null) {
if (this.buckets == null) {
return null;
}
Iterator<PredefinedBucket> it = this.buckets.iterator();
while (it.hasNext()) {
if (it.next().getCount() != 0) continue;
it.remove();
}
this.facet = new FacetImpl(this.buckets);
}
return this.facet;
}
@Override
protected List<Value> filter(List<Value> values, ValueFactory vf) throws RepositoryException {
return values;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || obj.getClass() != this.getClass()) {
return false;
}
PredefinedBucketsFacetExtractor other = (PredefinedBucketsFacetExtractor)obj;
if (this.propertyRelPath != other.propertyRelPath && !this.propertyRelPath.equals(other.propertyRelPath)) {
return false;
}
if (this.buckets != other.buckets && !this.buckets.equals(other.buckets)) {
return false;
}
return true;
}
public int hashCode() {
int hash = 7;
hash = 31 * hash + (this.propertyRelPath == null ? 0 : this.propertyRelPath.hashCode());
hash = 31 * hash + (this.buckets == null ? 0 : this.buckets.hashCode());
return hash;
}
}