1 package org.apache.lucene.facet.index.streaming;
3 import java.io.IOException;
4 import java.util.Iterator;
6 import org.apache.lucene.analysis.TokenStream;
8 import org.apache.lucene.facet.index.attributes.CategoryAttribute;
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed with
13 * this work for additional information regarding copyright ownership.
14 * The ASF licenses this file to You under the Apache License, Version 2.0
15 * (the "License"); you may not use this file except in compliance with
16 * the License. You may obtain a copy of the License at
18 * http://www.apache.org/licenses/LICENSE-2.0
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
28 * An attribute stream built from an {@link Iterable} of
29 * {@link CategoryAttribute}. This stream should then be passed through several
30 * filters (see {@link CategoryParentsStream}, {@link CategoryListTokenizer} and
31 * {@link CategoryTokenizer}) until a token stream is produced that can be
34 * A CategoryAttributesStream object can be reused for producing more than one
35 * stream. To do that, the user should cause the underlying
36 * Iterable<CategoryAttribute> object to return a new set of categories, and
37 * then call {@link #reset()} to allow this stream to be used again.
39 * @lucene.experimental
41 public class CategoryAttributesStream extends TokenStream {
43 protected CategoryAttribute categoryAttribute;
45 private Iterable<CategoryAttribute> iterable;
46 private Iterator<CategoryAttribute> iterator;
52 * {@link Iterable} of {@link CategoryAttribute}, from which
53 * categories are taken.
55 public CategoryAttributesStream(Iterable<CategoryAttribute> iterable) {
56 this.iterable = iterable;
58 this.categoryAttribute = this.addAttribute(CategoryAttribute.class);
62 public final boolean incrementToken() throws IOException {
63 if (iterator == null) {
64 if (iterable == null) {
67 iterator = iterable.iterator();
69 if (iterator.hasNext()) {
70 categoryAttribute.set(iterator.next());