< prev index next >

src/java.desktop/share/classes/javax/print/attribute/TextSyntax.java

Print this page




  44     private static final long serialVersionUID = -8130648736378144102L;
  45 
  46     /**
  47      * String value of this text attribute.
  48      * @serial
  49      */
  50     private String value;
  51 
  52     /**
  53      * Locale of this text attribute.
  54      * @serial
  55      */
  56     private Locale locale;
  57 
  58     /**
  59      * Constructs a TextAttribute with the specified string and locale.
  60      *
  61      * @param  value   Text string.
  62      * @param  locale  Natural language of the text string. null
  63      * is interpreted to mean the default locale for as returned
  64      * by <code>Locale.getDefault()</code>
  65      *
  66      * @exception  NullPointerException
  67      *     (unchecked exception) Thrown if <CODE>value</CODE> is null.
  68      */
  69     protected TextSyntax(String value, Locale locale) {
  70         this.value = verify (value);
  71         this.locale = verify (locale);
  72     }
  73 
  74     private static String verify(String value) {
  75         if (value == null) {
  76             throw new NullPointerException(" value is null");
  77         }
  78         return value;
  79     }
  80 
  81     private static Locale verify(Locale locale) {
  82         if (locale == null) {
  83             return Locale.getDefault();
  84         }
  85         return locale;
  86     }
  87 


  98      * @return the locale
  99      */
 100     public Locale getLocale() {
 101         return locale;
 102     }
 103 
 104     /**
 105      * Returns a hashcode for this text attribute.
 106      *
 107      * @return  A hashcode value for this object.
 108      */
 109     public int hashCode() {
 110         return value.hashCode() ^ locale.hashCode();
 111     }
 112 
 113     /**
 114      * Returns whether this text attribute is equivalent to the passed in
 115      * object. To be equivalent, all of the following conditions must be true:
 116      * <OL TYPE=1>
 117      * <LI>
 118      * <CODE>object</CODE> is not null.
 119      * <LI>
 120      * <CODE>object</CODE> is an instance of class TextSyntax.
 121      * <LI>
 122      * This text attribute's underlying string and <CODE>object</CODE>'s
 123      * underlying string are equal.
 124      * <LI>
 125      * This text attribute's locale and <CODE>object</CODE>'s locale are
 126      * equal.
 127      * </OL>
 128      *
 129      * @param  object  Object to compare to.
 130      *
 131      * @return  True if <CODE>object</CODE> is equivalent to this text
 132      *          attribute, false otherwise.
 133      */
 134     public boolean equals(Object object) {
 135         return(object != null &&
 136                object instanceof TextSyntax &&
 137                this.value.equals (((TextSyntax) object).value) &&
 138                this.locale.equals (((TextSyntax) object).locale));
 139     }
 140 
 141     /**
 142      * Returns a String identifying this text attribute. The String is
 143      * the attribute's underlying text string.
 144      *
 145      * @return  A String identifying this object.
 146      */
 147     public String toString(){
 148         return value;
 149     }
 150 
 151 }


  44     private static final long serialVersionUID = -8130648736378144102L;
  45 
  46     /**
  47      * String value of this text attribute.
  48      * @serial
  49      */
  50     private String value;
  51 
  52     /**
  53      * Locale of this text attribute.
  54      * @serial
  55      */
  56     private Locale locale;
  57 
  58     /**
  59      * Constructs a TextAttribute with the specified string and locale.
  60      *
  61      * @param  value   Text string.
  62      * @param  locale  Natural language of the text string. null
  63      * is interpreted to mean the default locale for as returned
  64      * by {@code Locale.getDefault()}
  65      *
  66      * @exception  NullPointerException
  67      *     (unchecked exception) Thrown if {@code value} is null.
  68      */
  69     protected TextSyntax(String value, Locale locale) {
  70         this.value = verify (value);
  71         this.locale = verify (locale);
  72     }
  73 
  74     private static String verify(String value) {
  75         if (value == null) {
  76             throw new NullPointerException(" value is null");
  77         }
  78         return value;
  79     }
  80 
  81     private static Locale verify(Locale locale) {
  82         if (locale == null) {
  83             return Locale.getDefault();
  84         }
  85         return locale;
  86     }
  87 


  98      * @return the locale
  99      */
 100     public Locale getLocale() {
 101         return locale;
 102     }
 103 
 104     /**
 105      * Returns a hashcode for this text attribute.
 106      *
 107      * @return  A hashcode value for this object.
 108      */
 109     public int hashCode() {
 110         return value.hashCode() ^ locale.hashCode();
 111     }
 112 
 113     /**
 114      * Returns whether this text attribute is equivalent to the passed in
 115      * object. To be equivalent, all of the following conditions must be true:
 116      * <OL TYPE=1>
 117      * <LI>
 118      * {@code object} is not null.
 119      * <LI>
 120      * {@code object} is an instance of class TextSyntax.
 121      * <LI>
 122      * This text attribute's underlying string and {@code object}'s
 123      * underlying string are equal.
 124      * <LI>
 125      * This text attribute's locale and {@code object}'s locale are
 126      * equal.
 127      * </OL>
 128      *
 129      * @param  object  Object to compare to.
 130      *
 131      * @return  True if {@code object} is equivalent to this text
 132      *          attribute, false otherwise.
 133      */
 134     public boolean equals(Object object) {
 135         return(object != null &&
 136                object instanceof TextSyntax &&
 137                this.value.equals (((TextSyntax) object).value) &&
 138                this.locale.equals (((TextSyntax) object).locale));
 139     }
 140 
 141     /**
 142      * Returns a String identifying this text attribute. The String is
 143      * the attribute's underlying text string.
 144      *
 145      * @return  A String identifying this object.
 146      */
 147     public String toString(){
 148         return value;
 149     }
 150 
 151 }
< prev index next >