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