import
java.util.*;
class
TreeMapImplementation<K, V> {
private
TreeMap<K, V> map;
public
TreeMapImplementation()
{
map =
new
TreeMap<K, V>();
}
public
TreeMapImplementation(
Comparator<?
super
K> comparator)
{
map =
new
TreeMap<K, V>(comparator);
}
public
TreeMapImplementation(
Map<?
extends
K, ?
extends
V> map1)
{
map =
new
TreeMap<K, V>(map1);
}
public
TreeMapImplementation(
SortedMap<K, ?
extends
V> m)
{
map =
new
TreeMap<K, V>(m);
}
public
Map.Entry<K, V> ceilingEntry(K key)
{
return
map.ceilingEntry(key);
}
public
K ceilingKey(K key)
{
return
map.ceilingKey(key);
}
public
void
clear() { map.clear(); }
public
Object clone() {
return
map.clone(); }
public
Comparator<?
super
K> comparator()
{
return
map.comparator();
}
public
boolean
containsKey(Object key)
{
return
map.containsKey(key);
}
public
boolean
containsValue(Object val)
{
return
map.containsValue(val);
}
public
NavigableSet<K> descendingKeySet()
{
return
map.descendingKeySet();
}
public
NavigableMap<K, V> descendingMap()
{
return
map.descendingMap();
}
public
Set<Map.Entry<K, V> > entrySet()
{
return
map.entrySet();
}
public
Map.Entry<K, V> firstEntry()
{
return
map.firstEntry();
}
public
K firstKey() {
return
map.firstKey(); }
public
K floorKey(K key) {
return
map.floorKey(key); }
public
V get(Object key) {
return
map.get(key); }
public
SortedMap<K, V> headMap(K key)
{
return
map.headMap(key);
}
public
NavigableMap<K, V> headMap(K key,
boolean
include)
{
return
map.headMap(key, include);
}
public
Map.Entry<K, V> higherEntry(K key)
{
return
map.higherEntry(key);
}
public
K higherKey(K key) {
return
map.higherKey(key); }
public
Set<K> keySet() {
return
map.keySet(); }
public
Map.Entry<K, V> lastEntry()
{
return
map.lastEntry();
}
public
K lastKey() {
return
map.lastKey(); }
public
Map.Entry<K, V> lowerEntry(K key)
{
return
map.lowerEntry(key);
}
public
K lowerKey(K key) {
return
map.lowerKey(key); }
public
NavigableSet<K> navigableKeySet()
{
return
map.navigableKeySet();
}
public
Map.Entry<K, V> pollFirstEntry()
{
return
map.pollFirstEntry();
}
public
Map.Entry<K, V> pollLastEntry()
{
return
map.pollLastEntry();
}
public
V put(K key, V val) {
return
map.put(key, val); }
public
void
putAll(Map<?
extends
K, ?
extends
V> map1)
{
map.putAll(map1);
}
public
V remove(Object key) {
return
map.remove(key); }
public
int
size() {
return
map.size(); }
public
NavigableMap<K, V> subMap(K lKey,
boolean
lInclude,
K rKey,
boolean
rInclude)
{
return
map.subMap(lKey, lInclude, rKey, rInclude);
}
public
SortedMap<K, V> subMap(K lKey, K rKey)
{
return
map.subMap(lKey, rKey);
}
public
Collection<V> values() {
return
map.values(); }
}
public
class
GFG {
public
static
void
main(String[] arg)
{
TreeMapImplementation<String, Integer> student
=
new
TreeMapImplementation<>();
student.put(
"Akshay"
,
500
);
student.put(
"Ashok"
,
460
);
student.put(
"Aakash"
,
495
);
System.out.println(
"The key value pairs of TreeMap:"
);
for
(Map.Entry<String, Integer> entry :
student.entrySet()) {
System.out.println(entry.getKey() +
" : "
+ entry.getValue());
}
System.out.println(
"Size of the TreeMap after insertion: "
+ student.size());
System.out.println(
"Poll first entry of the map: "
);
Map.Entry<String, Integer> firstEntry
= student.pollFirstEntry();
System.out.println();
System.out.println(firstEntry.getKey() +
" : "
+ firstEntry.getValue());
System.out.println(
"TreeMap contains Akshay: "
+ student.containsKey(
"Akshay"
));
System.out.println(
"Deleting all the entries"
);
student.clear();
System.out.println(
"Size of the treemap: "
+ student.size());
}
}