3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 package org
.apache
.hadoop
.hbase
.util
;
21 import java
.util
.ArrayList
;
22 import java
.util
.Collections
;
23 import java
.util
.Iterator
;
24 import java
.util
.List
;
25 import java
.util
.SortedSet
;
27 import org
.apache
.yetus
.audience
.InterfaceAudience
;
28 import org
.apache
.hadoop
.hbase
.Cell
;
29 import org
.apache
.hadoop
.hbase
.CellComparator
;
30 import org
.apache
.hadoop
.hbase
.regionserver
.NonReversedNonLazyKeyValueScanner
;
33 * Utility scanner that wraps a sortable collection and serves as a KeyValueScanner.
35 @InterfaceAudience.Private
36 public class CollectionBackedScanner
extends NonReversedNonLazyKeyValueScanner
{
37 final private Iterable
<Cell
> data
;
38 final CellComparator comparator
;
39 private Iterator
<Cell
> iter
;
42 public CollectionBackedScanner(SortedSet
<Cell
> set
) {
43 this(set
, CellComparator
.getInstance());
46 public CollectionBackedScanner(SortedSet
<Cell
> set
,
47 CellComparator comparator
) {
48 this.comparator
= comparator
;
53 public CollectionBackedScanner(List
<Cell
> list
) {
54 this(list
, CellComparator
.getInstance());
57 public CollectionBackedScanner(List
<Cell
> list
,
58 CellComparator comparator
) {
59 Collections
.sort(list
, comparator
);
60 this.comparator
= comparator
;
65 public CollectionBackedScanner(CellComparator comparator
,
67 this.comparator
= comparator
;
69 List
<Cell
> tmp
= new ArrayList
<>(array
.length
);
70 Collections
.addAll(tmp
, array
);
71 Collections
.sort(tmp
, comparator
);
77 iter
= data
.iterator();
79 current
= iter
.next();
90 Cell oldCurrent
= current
;
92 current
= iter
.next();
100 public boolean seek(Cell seekCell
) {
102 iter
= data
.iterator();
103 return reseek(seekCell
);
107 public boolean reseek(Cell seekCell
) {
108 while(iter
.hasNext()){
109 Cell next
= iter
.next();
110 int ret
= comparator
.compare(next
, seekCell
);
121 public void close() {