1. /*
  2. * @(#)NumberUpSupported.java 1.4 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.print.attribute.standard;
  8. import javax.print.attribute.SetOfIntegerSyntax;
  9. import javax.print.attribute.SupportedValuesAttribute;
  10. /**
  11. * Class NumberUpSupported is a printing attribute class, a set of integers,
  12. * that gives the supported values for a {@link NumberUp NumberUp} attribute.
  13. * <P>
  14. * <B>IPP Compatibility:</B> The NumberUpSupported attribute's canonical array
  15. * form gives the lower and upper bound for each range of number-up to be
  16. * included in an IPP "number-up-supported" attribute. See class {@link
  17. * javax.print.attribute.SetOfIntegerSyntax SetOfIntegerSyntax} for an
  18. * explanation of canonical array form. The category name returned by
  19. * <CODE>getName()</CODE> gives the IPP attribute name.
  20. * <P>
  21. *
  22. * @author Alan Kaminsky
  23. */
  24. public final class NumberUpSupported extends SetOfIntegerSyntax
  25. implements SupportedValuesAttribute {
  26. /**
  27. * Construct a new number up supported attribute with the given members.
  28. * The supported values for NumberUp are specified in "array form;" see
  29. * class
  30. * {@link javax.print.attribute.SetOfIntegerSyntax SetOfIntegerSyntax}
  31. * for an explanation of array form.
  32. *
  33. * @param members Set members in array form.
  34. *
  35. * @exception NullPointerException
  36. * (unchecked exception) Thrown if <CODE>members</CODE> is null or
  37. * any element of <CODE>members</CODE> is null.
  38. * @exception IllegalArgumentException
  39. * (unchecked exception) Thrown if any element of
  40. * <CODE>members</CODE> is not a length-one or length-two array. Also
  41. * thrown if <CODE>members</CODE> is a zero-length array or if any
  42. * member of the set is less than 1.
  43. */
  44. public NumberUpSupported(int[][] members) {
  45. super (members);
  46. if (members == null) {
  47. throw new NullPointerException("members is null");
  48. }
  49. int[][] myMembers = getMembers();
  50. int n = myMembers.length;
  51. if (n == 0) {
  52. throw new IllegalArgumentException("members is zero-length");
  53. }
  54. int i;
  55. for (i = 0; i < n; ++ i) {
  56. if (myMembers[i][0] < 1) {
  57. throw new IllegalArgumentException
  58. ("Number up value must be > 0");
  59. }
  60. }
  61. }
  62. /**
  63. * Construct a new number up supported attribute containing a single
  64. * integer. That is, only the one value of NumberUp is supported.
  65. *
  66. * @param member Set member.
  67. *
  68. * @exception IllegalArgumentException
  69. * (Unchecked exception) Thrown if <CODE>member</CODE> is less than
  70. * 1.
  71. */
  72. public NumberUpSupported(int member) {
  73. super (member);
  74. if (member < 1) {
  75. throw new IllegalArgumentException("Number up value must be > 0");
  76. }
  77. }
  78. /**
  79. * Construct a new number up supported attribute containing a single range
  80. * of integers. That is, only those values of NumberUp in the one range are
  81. * supported.
  82. *
  83. * @param lowerBound Lower bound of the range.
  84. * @param upperBound Upper bound of the range.
  85. *
  86. * @exception IllegalArgumentException
  87. * (Unchecked exception) Thrown if a null range is specified or if a
  88. * non-null range is specified with <CODE>lowerBound</CODE> less than
  89. * 1.
  90. */
  91. public NumberUpSupported(int lowerBound, int upperBound) {
  92. super (lowerBound, upperBound);
  93. if (lowerBound > upperBound) {
  94. throw new IllegalArgumentException("Null range specified");
  95. } else if (lowerBound < 1) {
  96. throw new IllegalArgumentException
  97. ("Number up value must be > 0");
  98. }
  99. }
  100. /**
  101. * Returns whether this number up supported attribute is equivalent to the
  102. * passed in object. To be equivalent, all of the following conditions
  103. * must be true:
  104. * <OL TYPE=1>
  105. * <LI>
  106. * <CODE>object</CODE> is not null.
  107. * <LI>
  108. * <CODE>object</CODE> is an instance of class NumberUpSupported.
  109. * <LI>
  110. * This number up supported attribute's members and <CODE>object</CODE>'s
  111. * members are the same.
  112. * </OL>
  113. *
  114. * @param object Object to compare to.
  115. *
  116. * @return True if <CODE>object</CODE> is equivalent to this number up
  117. * supported attribute, false otherwise.
  118. */
  119. public boolean equals(Object object) {
  120. return (super.equals (object) &&
  121. object instanceof NumberUpSupported);
  122. }
  123. /**
  124. * Get the printing attribute class which is to be used as the "category"
  125. * for this printing attribute value.
  126. * <P>
  127. * For class NumberUpSupported, the
  128. * category is class NumberUpSupported itself.
  129. *
  130. * @return Printing attribute class (category), an instance of class
  131. * {@link java.lang.Class java.lang.Class}.
  132. */
  133. public final Class getCategory() {
  134. return NumberUpSupported.class;
  135. }
  136. /**
  137. * Get the name of the category of which this attribute value is an
  138. * instance.
  139. * <P>
  140. * For class NumberUpSupported, the
  141. * category name is <CODE>"number-up-supported"</CODE>.
  142. *
  143. * @return Attribute category name.
  144. */
  145. public final String getName() {
  146. return "number-up-supported";
  147. }
  148. }