home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / DecimalFormatSymbols.java < prev    next >
Text File  |  1997-05-20  |  8KB  |  269 lines

  1. /*
  2.  * @(#)DecimalFormatSymbols.java    1.12 97/01/29
  3.  *
  4.  * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
  5.  * (C) Copyright IBM Corp. 1996 - All Rights Reserved
  6.  *
  7.  * Portions copyright (c) 1996-1997 Sun Microsystems, Inc. All Rights Reserved.
  8.  *
  9.  *   The original version of this source code and documentation is copyrighted
  10.  * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
  11.  * materials are provided under terms of a License Agreement between Taligent
  12.  * and Sun. This technology is protected by multiple US and International
  13.  * patents. This notice and attribution to Taligent may not be removed.
  14.  *   Taligent is a registered trademark of Taligent, Inc.
  15.  *
  16.  * Permission to use, copy, modify, and distribute this software
  17.  * and its documentation for NON-COMMERCIAL purposes and without
  18.  * fee is hereby granted provided that this copyright notice
  19.  * appears in all copies. Please refer to the file "copyright.html"
  20.  * for further important copyright and licensing information.
  21.  *
  22.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  23.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  24.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  25.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  26.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  27.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  28.  *
  29.  */
  30.  
  31. package java.text;
  32. import java.io.Serializable;
  33. import java.util.ResourceBundle;
  34. import java.util.Locale;
  35.  
  36. /**
  37.  * This class represents the set of symbols (such as the decimal separator,
  38.  * the grouping separator, and so on) needed by <code>DecimalFormat</code>
  39.  * to format numbers. <code>DecimalFormat</code> creates for itself an instance of
  40.  * <code>DecimalFormatSymbols</code> from its locale data.  If you need to change any
  41.  * of these symbols, you can get the <code>DecimalFormatSymbols</code> object from
  42.  * your <code>DecimalFormat</code> and modify it.
  43.  *
  44.  * @see          java.util.Locale
  45.  * @see          DecimalFormat
  46.  * @version      1.12 29 Jan 1997
  47.  * @author       Mark Davis
  48.  */
  49.  
  50. final public class DecimalFormatSymbols implements Cloneable, Serializable {
  51.  
  52.     /**
  53.      * Create a DecimalFormatSymbols object for the default locale.
  54.      */
  55.     public DecimalFormatSymbols() {
  56.         initialize( Locale.getDefault() );
  57.     }
  58.  
  59.     /**
  60.      * Create a DecimalFormatSymbols object for the given locale.
  61.      */
  62.     public DecimalFormatSymbols( Locale locale ) {
  63.         initialize( locale );
  64.     }
  65.  
  66.     /**
  67.      * character used for zero. Different for Arabic, etc.
  68.      */
  69.     public char getZeroDigit() {
  70.         return zeroDigit;
  71.     }
  72.  
  73.     public void setZeroDigit(char zeroDigit) {
  74.         this.zeroDigit = zeroDigit;
  75.     }
  76.  
  77.     /**
  78.      * character used for thousands separator. Different for French, etc.
  79.      */
  80.     public char getGroupingSeparator() {
  81.         return groupingSeparator;
  82.     }
  83.  
  84.     public void setGroupingSeparator(char groupingSeparator) {
  85.         this.groupingSeparator = groupingSeparator;
  86.     }
  87.  
  88.     /**
  89.      * character used for decimal sign. Different for French, etc.
  90.      */
  91.     public char getDecimalSeparator() {
  92.         return decimalSeparator;
  93.     }
  94.  
  95.     public void setDecimalSeparator(char decimalSeparator) {
  96.         this.decimalSeparator = decimalSeparator;
  97.     }
  98.  
  99.     /**
  100.      * character used for mille percent sign. Different for Arabic, etc.
  101.      */
  102.     public char getPerMill() {
  103.         return perMill;
  104.     }
  105.  
  106.     public void setPerMill(char perMill) {
  107.         this.perMill = perMill;
  108.     }
  109.  
  110.     /**
  111.      * character used for percent sign. Different for Arabic, etc.
  112.      */
  113.     public char getPercent() {
  114.         return percent;
  115.     }
  116.  
  117.     public void setPercent(char percent) {
  118.         this.percent = percent;
  119.     }
  120.  
  121.     /**
  122.      * character used for a digit in a pattern.
  123.      */
  124.     public char getDigit() {
  125.         return digit;
  126.     }
  127.  
  128.     public void setDigit(char digit) {
  129.         this.digit = digit;
  130.     }
  131.  
  132.     /**
  133.      * character used to separate positive and negative subpatterns
  134.      * in a pattern.
  135.      */
  136.     public char getPatternSeparator() {
  137.         return patternSeparator;
  138.     }
  139.  
  140.     public void setPatternSeparator(char patternSeparator) {
  141.         this.patternSeparator = patternSeparator;
  142.     }
  143.  
  144.     /**
  145.      * character used to represent infinity. Almost always left
  146.      * unchanged.
  147.      */
  148.  
  149.     public String getInfinity() {
  150.         return infinity;
  151.     }
  152.  
  153.     public void setInfinity(String infinity) {
  154.         this.infinity = infinity;
  155.     }
  156.  
  157.     /**
  158.      * character used to represent NaN. Almost always left
  159.      * unchanged.
  160.      */
  161.     public String getNaN() {
  162.         return NaN;
  163.     }
  164.  
  165.     public void setNaN(String NaN) {
  166.         this.NaN = NaN;
  167.     }
  168.  
  169.     /**
  170.      * character used to represent minus sign. If no explicit
  171.      * negative format is specified, one is formed by prefixing
  172.      * minusSign to the positive format.
  173.      */
  174.     public char getMinusSign() {
  175.         return minusSign;
  176.     }
  177.  
  178.     public void setMinusSign(char minusSign) {
  179.         this.minusSign = minusSign;
  180.     }
  181.  
  182.  
  183.     /**
  184.      * Standard override.
  185.      */
  186.     public Object clone() {
  187.         try {
  188.             return (DecimalFormatSymbols)super.clone();
  189.             // other fields are bit-copied
  190.         } catch (CloneNotSupportedException e) {
  191.             throw new InternalError();
  192.         }
  193.     }
  194.  
  195.     /**
  196.      * Override equals
  197.      */
  198.     public boolean equals(Object obj) {
  199.         if (this == obj) return true;
  200.         if (getClass() != obj.getClass()) return false;
  201.         DecimalFormatSymbols other = (DecimalFormatSymbols) obj;
  202.         return (zeroDigit == other.zeroDigit
  203.                 && groupingSeparator == other.groupingSeparator
  204.                 && decimalSeparator == other.decimalSeparator
  205.                 && percent == other.percent
  206.                 && perMill == other.perMill
  207.                 && digit == other.digit
  208.                 && minusSign == other.minusSign
  209.                 && patternSeparator == other.patternSeparator
  210.                 && infinity.equals(other.infinity)
  211.                 && NaN.equals(other.NaN)
  212.                 && currencySymbol.equals(other.currencySymbol)
  213.                 && intlCurrencySymbol.equals(other.intlCurrencySymbol));
  214.     }
  215.  
  216.     /**
  217.      * Override hashCode
  218.      */
  219.     public int hashCode() {
  220.             int result = zeroDigit;
  221.             result = result * 37 + groupingSeparator;
  222.             result = result * 37 + decimalSeparator;
  223.             return result;
  224.     }
  225.  
  226.     /**
  227.      * Initializes the symbols from the LocaleElements resource bundle.
  228.      * Note: The organization of LocaleElements badly needs to be
  229.      * cleaned up.
  230.      */
  231.     private void initialize( Locale locale ) {
  232.         ResourceBundle rb = ResourceBundle.getBundle
  233.                             ("java.text.resources.LocaleElements", locale);
  234.  
  235.         String[] numberElements = rb.getStringArray("NumberElements");
  236.  
  237.         this.decimalSeparator = numberElements[0].charAt(0);
  238.         this.groupingSeparator = numberElements[1].charAt(0);
  239.         // workaround bug - numberElements[2].charAt(
  240.         this.patternSeparator = ';';
  241.         this.percent = numberElements[3].charAt(0);
  242.         this.zeroDigit = numberElements[4].charAt(0); //different for Arabic,etc.
  243.         this.digit = numberElements[5].charAt(0);
  244.         this.minusSign = numberElements[6].charAt(0);
  245.  
  246.         String[] currencyElements = rb.getStringArray("CurrencyElements");
  247.         currencySymbol = currencyElements[0];
  248.         intlCurrencySymbol = currencyElements[1];
  249.  
  250.         // Not yet available from resource bundle.
  251.         this.perMill = '\u2030';
  252.         this.infinity  = "\u221E";
  253.         this.NaN = "\uFFFD";
  254.     }
  255.  
  256.     private  char    zeroDigit;
  257.     private  char    groupingSeparator;
  258.     private  char    decimalSeparator;
  259.     private  char    perMill;
  260.     private  char    percent;
  261.     private  char    digit;
  262.     private  char    patternSeparator;
  263.     private  String  infinity;
  264.     private  String  NaN;
  265.     private  char    minusSign;
  266.     private  String  currencySymbol;
  267.     private  String  intlCurrencySymbol;
  268. }
  269.