View Javadoc

1   /**
2    *
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
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
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.
18   */
19  package org.apache.hadoop.hbase.regionserver;
20  
21  import java.util.Collection;
22  import java.util.Comparator;
23  import java.util.Iterator;
24  import java.util.NavigableSet;
25  import java.util.SortedSet;
26  import java.util.concurrent.ConcurrentNavigableMap;
27  import java.util.concurrent.ConcurrentSkipListMap;
28  
29  import org.apache.hadoop.hbase.Cell;
30  import org.apache.hadoop.hbase.KeyValue;
31  import org.apache.hadoop.hbase.classification.InterfaceAudience;
32  
33  /**
34   * A {@link java.util.Set} of {@link Cell}s implemented on top of a
35   * {@link java.util.concurrent.ConcurrentSkipListMap}.  Works like a
36   * {@link java.util.concurrent.ConcurrentSkipListSet} in all but one regard:
37   * An add will overwrite if already an entry for the added key.  In other words,
38   * where CSLS does "Adds the specified element to this set if it is not already
39   * present.", this implementation "Adds the specified element to this set EVEN
40   * if it is already present overwriting what was there previous".  The call to
41   * add returns true if no value in the backing map or false if there was an
42   * entry with same key (though value may be different).
43   * <p>Otherwise,
44   * has same attributes as ConcurrentSkipListSet: e.g. tolerant of concurrent
45   * get and set and won't throw ConcurrentModificationException when iterating.
46   */
47  @InterfaceAudience.Private
48  public class CellSkipListSet implements NavigableSet<Cell> {
49    private final ConcurrentNavigableMap<Cell, Cell> delegatee;
50  
51    CellSkipListSet(final KeyValue.KVComparator c) {
52      this.delegatee = new ConcurrentSkipListMap<Cell, Cell>(c);
53    }
54  
55    CellSkipListSet(final ConcurrentNavigableMap<Cell, Cell> m) {
56      this.delegatee = m;
57    }
58  
59    public Cell ceiling(Cell e) {
60      throw new UnsupportedOperationException("Not implemented");
61    }
62  
63    public Iterator<Cell> descendingIterator() {
64      return this.delegatee.descendingMap().values().iterator();
65    }
66  
67    public NavigableSet<Cell> descendingSet() {
68      throw new UnsupportedOperationException("Not implemented");
69    }
70  
71    public Cell floor(Cell e) {
72      throw new UnsupportedOperationException("Not implemented");
73    }
74  
75    public SortedSet<Cell> headSet(final Cell toElement) {
76      return headSet(toElement, false);
77    }
78  
79    public NavigableSet<Cell> headSet(final Cell toElement,
80        boolean inclusive) {
81      return new CellSkipListSet(this.delegatee.headMap(toElement, inclusive));
82    }
83  
84    public Cell higher(Cell e) {
85      throw new UnsupportedOperationException("Not implemented");
86    }
87  
88    public Iterator<Cell> iterator() {
89      return this.delegatee.values().iterator();
90    }
91  
92    public Cell lower(Cell e) {
93      throw new UnsupportedOperationException("Not implemented");
94    }
95  
96    public Cell pollFirst() {
97      throw new UnsupportedOperationException("Not implemented");
98    }
99  
100   public Cell pollLast() {
101     throw new UnsupportedOperationException("Not implemented");
102   }
103 
104   public SortedSet<Cell> subSet(Cell fromElement, Cell toElement) {
105     throw new UnsupportedOperationException("Not implemented");
106   }
107 
108   public NavigableSet<Cell> subSet(Cell fromElement,
109       boolean fromInclusive, Cell toElement, boolean toInclusive) {
110     throw new UnsupportedOperationException("Not implemented");
111   }
112 
113   public SortedSet<Cell> tailSet(Cell fromElement) {
114     return tailSet(fromElement, true);
115   }
116 
117   public NavigableSet<Cell> tailSet(Cell fromElement, boolean inclusive) {
118     return new CellSkipListSet(this.delegatee.tailMap(fromElement, inclusive));
119   }
120 
121   public Comparator<? super Cell> comparator() {
122     throw new UnsupportedOperationException("Not implemented");
123   }
124 
125   public Cell first() {
126     return this.delegatee.get(this.delegatee.firstKey());
127   }
128 
129   public Cell last() {
130     return this.delegatee.get(this.delegatee.lastKey());
131   }
132 
133   public boolean add(Cell e) {
134     return this.delegatee.put(e, e) == null;
135   }
136 
137   public boolean addAll(Collection<? extends Cell> c) {
138     throw new UnsupportedOperationException("Not implemented");
139   }
140 
141   public void clear() {
142     this.delegatee.clear();
143   }
144 
145   public boolean contains(Object o) {
146     //noinspection SuspiciousMethodCalls
147     return this.delegatee.containsKey(o);
148   }
149 
150   public boolean containsAll(Collection<?> c) {
151     throw new UnsupportedOperationException("Not implemented");
152   }
153 
154   public boolean isEmpty() {
155     return this.delegatee.isEmpty();
156   }
157 
158   public boolean remove(Object o) {
159     return this.delegatee.remove(o) != null;
160   }
161 
162   public boolean removeAll(Collection<?> c) {
163     throw new UnsupportedOperationException("Not implemented");
164   }
165 
166   public boolean retainAll(Collection<?> c) {
167     throw new UnsupportedOperationException("Not implemented");
168   }
169 
170   public Cell get(Cell kv) {
171     return this.delegatee.get(kv);
172   }
173 
174   public int size() {
175     return this.delegatee.size();
176   }
177 
178   public Object[] toArray() {
179     throw new UnsupportedOperationException("Not implemented");
180   }
181 
182   public <T> T[] toArray(T[] a) {
183     throw new UnsupportedOperationException("Not implemented");
184   }
185 }