Java Program to Implement JobStateReasons API

This Java program Implements JobStateReasons API.Class JobStateReasons is a printing attribute class, a set of enumeration values, that provides additional information about the job’s current state, i.e., information that augments the value of the job’s JobState attribute.

Here is the source code of the Java Program to Implement JobStateReasons API.The Java program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. import java.util.Collection;
  2. import javax.print.attribute.Attribute;
  3. import javax.print.attribute.standard.JobStateReason;
  4. import javax.print.attribute.standard.JobStateReasons;
  5.  
  6. public class JobStateReasonsImpl
  7. {
  8.     private JobStateReasons jobStateReasons;
  9.  
  10.     /**
  11.      * Construct a new, empty job state reasons attribute; the underlying hash
  12.      * set has the default initial capacity and load factor.
  13.     **/
  14.     public JobStateReasonsImpl()
  15.     {
  16.         jobStateReasons = new JobStateReasons();
  17.     }
  18.  
  19.     /**
  20.      * Construct a new job state reasons attribute that contains the same
  21.      * JobStateReason objects as the given collection.
  22.     **/
  23.     public JobStateReasonsImpl(Collection<JobStateReason> collection)
  24.     {
  25.         jobStateReasons = new JobStateReasons(collection);
  26.     }
  27.  
  28.     /**
  29.      * Construct a new, empty job state reasons attribute; the underlying hash
  30.      * set has the given initial capacity and the default load factor.
  31.     **/
  32.     public JobStateReasonsImpl(int initialCapacity)
  33.     {
  34.         jobStateReasons = new JobStateReasons(initialCapacity);
  35.     }
  36.  
  37.     /**
  38.      * Construct a new, empty job state reasons attribute; the underlying hash
  39.      * set has the given initial capacity and load factor.
  40.      **/
  41.     public JobStateReasonsImpl(int initialCapacity, float loadFactor)
  42.     {
  43.         jobStateReasons = new JobStateReasons(initialCapacity, loadFactor);
  44.     }
  45.  
  46.     /**
  47.      * Adds the specified element to this job state reasons attribute if it is
  48.      * not already present.
  49.     **/
  50.     public boolean add(JobStateReason o)
  51.     {
  52.         return jobStateReasons.add(o);
  53.     }
  54.  
  55.     /**
  56.      * Get the printing attribute class which is to be used as the "category"
  57.      * for this printing attribute value.
  58.     **/
  59.     public Class<? extends Attribute> getCategory()
  60.     {
  61.         return jobStateReasons.getCategory();
  62.     }
  63.  
  64.     /**
  65.      * Get the name of the category of which this attribute value is an
  66.      * instance.
  67.      **/
  68.     public String getName()
  69.     {
  70.         return jobStateReasons.getName();
  71.     }
  72.  
  73.     /** return true if this set contains the specified element **/
  74.     public boolean contains(Object obj)
  75.     {
  76.         return jobStateReasons.contains(obj);
  77.     }
  78.  
  79.     /** returns true if the set is empty **/
  80.     public boolean isEmpty()
  81.     {
  82.         return jobStateReasons.isEmpty();
  83.     }
  84.  
  85.     /** removes the specified element from this set if present **/
  86.     public boolean remove(Object obj)
  87.     {
  88.         return jobStateReasons.remove(obj);
  89.     }
  90.  
  91.     /** returns the number of elements in set **/
  92.     public int size()
  93.     {
  94.         return jobStateReasons.size();
  95.     }
  96.  
  97.     /** removes all elements from this set **/
  98.     public void clear()
  99.     {
  100.         jobStateReasons.clear();
  101.     }
  102.  
  103.     /** Returns an array containing all of the elements in this set. **/
  104.     public Object[] toArray() 
  105.     {
  106.         return jobStateReasons.toArray();
  107.     }
  108.  
  109.     public static void main(String... arg)
  110.     {
  111.         JobStateReasonsImpl jobStateReasons = new JobStateReasonsImpl();
  112.         jobStateReasons.add(JobStateReason.COMPRESSION_ERROR);
  113.         jobStateReasons.add(JobStateReason.JOB_CANCELED_BY_USER);
  114.         jobStateReasons.add(JobStateReason.JOB_COMPLETED_WITH_WARNINGS);
  115.         jobStateReasons.add(JobStateReason.DOCUMENT_FORMAT_ERROR);
  116.  
  117.         System.out.println("the name of category " + jobStateReasons.getName());
  118.         System.out.println("the jobStateReason are");
  119.         Object[] array = (Object[]) jobStateReasons.toArray();
  120.         for (int i = 0; i < array.length; i++)
  121.         {
  122.             System.out.print(array[i] + "\t");
  123.         }
  124.         System.out.println();
  125.  
  126.         jobStateReasons.clear();
  127.         System.out.println("jobStateReasons cleared");
  128.         if (jobStateReasons.isEmpty())
  129.             System.out.println("jobStateReasons is empty");
  130.         else
  131.             System.out.println("jobStateReasons is not empty");
  132.     }
  133. }

$ javac JobStateReasonsImpl.java
$ java JobStateReasonsImpl
the name of category job-state-reasons
the jobStateReason are
compression-error	document-format-error	job-completed-with-warnings	job-canceled-by-user	
jobStateReasons cleared
jobStateReasons is not empty

Sanfoundry Global Education & Learning Series – 1000 Java Programs.

advertisement
advertisement
If you wish to look at all Java Programming examples, go to Java Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.