AttributeSetUtilities (Java SE 26 & JDK 26)
Description: declaration: module: java.desktop, package: javax.print.attribute, class: AttributeSetUtilities
Keywords: javax.print.attribute.AttributeSetUtilities class

# Class AttributeSetUtilities

java.lang.Object
javax.print.attribute.AttributeSetUtilities

public final class AttributeSetUtilities extends Object
Class `AttributeSetUtilities` provides static methods for manipulating `AttributeSets`.

- Methods for creating unmodifiable and synchronized views of attribute sets.
- operations useful for building implementations of interface `AttributeSet`

An unmodifiable view U of an `AttributeSet` S provides a client with "read-only" access to S. Query operations on U "read through" to S; thus, changes in S are reflected in U. However, any attempt to modify U, results in an `UnmodifiableSetException`. The unmodifiable view object U will be serializable if the attribute set object S is serializable.

A synchronized view V of an attribute set S provides a client with synchronized (multiple thread safe) access to S. Each operation of V is synchronized using V itself as the lock object and then merely invokes the corresponding operation of S. In order to guarantee mutually exclusive access, it is critical that all access to S is accomplished through V. The synchronized view object V will be serializable if the attribute set object S is serializable.

As mentioned in the package description of `javax.print`, a `null` reference parameter to methods is incorrect unless explicitly documented on the method as having a meaningful interpretation. Usage to the contrary is incorrect coding and may result in a run time exception either immediately or at some later time. `IllegalArgumentException` and `NullPointerException` are examples of typical and acceptable run time exceptions for such cases.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static AttributeSet`
  `synchronizedView(AttributeSet attributeSet)`
  Creates a synchronized view of the given attribute set.
  `static DocAttributeSet`
  `synchronizedView(DocAttributeSet attributeSet)`
  Creates a synchronized view of the given doc attribute set.
  `static PrintJobAttributeSet`
  `synchronizedView(PrintJobAttributeSet attributeSet)`
  Creates a synchronized view of the given print job attribute set.
  `static PrintRequestAttributeSet`
  `synchronizedView(PrintRequestAttributeSet attributeSet)`
  Creates a synchronized view of the given print request attribute set.
  `static PrintServiceAttributeSet`
  `synchronizedView(PrintServiceAttributeSet attributeSet)`
  Creates a synchronized view of the given print service attribute set.
  `static AttributeSet`
  `unmodifiableView(AttributeSet attributeSet)`
  Creates an unmodifiable view of the given attribute set.
  `static DocAttributeSet`
  `unmodifiableView(DocAttributeSet attributeSet)`
  Creates an unmodifiable view of the given doc attribute set.
  `static PrintJobAttributeSet`
  `unmodifiableView(PrintJobAttributeSet attributeSet)`
  Creates an unmodifiable view of the given print job attribute set.
  `static PrintRequestAttributeSet`
  `unmodifiableView(PrintRequestAttributeSet attributeSet)`
  Creates an unmodifiable view of the given print request attribute set.
  `static PrintServiceAttributeSet`
  `unmodifiableView(PrintServiceAttributeSet attributeSet)`
  Creates an unmodifiable view of the given print service attribute set.
  `static Class<?>`
  `verifyAttributeCategory(Object object, Class<?> interfaceName)`
  Verify that the given object is a `Class` that implements the given interface, which is assumed to be interface `Attribute` or a subinterface thereof.
  `static Attribute`
  `verifyAttributeValue(Object object, Class<?> interfaceName)`
  Verify that the given object is an instance of the given interface, which is assumed to be interface `Attribute` or a subinterface thereof.
  `static void`
  `verifyCategoryForValue(Class<?> category, Attribute attribute)`
  Verify that the given attribute category object is equal to the category of the given attribute value object.

  ### Methods declared in class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
  Modifier and Type
  Method
  Description
  `protected Object`
  `clone()`
  Creates and returns a copy of this object.
  `boolean`
  `equals(Object obj)`
  Indicates whether some other object is "equal to" this one.
  `protected void`
  `finalize()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Finalization is deprecated and subject to removal in a future release.
  `final Class<?>`
  `getClass()`
  Returns the runtime class of this `Object`.
  `int`
  `hashCode()`
  Returns a hash code value for this object.
  `final void`
  `notify()`
  Wakes up a single thread that is waiting on this object's monitor.
  `final void`
  `notifyAll()`
  Wakes up all threads that are waiting on this object's monitor.
  `String`
  `toString()`
  Returns a string representation of the object.
  `final void`
  `wait()`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted.
  `final void`
  `wait(long timeoutMillis)`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
  `final void`
  `wait(long timeoutMillis, int nanos)`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

