AttributeSetUtilities.java [plain text]
package javax.print.attribute;
import java.io.Serializable;
public final class AttributeSetUtilities
{
private AttributeSetUtilities() {}
private static class UnmodifiableAttributeSet
implements AttributeSet, Serializable
{
private AttributeSet set;
public UnmodifiableAttributeSet(AttributeSet attributeSet)
{
if (attributeSet == null)
throw new NullPointerException("attributeSet may not be null");
this.set = attributeSet;
}
public boolean add(Attribute attribute)
{
throw new UnmodifiableSetException();
}
public boolean addAll(AttributeSet attributes)
{
throw new UnmodifiableSetException();
}
public void clear()
{
throw new UnmodifiableSetException();
}
public boolean containsKey(Class category)
{
return set.containsKey(category);
}
public boolean containsValue(Attribute attribute)
{
return set.containsValue(attribute);
}
public boolean equals(Object obj)
{
return set.equals(obj);
}
public Attribute get(Class interfaceName)
{
return set.get(interfaceName);
}
public int hashCode()
{
return set.hashCode();
}
public boolean isEmpty()
{
return set.isEmpty();
}
public boolean remove(Class category)
{
throw new UnmodifiableSetException();
}
public boolean remove(Attribute attribute)
{
throw new UnmodifiableSetException();
}
public int size()
{
return set.size();
}
public Attribute[] toArray()
{
return set.toArray();
}
}
private static class UnmodifiableDocAttributeSet
extends UnmodifiableAttributeSet
implements DocAttributeSet, Serializable
{
public UnmodifiableDocAttributeSet(DocAttributeSet attributeSet)
{
super(attributeSet);
}
}
private static class UnmodifiablePrintJobAttributeSet
extends UnmodifiableAttributeSet
implements PrintJobAttributeSet, Serializable
{
public UnmodifiablePrintJobAttributeSet(PrintJobAttributeSet attributeSet)
{
super(attributeSet);
}
}
private static class UnmodifiablePrintRequestAttributeSet
extends UnmodifiableAttributeSet
implements PrintRequestAttributeSet, Serializable
{
public UnmodifiablePrintRequestAttributeSet(PrintRequestAttributeSet attributeSet)
{
super(attributeSet);
}
}
private static class UnmodifiablePrintServiceAttributeSet
extends UnmodifiableAttributeSet
implements PrintServiceAttributeSet, Serializable
{
public UnmodifiablePrintServiceAttributeSet(PrintServiceAttributeSet attributeSet)
{
super(attributeSet);
}
}
private static class SynchronizedAttributeSet
implements AttributeSet, Serializable
{
private AttributeSet set;
public SynchronizedAttributeSet(AttributeSet attributeSet)
{
if (attributeSet == null)
throw new NullPointerException("attributeSet may not be null");
this.set = attributeSet;
}
public synchronized boolean add(Attribute attribute)
{
return set.add(attribute);
}
public synchronized boolean addAll(AttributeSet attributes)
{
return set.addAll(attributes);
}
public synchronized void clear()
{
set.clear();
}
public synchronized boolean containsKey(Class category)
{
return set.containsKey(category);
}
public synchronized boolean containsValue(Attribute attribute)
{
return set.containsValue(attribute);
}
public synchronized boolean equals(Object obj)
{
return set.equals(obj);
}
public synchronized Attribute get(Class interfaceName)
{
return set.get(interfaceName);
}
public synchronized int hashCode()
{
return set.hashCode();
}
public synchronized boolean isEmpty()
{
return set.isEmpty();
}
public synchronized boolean remove(Class category)
{
return set.remove(category);
}
public synchronized boolean remove(Attribute attribute)
{
return set.remove(attribute);
}
public synchronized int size()
{
return set.size();
}
public synchronized Attribute[] toArray()
{
return set.toArray();
}
}
private static class SynchronizedDocAttributeSet
extends SynchronizedAttributeSet
implements DocAttributeSet, Serializable
{
public SynchronizedDocAttributeSet(DocAttributeSet attributeSet)
{
super(attributeSet);
}
}
private static class SynchronizedPrintJobAttributeSet
extends SynchronizedAttributeSet
implements PrintJobAttributeSet, Serializable
{
public SynchronizedPrintJobAttributeSet(PrintJobAttributeSet attributeSet)
{
super(attributeSet);
}
}
private static class SynchronizedPrintRequestAttributeSet
extends SynchronizedAttributeSet
implements PrintRequestAttributeSet, Serializable
{
public SynchronizedPrintRequestAttributeSet(PrintRequestAttributeSet attributeSet)
{
super(attributeSet);
}
}
private static class SynchronizedPrintServiceAttributeSet
extends SynchronizedAttributeSet
implements PrintServiceAttributeSet, Serializable
{
public SynchronizedPrintServiceAttributeSet(PrintServiceAttributeSet attributeSet)
{
super(attributeSet);
}
}
public static AttributeSet synchronizedView(AttributeSet attributeSet)
{
return new SynchronizedAttributeSet(attributeSet);
}
public static DocAttributeSet synchronizedView(DocAttributeSet attributeSet)
{
return new SynchronizedDocAttributeSet(attributeSet);
}
public static PrintJobAttributeSet synchronizedView(PrintJobAttributeSet attributeSet)
{
return new SynchronizedPrintJobAttributeSet(attributeSet);
}
public static PrintRequestAttributeSet synchronizedView(PrintRequestAttributeSet attributeSet)
{
return new SynchronizedPrintRequestAttributeSet(attributeSet);
}
public static PrintServiceAttributeSet synchronizedView(PrintServiceAttributeSet attributeSet)
{
return new SynchronizedPrintServiceAttributeSet(attributeSet);
}
public static AttributeSet unmodifiableView(AttributeSet attributeSet)
{
return new UnmodifiableAttributeSet(attributeSet);
}
public static DocAttributeSet unmodifiableView(DocAttributeSet attributeSet)
{
return new UnmodifiableDocAttributeSet(attributeSet);
}
public static PrintJobAttributeSet unmodifiableView(PrintJobAttributeSet attributeSet)
{
return new UnmodifiablePrintJobAttributeSet(attributeSet);
}
public static PrintRequestAttributeSet unmodifiableView(PrintRequestAttributeSet attributeSet)
{
return new UnmodifiablePrintRequestAttributeSet(attributeSet);
}
public static PrintServiceAttributeSet unmodifiableView(PrintServiceAttributeSet attributeSet)
{
return new UnmodifiablePrintServiceAttributeSet(attributeSet);
}
public static Class verifyAttributeCategory(Object object,
Class interfaceName)
{
if (object == null)
throw new NullPointerException("object may not be null");
Class clazz = (Class) object;
if (interfaceName.isAssignableFrom(clazz))
return clazz;
throw new ClassCastException();
}
public static Attribute verifyAttributeValue(Object object,
Class interfaceName)
{
if (object == null)
throw new NullPointerException("object may not be null");
if (interfaceName.isInstance(object))
return (Attribute) object;
throw new ClassCastException();
}
public static void verifyCategoryForValue(Class category,
Attribute attribute)
{
if (category == null)
throw new NullPointerException("object may not be null");
if (category.equals(attribute.getCategory()))
throw new IllegalArgumentException
("category of attribute not equal to category");
}
}