import
java.util.Collection;
import
java.util.Comparator;
import
java.util.HashMap;
import
java.util.Iterator;
import
java.util.Map;
import
java.util.Map.Entry;
import
java.util.NavigableSet;
import
java.util.Set;
import
java.util.SortedMap;
import
java.util.concurrent.ConcurrentNavigableMap;
import
java.util.concurrent.ConcurrentSkipListMap;
public
class
ConcurrentSkipList<K, V> {
private
ConcurrentSkipListMap<K, V> cmp;
public
ConcurrentSkipList()
{
cmp =
new
ConcurrentSkipListMap<K, V>();
}
public
ConcurrentSkipList(Comparator<?
super
K> comp)
{
cmp =
new
ConcurrentSkipListMap<K, V>(comp);
}
public
ConcurrentSkipList(
Map<?
extends
K, ?
extends
V> mp)
{
cmp =
new
ConcurrentSkipListMap<K, V>(mp);
}
public
ConcurrentSkipList(SortedMap<K, ?
extends
V> mp)
{
cmp =
new
ConcurrentSkipListMap<K, V>(mp);
}
public
Map.Entry<K, V> ceilingEntry(K k)
{
return
cmp.ceilingEntry(k);
}
public
K ceilingKey(K k) {
return
cmp.ceilingKey(k); }
public
void
clear() { cmp.clear(); }
public
ConcurrentSkipListMap<K, V> clone()
{
return
cmp.clone();
}
public
Comparator<?
super
K> comparator()
{
return
cmp.comparator();
}
public
boolean
containsKey(Object k)
{
return
cmp.containsKey(k);
}
public
boolean
containsValue(Object v)
{
return
cmp.containsValue(v);
}
public
NavigableSet<K> descendingKeySet()
{
return
cmp.descendingKeySet();
}
public
ConcurrentNavigableMap<K, V> descendingMap()
{
return
cmp.descendingMap();
}
public
Set<Map.Entry<K, V> > entrySet()
{
return
cmp.entrySet();
}
public
Map.Entry<K, V> firstEntry()
{
return
cmp.firstEntry();
}
public
K firstKey() {
return
cmp.firstKey(); }
public
K floorKey(K k) {
return
cmp.floorKey(k); }
public
V get(Object k) {
return
cmp.get(k); }
public
ConcurrentNavigableMap<K, V> headMap(K k)
{
return
cmp.headMap(k);
}
public
ConcurrentNavigableMap<K, V> headMap(K k,
boolean
in)
{
return
cmp.headMap(k, in);
}
public
Map.Entry<K, V> higherEntry(K k)
{
return
cmp.higherEntry(k);
}
public
K higherKey(K k) {
return
cmp.higherKey(k); }
public
Set<K> keySet() {
return
cmp.keySet(); }
public
Map.Entry<K, V> lastEntry()
{
return
cmp.lastEntry();
}
public
K lastKey() {
return
cmp.lastKey(); }
public
Map.Entry<K, V> lowerEntry(K k)
{
return
cmp.lowerEntry(k);
}
public
K lowerKey(K k) {
return
cmp.lowerKey(k); }
public
NavigableSet<K> navigableKeySet()
{
return
cmp.navigableKeySet();
}
public
Map.Entry<K, V> pollFirstEntry()
{
return
cmp.pollFirstEntry();
}
public
Map.Entry<K, V> pollLastEntry()
{
return
cmp.pollLastEntry();
}
public
V put(K k, V v) {
return
cmp.put(k, v); }
public
void
putAll(Map<?
extends
K, ?
extends
V> mp)
{
cmp.putAll(mp);
}
public
V remove(Object k) {
return
cmp.remove(k); }
public
V replace(K k, V v) {
return
cmp.replace(k, v); }
public
boolean
replace(K k, V oValue, V nValue)
{
return
cmp.replace(k, oValue, nValue);
}
public
int
size() {
return
cmp.size(); }
public
ConcurrentNavigableMap<K, V>
subMap(K k1,
boolean
f, K k2,
boolean
t)
{
return
cmp.subMap(k1, f, k2, t);
}
public
ConcurrentNavigableMap<K, V> subMap(K k1, K k2)
{
return
cmp.subMap(k1, k2);
}
public
Collection<V> values() {
return
cmp.values(); }
public
static
void
main(String[] arg)
{
ConcurrentSkipList<Integer, String> cmp
=
new
ConcurrentSkipList<Integer, String>();
cmp.put(
1
,
"Sahil"
);
cmp.put(
2
,
"Kahish"
);
cmp.put(
3
,
"Tarun"
);
cmp.put(
4
,
"Karan"
);
Map<Integer, String> mp
=
new
HashMap<Integer, String>();
mp.put(
5
,
"Shweta"
);
mp.put(
6
,
"Aditya"
);
cmp.putAll(mp);
System.out.println(
"The key set of the map is "
);
Set<Integer> kSet = cmp.keySet();
Iterator<Integer> i = kSet.iterator();
while
(i.hasNext()) {
System.out.print(i.next() +
" "
);
}
System.out.println();
System.out.println(
"The values of the Map is "
);
Collection<String> values = cmp.values();
Iterator<String> it = values.iterator();
it = values.iterator();
while
(it.hasNext()) {
System.out.print(it.next() +
" "
);
}
System.out.println();
System.out.println(
"Poll first entry of the ConcurrentSkipListMap "
);
Map.Entry<Integer, String> pfe
= cmp.pollFirstEntry();
System.out.println(
"Key = "
+ pfe.getKey()
+
" Value = "
+ pfe.getValue());
System.out.println(
"Poll last entry of the ConcurrentSkipListMap "
);
Map.Entry<Integer, String> ple
= cmp.pollLastEntry();
System.out.println(
"key = "
+ ple.getKey()
+
" value = "
+ ple.getValue());
System.out.println(
"The entry set of the map is "
);
Iterator<Entry<Integer, String> > itr;
Set<Entry<Integer, String> > eSet = cmp.entrySet();
itr = eSet.iterator();
while
(itr.hasNext()) {
System.out.println(itr.next() +
" "
);
}
System.out.println(
"The concurrentSkipListMap contains Key 4 :"
+ cmp.containsKey(
4
));
System.out.println(
"The concurrentSkipListMap contains Value 9 :"
+ cmp.containsValue(
9
));
System.out.println(
"The size of the concurrentSkipListMap is "
+ cmp.size());
cmp.clear();
}
}