- ## Method Details

  - ### unmodifiableView

    public static AttributeSet unmodifiableView(AttributeSet attributeSet)
    Creates an unmodifiable view of the given attribute set.
    Parameters:
      `attributeSet` - underlying attribute set
    Returns:
      unmodifiable view of `attributeSet`
    Throws:
      `NullPointerException` - if `attributeSet` is `null`

  - ### unmodifiableView

    public static DocAttributeSet unmodifiableView(DocAttributeSet attributeSet)
    Creates an unmodifiable view of the given doc attribute set.
    Parameters:
      `attributeSet` - underlying doc attribute set
    Returns:
      unmodifiable view of `attributeSet`
    Throws:
      `NullPointerException` - if `attributeSet` is `null`

  - ### unmodifiableView

    public static PrintRequestAttributeSet unmodifiableView(PrintRequestAttributeSet attributeSet)
    Creates an unmodifiable view of the given print request attribute set.
    Parameters:
      `attributeSet` - underlying print request attribute set
    Returns:
      unmodifiable view of `attributeSet`
    Throws:
      `NullPointerException` - if `attributeSet` is `null`

  - ### unmodifiableView

    public static PrintJobAttributeSet unmodifiableView(PrintJobAttributeSet attributeSet)
    Creates an unmodifiable view of the given print job attribute set.
    Parameters:
      `attributeSet` - underlying print job attribute set
    Returns:
      unmodifiable view of `attributeSet`
    Throws:
      `NullPointerException` - if `attributeSet` is `null`

  - ### unmodifiableView

    public static PrintServiceAttributeSet unmodifiableView(PrintServiceAttributeSet attributeSet)
    Creates an unmodifiable view of the given print service attribute set.
    Parameters:
      `attributeSet` - underlying print service attribute set
    Returns:
      unmodifiable view of `attributeSet`
    Throws:
      `NullPointerException` - if `attributeSet` is `null`

  - ### synchronizedView

    public static AttributeSet synchronizedView(AttributeSet attributeSet)
    Creates a synchronized view of the given attribute set.
    Parameters:
      `attributeSet` - underlying attribute set
    Returns:
      synchronized view of `attributeSet`
    Throws:
      `NullPointerException` - if `attributeSet` is `null`

  - ### synchronizedView

    public static DocAttributeSet synchronizedView(DocAttributeSet attributeSet)
    Creates a synchronized view of the given doc attribute set.
    Parameters:
      `attributeSet` - underlying doc attribute set
    Returns:
      synchronized view of `attributeSet`
    Throws:
      `NullPointerException` - if `attributeSet` is `null`

  - ### synchronizedView

    public static PrintRequestAttributeSet synchronizedView(PrintRequestAttributeSet attributeSet)
    Creates a synchronized view of the given print request attribute set.
    Parameters:
      `attributeSet` - underlying print request attribute set
    Returns:
      synchronized view of `attributeSet`
    Throws:
      `NullPointerException` - if `attributeSet` is `null`

  - ### synchronizedView

    public static PrintJobAttributeSet synchronizedView(PrintJobAttributeSet attributeSet)
    Creates a synchronized view of the given print job attribute set.
    Parameters:
      `attributeSet` - underlying print job attribute set
    Returns:
      synchronized view of `attributeSet`
    Throws:
      `NullPointerException` - if `attributeSet` is `null`

  - ### synchronizedView

    public static PrintServiceAttributeSet synchronizedView(PrintServiceAttributeSet attributeSet)
    Creates a synchronized view of the given print service attribute set.
    Parameters:
      `attributeSet` - underlying print service attribute set
    Returns:
      synchronized view of `attributeSet`
    Throws:
      `NullPointerException` - if `attributeSet` is `null`

  - ### verifyAttributeCategory

    public static Class<?> verifyAttributeCategory(Object object, Class<?> interfaceName)
    Verify that the given object is a `Class` that implements the given interface, which is assumed to be interface `Attribute` or a subinterface thereof.
    Parameters:
      `object` - `Object` to test
      `interfaceName` - interface the object must implement
    Returns:
      if `object` is a `Class` that implements `interfaceName`, `object` is returned downcast to type `Class`; otherwise an exception is thrown
    Throws:
      `NullPointerException` - if `object` is `null`
      `ClassCastException` - if `object` is not a `Class` that implements `interfaceName`

  - ### verifyAttributeValue

    public static Attribute verifyAttributeValue(Object object, Class<?> interfaceName)
    Verify that the given object is an instance of the given interface, which is assumed to be interface `Attribute` or a subinterface thereof.
    Parameters:
      `object` - `Object` to test
      `interfaceName` - interface of which the object must be an instance
    Returns:
      if `object` is an instance of `interfaceName`, `object` is returned downcast to type `Attribute`; otherwise an exception is thrown
    Throws:
      `NullPointerException` - if `object` is `null`
      `ClassCastException` - if `object` is not an instance of `interfaceName`

  - ### verifyCategoryForValue

    public static void verifyCategoryForValue(Class<?> category, Attribute attribute)
    Verify that the given attribute category object is equal to the category of the given attribute value object. If so, this method returns doing nothing. If not, this method throws an exception.
    Parameters:
      `category` - attribute category to test
      `attribute` - attribute value to test
    Throws:
      `NullPointerException` - if the `category` or `attribute` are `null`
      `IllegalArgumentException` - if the `category` is not equal to the category of the `attribute`