1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package org.apache.hbase.codec.prefixtree.scanner;
20
21 import org.apache.hadoop.classification.InterfaceAudience;
22 import org.apache.hbase.Cell;
23
24 /**
25 * Alternate name may be CellInputStream
26 * <p/>
27 * An interface for iterating through a sequence of cells. Similar to Java's Iterator, but without
28 * the hasNext() or remove() methods. The hasNext() method is problematic because it may require
29 * actually loading the next object, which in turn requires storing the previous object somewhere.
30 * The core data block decoder should be as fast as possible, so we push the complexity and
31 * performance expense of concurrently tracking multiple cells to layers above the CellScanner.
32 * <p/>
33 * The getCurrentCell() method will return a reference to a Cell implementation. This reference may
34 * or may not point to a reusable cell implementation, so users of the CellScanner should not, for
35 * example, accumulate a List of Cells. All of the references may point to the same object, which
36 * would be the latest state of the underlying Cell. In short, the Cell is mutable.
37 * <p/>
38 * At a minimum, an implementation will need to be able to advance from one cell to the next in a
39 * LinkedList fashion. The nextQualifier(), nextFamily(), and nextRow() methods can all be
40 * implemented by calling nextCell(), however, if the DataBlockEncoding supports random access into
41 * the block then it may provide smarter versions of these methods.
42 * <p/>
43 * Typical usage:
44 *
45 * <pre>
46 * while (scanner.nextCell()) {
47 * Cell cell = scanner.getCurrentCell();
48 * // do something
49 * }
50 * </pre>
51 */
52 @InterfaceAudience.Private
53 public interface CellScanner{
54
55 /**
56 * Reset any state in the scanner so it appears it was freshly opened.
57 */
58 void resetToBeforeFirstEntry();
59
60 /**
61 * @return the current Cell which may be mutable
62 */
63 Cell getCurrent();
64
65 /**
66 * Advance the scanner 1 cell.
67 * @return true if the next cell is found and getCurrentCell() will return a valid Cell
68 */
69 boolean next();
70
71 }