< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 
  27 package javax.print.attribute;
  28 
  29 import java.io.Serializable;
  30 import java.util.Locale;
  31 
  32 /**
  33  * Class TextSyntax is an abstract base class providing the common
  34  * implementation of all attributes whose value is a string. The text attribute
  35  * includes a locale to indicate the natural language. Thus, a text attribute
  36  * always represents a localized string. Once constructed, a text attribute's
  37  * value is immutable.
  38  *
  39  * @author  David Mendenhall
  40  * @author  Alan Kaminsky
  41  */
  42 public abstract class TextSyntax implements Serializable, Cloneable {
  43 



  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 
  88     /**
  89      * Returns this text attribute's text string.
  90      * @return the text string.

  91      */
  92     public String getValue() {
  93         return value;
  94     }
  95 
  96     /**
  97      * Returns this text attribute's text string's natural language (locale).

  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 }
   1 /*
   2  * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 

  26 package javax.print.attribute;
  27 
  28 import java.io.Serializable;
  29 import java.util.Locale;
  30 
  31 /**
  32  * Class {@code TextSyntax} is an abstract base class providing the common
  33  * implementation of all attributes whose value is a string. The text attribute
  34  * includes a locale to indicate the natural language. Thus, a text attribute
  35  * always represents a localized string. Once constructed, a text attribute's
  36  * value is immutable.
  37  *
  38  * @author David Mendenhall
  39  * @author Alan Kaminsky
  40  */
  41 public abstract class TextSyntax implements Serializable, Cloneable {
  42 
  43     /**
  44      * Use serialVersionUID from JDK 1.4 for interoperability.
  45      */
  46     private static final long serialVersionUID = -8130648736378144102L;
  47 
  48     /**
  49      * String value of this text attribute.
  50      *
  51      * @serial
  52      */
  53     private String value;
  54 
  55     /**
  56      * Locale of this text attribute.
  57      *
  58      * @serial
  59      */
  60     private Locale locale;
  61 
  62     /**
  63      * Constructs a {@code TextAttribute} with the specified string and locale.
  64      *
  65      * @param  value text string
  66      * @param  locale natural language of the text string. {@code null} is
  67      *         interpreted to mean the default locale for as returned by
  68      *         {@code Locale.getDefault()}
  69      * @throws NullPointerException if {@code value} is {@code null}


  70      */
  71     protected TextSyntax(String value, Locale locale) {
  72         this.value = verify (value);
  73         this.locale = verify (locale);
  74     }
  75 
  76     private static String verify(String value) {
  77         if (value == null) {
  78             throw new NullPointerException(" value is null");
  79         }
  80         return value;
  81     }
  82 
  83     private static Locale verify(Locale locale) {
  84         if (locale == null) {
  85             return Locale.getDefault();
  86         }
  87         return locale;
  88     }
  89 
  90     /**
  91      * Returns this text attribute's text string.
  92      *
  93      * @return the text string
  94      */
  95     public String getValue() {
  96         return value;
  97     }
  98 
  99     /**
 100      * Returns this text attribute's text string's natural language (locale).
 101      *
 102      * @return the locale
 103      */
 104     public Locale getLocale() {
 105         return locale;
 106     }
 107 
 108     /**
 109      * Returns a hashcode for this text attribute.
 110      *
 111      * @return a hashcode value for this object
 112      */
 113     public int hashCode() {
 114         return value.hashCode() ^ locale.hashCode();
 115     }
 116 
 117     /**
 118      * Returns whether this text attribute is equivalent to the passed in
 119      * object. To be equivalent, all of the following conditions must be true:
 120      * <ol type=1>
 121      *   <li>{@code object} is not {@code null}.
 122      *   <li>{@code object} is an instance of class {@code TextSyntax}.
 123      *   <li>This text attribute's underlying string and {@code object}'s



 124      *   underlying string are equal.
 125      *   <li>This text attribute's locale and {@code object}'s locale are equal.
 126      * </ol>


 127      *
 128      * @param  object {@code Object} to compare to
 129      * @return {@code true} if {@code object} is equivalent to this text
 130      *         attribute, {@code false} otherwise

 131      */
 132     public boolean equals(Object object) {
 133         return(object != null &&
 134                object instanceof TextSyntax &&
 135                this.value.equals (((TextSyntax) object).value) &&
 136                this.locale.equals (((TextSyntax) object).locale));
 137     }
 138 
 139     /**
 140      * Returns a {@code String} identifying this text attribute. The
 141      * {@code String} is the attribute's underlying text string.
 142      *
 143      * @return a {@code String} identifying this object
 144      */
 145     public String toString(){
 146         return value;
 147     }

 148 }
< prev index next >