forked from javasoze/bobo
/
PathFacetIterator.java
82 lines (72 loc) · 1.8 KB
/
PathFacetIterator.java
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
/**
*
*/
package com.browseengine.bobo.facets.impl;
import java.util.List;
import java.util.NoSuchElementException;
import com.browseengine.bobo.api.BrowseFacet;
import com.browseengine.bobo.api.FacetIterator;
/**
* @author nnarkhed
*
*/
public class PathFacetIterator extends FacetIterator {
private BrowseFacet[] _facets;
private int _index;
public PathFacetIterator(List<BrowseFacet> facets) {
_facets = facets.toArray(new BrowseFacet[facets.size()]);
_index = -1;
facet = null;
count = 0;
}
/* (non-Javadoc)
* @see com.browseengine.bobo.api.FacetIterator#next()
*/
public Comparable next() {
if((_index >= 0) && !hasNext())
throw new NoSuchElementException("No more facets in this iteration");
_index++;
facet = _facets[_index].getValue();
count = _facets[_index].getHitCount();
return facet;
}
/* (non-Javadoc)
* @see java.util.Iterator#hasNext()
*/
public boolean hasNext() {
return ( (_index >= 0) && (_index < (_facets.length-1)) );
}
/* (non-Javadoc)
* @see java.util.Iterator#remove()
*/
public void remove() {
throw new UnsupportedOperationException("remove() method not supported for Facet Iterators");
}
/* (non-Javadoc)
* @see com.browseengine.bobo.api.FacetIterator#next(int)
*/
public Comparable next(int minHits)
{
while(++_index < _facets.length)
{
if(_facets[_index].getHitCount() >= minHits)
{
facet = _facets[_index].getValue();
count = _facets[_index].getHitCount();
return facet;
}
}
facet = null;
count = 0;
return facet;
}
/**
* The string from here should be already formatted. No need to reformat.
* @see com.browseengine.bobo.api.FacetIterator#format(java.lang.Object)
*/
@Override
public String format(Object val)
{
return (String)val;
}
}