< prev index next >

src/java.base/share/classes/java/text/ChoiceFormat.java

Print this page




 151  * }</pre>
 152  * </blockquote>
 153  *
 154  * <h2><a id="synchronization">Synchronization</a></h2>
 155  *
 156  * <p>
 157  * Choice formats are not synchronized.
 158  * It is recommended to create separate format instances for each thread.
 159  * If multiple threads access a format concurrently, it must be synchronized
 160  * externally.
 161  *
 162  *
 163  * @see          DecimalFormat
 164  * @see          MessageFormat
 165  * @author       Mark Davis
 166  * @since 1.1
 167  */
 168 public class ChoiceFormat extends NumberFormat {
 169 
 170     // Proclaim serial compatibility with 1.1 FCS

 171     private static final long serialVersionUID = 1795184449645032964L;
 172 
 173     /**
 174      * Sets the pattern.
 175      * @param newPattern See the class description.
 176      * @exception NullPointerException if {@code newPattern}
 177      *            is {@code null}
 178      */
 179     public void applyPattern(String newPattern) {
 180         StringBuffer[] segments = new StringBuffer[2];
 181         for (int i = 0; i < segments.length; ++i) {
 182             segments[i] = new StringBuffer();
 183         }
 184         double[] newChoiceLimits = new double[30];
 185         String[] newChoiceFormats = new String[30];
 186         int count = 0;
 187         int part = 0;
 188         double startValue = 0;
 189         double oldStartValue = Double.NaN;
 190         boolean inQuote = false;


 511 
 512     /**
 513      * Equality comparison between two
 514      */
 515     public boolean equals(Object obj) {
 516         if (obj == null) return false;
 517         if (this == obj)                      // quick check
 518             return true;
 519         if (getClass() != obj.getClass())
 520             return false;
 521         ChoiceFormat other = (ChoiceFormat) obj;
 522         return (Arrays.equals(choiceLimits, other.choiceLimits)
 523              && Arrays.equals(choiceFormats, other.choiceFormats));
 524     }
 525 
 526     /**
 527      * After reading an object from the input stream, do a simple verification
 528      * to maintain class invariants.
 529      * @throws InvalidObjectException if the objects read from the stream is invalid.
 530      */

 531     private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
 532         in.defaultReadObject();
 533         if (choiceLimits.length != choiceFormats.length) {
 534             throw new InvalidObjectException(
 535                     "limits and format arrays of different length.");
 536         }
 537     }
 538 
 539     // ===============privates===========================
 540 
 541     /**
 542      * A list of lower bounds for the choices.  The formatter will return
 543      * <code>choiceFormats[i]</code> if the number being formatted is greater than or equal to
 544      * <code>choiceLimits[i]</code> and less than <code>choiceLimits[i+1]</code>.
 545      * @serial
 546      */
 547     private double[] choiceLimits;
 548 
 549     /**
 550      * A list of choice strings.  The formatter will return




 151  * }</pre>
 152  * </blockquote>
 153  *
 154  * <h2><a id="synchronization">Synchronization</a></h2>
 155  *
 156  * <p>
 157  * Choice formats are not synchronized.
 158  * It is recommended to create separate format instances for each thread.
 159  * If multiple threads access a format concurrently, it must be synchronized
 160  * externally.
 161  *
 162  *
 163  * @see          DecimalFormat
 164  * @see          MessageFormat
 165  * @author       Mark Davis
 166  * @since 1.1
 167  */
 168 public class ChoiceFormat extends NumberFormat {
 169 
 170     // Proclaim serial compatibility with 1.1 FCS
 171     @java.io.Serial
 172     private static final long serialVersionUID = 1795184449645032964L;
 173 
 174     /**
 175      * Sets the pattern.
 176      * @param newPattern See the class description.
 177      * @exception NullPointerException if {@code newPattern}
 178      *            is {@code null}
 179      */
 180     public void applyPattern(String newPattern) {
 181         StringBuffer[] segments = new StringBuffer[2];
 182         for (int i = 0; i < segments.length; ++i) {
 183             segments[i] = new StringBuffer();
 184         }
 185         double[] newChoiceLimits = new double[30];
 186         String[] newChoiceFormats = new String[30];
 187         int count = 0;
 188         int part = 0;
 189         double startValue = 0;
 190         double oldStartValue = Double.NaN;
 191         boolean inQuote = false;


 512 
 513     /**
 514      * Equality comparison between two
 515      */
 516     public boolean equals(Object obj) {
 517         if (obj == null) return false;
 518         if (this == obj)                      // quick check
 519             return true;
 520         if (getClass() != obj.getClass())
 521             return false;
 522         ChoiceFormat other = (ChoiceFormat) obj;
 523         return (Arrays.equals(choiceLimits, other.choiceLimits)
 524              && Arrays.equals(choiceFormats, other.choiceFormats));
 525     }
 526 
 527     /**
 528      * After reading an object from the input stream, do a simple verification
 529      * to maintain class invariants.
 530      * @throws InvalidObjectException if the objects read from the stream is invalid.
 531      */
 532     @java.io.Serial
 533     private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
 534         in.defaultReadObject();
 535         if (choiceLimits.length != choiceFormats.length) {
 536             throw new InvalidObjectException(
 537                     "limits and format arrays of different length.");
 538         }
 539     }
 540 
 541     // ===============privates===========================
 542 
 543     /**
 544      * A list of lower bounds for the choices.  The formatter will return
 545      * <code>choiceFormats[i]</code> if the number being formatted is greater than or equal to
 546      * <code>choiceLimits[i]</code> and less than <code>choiceLimits[i+1]</code>.
 547      * @serial
 548      */
 549     private double[] choiceLimits;
 550 
 551     /**
 552      * A list of choice strings.  The formatter will return


< prev index next >