pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / facet / src / java / org / apache / lucene / facet / index / attributes / CategoryAttributesIterable.java
1 package org.apache.lucene.facet.index.attributes;
2
3 import java.util.Iterator;
4
5 import org.apache.lucene.facet.index.streaming.CategoryAttributesStream;
6 import org.apache.lucene.facet.taxonomy.CategoryPath;
7
8 /**
9  * Licensed to the Apache Software Foundation (ASF) under one or more
10  * contributor license agreements.  See the NOTICE file distributed with
11  * this work for additional information regarding copyright ownership.
12  * The ASF licenses this file to You under the Apache License, Version 2.0
13  * (the "License"); you may not use this file except in compliance with
14  * the License.  You may obtain a copy of the License at
15  *
16  *     http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  */
24
25 /**
26  * This class transforms an {@link Iterable} of {@link CategoryPath} objects
27  * into an {@link Iterable} of {@link CategoryAttribute} objects, which can be
28  * used to construct a {@link CategoryAttributesStream}.
29  * 
30  * @lucene.experimental
31  */
32 public class CategoryAttributesIterable implements Iterable<CategoryAttribute> {
33
34   private Iterable<CategoryPath> inputIterable;
35
36   public CategoryAttributesIterable(Iterable<CategoryPath> inputIterable) {
37     this.inputIterable = inputIterable;
38   }
39
40   public Iterator<CategoryAttribute> iterator() {
41     return new CategoryAttributesIterator(this.inputIterable);
42   }
43
44   private static class CategoryAttributesIterator implements Iterator<CategoryAttribute> {
45
46     private Iterator<CategoryPath> internalIterator;
47     private CategoryAttributeImpl categoryAttributeImpl;
48
49     public CategoryAttributesIterator(Iterable<CategoryPath> inputIterable) {
50       this.internalIterator = inputIterable.iterator();
51       this.categoryAttributeImpl = new CategoryAttributeImpl();
52     }
53
54     public boolean hasNext() {
55       return this.internalIterator.hasNext();
56     }
57
58     public CategoryAttribute next() {
59       this.categoryAttributeImpl.setCategoryPath(this.internalIterator
60           .next());
61       return this.categoryAttributeImpl;
62     }
63
64     public void remove() {
65       this.internalIterator.remove();
66     }
67
68   }
69 }