1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.util;
20
21 import java.util.AbstractCollection;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.NoSuchElementException;
25
26 import org.apache.hadoop.hbase.classification.InterfaceAudience;
27
28
29
30
31
32
33
34 @InterfaceAudience.Private
35 public class ConcatenatedLists<T> extends AbstractCollection<T> {
36 protected final ArrayList<List<T>> components = new ArrayList<List<T>>();
37 protected int size = 0;
38
39 public void addAllSublists(List<? extends List<T>> items) {
40 for (List<T> list : items) {
41 addSublist(list);
42 }
43 }
44
45 public void addSublist(List<T> items) {
46 if (!items.isEmpty()) {
47 this.components.add(items);
48 this.size += items.size();
49 }
50 }
51
52 @Override
53 public int size() {
54 return this.size;
55 }
56
57 @Override
58 public java.util.Iterator<T> iterator() {
59 return new Iterator();
60 }
61
62 @edu.umd.cs.findbugs.annotations.SuppressWarnings(
63 value="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD",
64 justification="nextWasCalled is using by StripeStoreFileManager")
65 public class Iterator implements java.util.Iterator<T> {
66 protected int currentComponent = 0;
67 protected int indexWithinComponent = -1;
68 protected boolean nextWasCalled = false;
69
70 @Override
71 public boolean hasNext() {
72 return (currentComponent + 1) < components.size()
73 || ((currentComponent + 1) == components.size()
74 && ((indexWithinComponent + 1) < components.get(currentComponent).size()));
75 }
76
77 @Override
78 public T next() {
79 if (!components.isEmpty()) {
80 this.nextWasCalled = true;
81 List<T> src = components.get(currentComponent);
82 if (++indexWithinComponent < src.size()) return src.get(indexWithinComponent);
83 if (++currentComponent < components.size()) {
84 indexWithinComponent = 0;
85 src = components.get(currentComponent);
86 assert src.size() > 0;
87 return src.get(indexWithinComponent);
88 }
89 }
90 this.nextWasCalled = false;
91 throw new NoSuchElementException();
92 }
93
94 @Override
95 public void remove() {
96 throw new UnsupportedOperationException();
97 }
98 }
99 }