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