import
java.util.Collection;
import
java.util.Iterator;
import
java.util.Map;
import
java.util.Map.Entry;
import
java.util.Set;
import
java.util.jar.Attributes;
public
class
GFG {
private
Attributes attributes;
public
GFG() { attributes =
new
Attributes(); }
public
GFG(Attributes attr)
{
attributes =
new
Attributes(attr);
}
public
GFG(
int
size)
{
attributes =
new
Attributes(size);
}
public
void
clear()
{
attributes.clear();
}
public
Object clone()
{
return
attributes.clone();
}
public
boolean
containsKey(Object key)
{
return
attributes.containsKey(key);
}
public
boolean
containsValue(Object value)
{
return
attributes.containsValue(value);
}
public
Set<Map.Entry<Object, Object> > entrySet()
{
return
attributes.entrySet();
}
public
Object get(Object key)
{
return
attributes.get(key);
}
public
String getValue(Attributes.Name name)
{
return
attributes.getValue(name);
}
public
String getValue(String name)
{
return
attributes.getValue(name);
}
public
boolean
isEmpty()
{
return
attributes.isEmpty();
}
public
Set<Object> keySet()
{
return
attributes.keySet();
}
public
Object put(Object key, Object value)
{
return
attributes.put(key, value);
}
public
void
putAll(Map<?, ?> m)
{
attributes.putAll(m);
}
public
String putValue(String name, String value)
{
return
attributes.putValue(name, value);
}
public
Object remove(Object key)
{
return
attributes.remove(key);
}
public
int
size() {
return
attributes.size(); }
public
Collection<Object> values()
{
return
attributes.values();
}
public
static
void
main(String[] args)
{
Attributes.Name CLASS_PATH
=
new
Attributes.Name(
"CLASS_PATH"
);
Attributes.Name CONTENT_TYPE
=
new
Attributes.Name(
"CONTENT_TYPE"
);
Attributes.Name MANIFEST_VERSION
=
new
Attributes.Name(
"MANIFEST_VERSION"
);
GFG attribute =
new
GFG();
attribute.put(CLASS_PATH,
"root/sub_dir/class_path"
);
attribute.put(CONTENT_TYPE,
"UTF-8"
);
attribute.put(MANIFEST_VERSION,
"2"
);
attribute.putValue(
"MAIN_CLASS"
,
"TESTMAIN.java"
);
System.out.println(
"the key set of the Attributes is "
);
Set<Object> keySet = attribute.keySet();
Iterator<Object> itr = keySet.iterator();
while
(itr.hasNext()) {
System.out.print(itr.next() +
"\t"
);
}
System.out.println();
System.out.println(
"the values of the Attributes is "
);
Collection<Object> collectionValues
= attribute.values();
itr = collectionValues.iterator();
while
(itr.hasNext()) {
System.out.print(itr.next() +
"\t"
);
}
System.out.println();
System.out.println(
"the entry set of the Attributes is "
);
Iterator<Entry<Object, Object> > eitr;
Set<Entry<Object, Object> > entrySet
= attribute.entrySet();
eitr = entrySet.iterator();
while
(eitr.hasNext()) {
System.out.println(eitr.next() +
"\t"
);
}
System.out.println(
"the Attributes contains Key CLASS_PATH:"
+ attribute.containsKey(CLASS_PATH));
System.out.println(
"the Attributes contains Value TESTMAIN.java :"
+ attribute.containsValue(
"TESTMAIN.java"
));
System.out.println(
"the size of the Attributes is "
+ attribute.size());
attribute.clear();
if
(attribute.isEmpty())
System.out.println(
"the Attributes is empty"
);
else
System.out.println(
"the Attributes is not empty"
);
}
}