1 package org.apache.lucene.facet.index.attributes;
3 import java.util.Iterator;
5 import org.apache.lucene.facet.index.streaming.CategoryAttributesStream;
6 import org.apache.lucene.facet.taxonomy.CategoryPath;
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
16 * http://www.apache.org/licenses/LICENSE-2.0
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.
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}.
30 * @lucene.experimental
32 public class CategoryAttributesIterable implements Iterable<CategoryAttribute> {
34 private Iterable<CategoryPath> inputIterable;
36 public CategoryAttributesIterable(Iterable<CategoryPath> inputIterable) {
37 this.inputIterable = inputIterable;
40 public Iterator<CategoryAttribute> iterator() {
41 return new CategoryAttributesIterator(this.inputIterable);
44 private static class CategoryAttributesIterator implements Iterator<CategoryAttribute> {
46 private Iterator<CategoryPath> internalIterator;
47 private CategoryAttributeImpl categoryAttributeImpl;
49 public CategoryAttributesIterator(Iterable<CategoryPath> inputIterable) {
50 this.internalIterator = inputIterable.iterator();
51 this.categoryAttributeImpl = new CategoryAttributeImpl();
54 public boolean hasNext() {
55 return this.internalIterator.hasNext();
58 public CategoryAttribute next() {
59 this.categoryAttributeImpl.setCategoryPath(this.internalIterator
61 return this.categoryAttributeImpl;
64 public void remove() {
65 this.internalIterator.remove();