import
java.util.Collection;
import
java.util.HashMap;
import
java.util.Iterator;
import
java.util.Map;
import
java.util.Map.Entry;
import
java.util.Set;
import
javax.script.SimpleBindings;
public
class
SimpleBindingsAPIExample {
private
SimpleBindings simpleBindings;
public
SimpleBindingsAPIExample()
{
simpleBindings =
new
SimpleBindings();
}
public
SimpleBindingsAPIExample(Map<String, Object> map)
{
simpleBindings =
new
SimpleBindings(map);
}
public
void
clear() { simpleBindings.clear(); }
public
boolean
containsKey(Object key)
{
return
simpleBindings.containsKey(key);
}
public
boolean
containsValue(Object value)
{
return
simpleBindings.containsValue(value);
}
public
Set<Map.Entry<String, Object> > entrySet()
{
return
simpleBindings.entrySet();
}
public
Object get(Object key)
{
return
simpleBindings.get(key);
}
public
boolean
isEmpty()
{
return
simpleBindings.isEmpty();
}
public
Set<String> keySet()
{
return
simpleBindings.keySet();
}
public
Object put(String key, Object value)
{
return
simpleBindings.put(key, value);
}
public
void
putAll(Map<?
extends
String, ?
extends
Object> map)
{
simpleBindings.putAll(map);
}
public
Object remove(Object key)
{
return
simpleBindings.remove(key);
}
public
int
size() {
return
simpleBindings.size(); }
public
Collection<Object> values()
{
return
simpleBindings.values();
}
}
class
SimpleBindingsImpl {
public
static
void
main(String[] args)
{
SimpleBindingsAPIExample map =
new
SimpleBindingsAPIExample();
map.put(
"1"
,
"Ram"
);
map.put(
"2"
,
"Shyam"
);
map.put(
"3"
,
"Sita"
);
Map<String, Object> anotherMap =
new
HashMap<String, Object>();
anotherMap.put(
"4"
,
"Geeta"
);
anotherMap.put(
"5"
,
"Tina"
);
map.putAll(anotherMap);
System.out.println(
"The key set of the map is : "
);
Set<String> keySet = map.keySet();
Iterator<String> itr = keySet.iterator();
while
(itr.hasNext()) {
System.out.print(itr.next() +
"\n"
);
}
System.out.println();
System.out.println(
"The values of map is : "
);
Collection<Object> collectionOfValues = map.values();
Iterator<Object> itrOfValues = collectionOfValues.iterator();
while
(itrOfValues.hasNext())
{
System.out.print(itrOfValues.next() +
"\n"
);
}
System.out.println();
System.out.println(
"The entry set of the map is "
);
Iterator<Entry<String, Object> > itrOfEntrySet;
Set<Entry<String, Object> > entrySet = map.entrySet();
itrOfEntrySet = entrySet.iterator();
while
(itrOfEntrySet.hasNext())
{
System.out.println(itrOfEntrySet.next());
}
System.out.println();
boolean
check = map.containsKey(
"2"
);
System.out.println(
"The map contains key 2 ? "
+ check);
System.out.println();
check = map.containsValue(
"Tina"
);
System.out.println(
"The map contains value Tina? "
+ check);
System.out.println();
int
result = map.size();
System.out.println(
"The number of key-value pairs in the map are : "
+ result);
System.out.println();
map.clear();
check = map.isEmpty();
System.out.println(
"After clear the map, the map is empty ? "
+ check);
System.out.println();
}
}