Index: modules/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupsCollector1.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- modules/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupsCollector1.java	(revision )
+++ modules/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupsCollector1.java	(revision )
@@ -0,0 +1,121 @@
+package org.apache.lucene.search.grouping.term;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.search.FieldCache;
+import org.apache.lucene.search.grouping.AbstractAllGroupsCollector;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefHash;
+
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * @lucene.experimental
+ */
+public class TermAllGroupsCollector1 extends AbstractAllGroupsCollector<BytesRef> {
+
+  private final String groupField;
+  private final BytesRefHash groups;
+
+  private final BytesRef spareBytesRef = new BytesRef();
+  private FieldCache.DocTermsIndex index;
+  private ByteRefHashCollection result;
+
+  /**
+   * Constructs a {@link org.apache.lucene.search.grouping.AbstractAllGroupsCollector}.
+   *
+   * @param groupField The field to group by
+   */
+  public TermAllGroupsCollector1(String groupField) {
+    this.groupField = groupField;
+    groups = new BytesRefHash();
+  }
+
+  public void collect(int doc) throws IOException {
+    groups.add(index.getTerm(doc, spareBytesRef));
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  public Collection<BytesRef> getGroups() {
+    return result == null ? result = new ByteRefHashCollection(groups) : result;
+  }
+
+  public int getGroupCount() {
+    return groups.size();
+  }
+
+  public void setNextReader(AtomicReaderContext context) throws IOException {
+    index = FieldCache.DEFAULT.getTermsIndex(context.reader(), groupField);
+  }
+
+  static class ByteRefHashCollection extends AbstractCollection<BytesRef> {
+
+    private final BytesRefHash source;
+    private final int[] ords;
+    private final BytesRef spare = new BytesRef();
+
+    ByteRefHashCollection(BytesRefHash source) {
+      this.source = source;
+      this.ords = source.compact();
+    }
+
+    public Iterator<BytesRef> iterator() {
+      if (source.size() == 0) {
+        return new Iterator<BytesRef>() {
+          public boolean hasNext() {
+            return false;
+          }
+
+          public BytesRef next() {
+            throw new NoSuchElementException("Empty iterator");
+          }
+
+          public void remove() {
+            throw new UnsupportedOperationException("Remove not supported");
+          }
+        };
+      } else {
+        return new Iterator<BytesRef>() {
+
+          final int lastPos = source.size() - 1;
+          int cursor;
+
+          public boolean hasNext() {
+            return cursor < lastPos;
+          }
+
+          public BytesRef next() {
+            return source.get(ords[cursor++], spare);
+          }
+
+          public void remove() {
+            throw new UnsupportedOperationException("Remove not supported");
+          }
+        };
+      }
+    }
+
+    public int size() {
+      return source.size();
+    }
+  }
+}
