< prev index next >

src/java.base/share/classes/java/util/Currency.java

Print this page




  96  * <p>
  97  * Where syntactically malformed entries are encountered, the entry is ignored
  98  * and the remainder of entries in file are processed. For instances where duplicate
  99  * country code entries exist, the behavior of the Currency information for that
 100  * {@code Currency} is undefined and the remainder of entries in file are processed.
 101  * <p>
 102  * If multiple property entries with same currency code but different numeric code
 103  * and/or minor unit are encountered, those entries are ignored and the remainder
 104  * of entries in file are processed.
 105  *
 106  * <p>
 107  * It is recommended to use {@link java.math.BigDecimal} class while dealing
 108  * with {@code Currency} or monetary values as it provides better handling of floating
 109  * point numbers and their operations.
 110  *
 111  * @see java.math.BigDecimal
 112  * @since 1.4
 113  */
 114 public final class Currency implements Serializable {
 115 

 116     private static final long serialVersionUID = -158308464356906721L;
 117 
 118     /**
 119      * ISO 4217 currency code for this currency.
 120      *
 121      * @serial
 122      */
 123     private final String currencyCode;
 124 
 125     /**
 126      * Default fraction digits for this currency.
 127      * Set from currency data tables.
 128      */
 129     private final transient int defaultFractionDigits;
 130 
 131     /**
 132      * ISO 4217 numeric code for this currency.
 133      * Set from currency data tables.
 134      */
 135     private final transient int numericCode;


 644             return result;
 645         }
 646 
 647         // use currency code as symbol of last resort
 648         return currencyCode;
 649     }
 650 
 651     /**
 652      * Returns the ISO 4217 currency code of this currency.
 653      *
 654      * @return the ISO 4217 currency code of this currency
 655      */
 656     @Override
 657     public String toString() {
 658         return currencyCode;
 659     }
 660 
 661     /**
 662      * Resolves instances being deserialized to a single instance per currency.
 663      */

 664     private Object readResolve() {
 665         return getInstance(currencyCode);
 666     }
 667 
 668     /**
 669      * Gets the main table entry for the country whose country code consists
 670      * of char1 and char2.
 671      */
 672     private static int getMainTableEntry(char char1, char char2) {
 673         if (char1 < 'A' || char1 > 'Z' || char2 < 'A' || char2 > 'Z') {
 674             throw new IllegalArgumentException();
 675         }
 676         return mainTable[(char1 - 'A') * A_TO_Z + (char2 - 'A')];
 677     }
 678 
 679     /**
 680      * Sets the main table entry for the country whose country code consists
 681      * of char1 and char2.
 682      */
 683     private static void setMainTableEntry(char char1, char char2, int entry) {




  96  * <p>
  97  * Where syntactically malformed entries are encountered, the entry is ignored
  98  * and the remainder of entries in file are processed. For instances where duplicate
  99  * country code entries exist, the behavior of the Currency information for that
 100  * {@code Currency} is undefined and the remainder of entries in file are processed.
 101  * <p>
 102  * If multiple property entries with same currency code but different numeric code
 103  * and/or minor unit are encountered, those entries are ignored and the remainder
 104  * of entries in file are processed.
 105  *
 106  * <p>
 107  * It is recommended to use {@link java.math.BigDecimal} class while dealing
 108  * with {@code Currency} or monetary values as it provides better handling of floating
 109  * point numbers and their operations.
 110  *
 111  * @see java.math.BigDecimal
 112  * @since 1.4
 113  */
 114 public final class Currency implements Serializable {
 115 
 116     @java.io.Serial
 117     private static final long serialVersionUID = -158308464356906721L;
 118 
 119     /**
 120      * ISO 4217 currency code for this currency.
 121      *
 122      * @serial
 123      */
 124     private final String currencyCode;
 125 
 126     /**
 127      * Default fraction digits for this currency.
 128      * Set from currency data tables.
 129      */
 130     private final transient int defaultFractionDigits;
 131 
 132     /**
 133      * ISO 4217 numeric code for this currency.
 134      * Set from currency data tables.
 135      */
 136     private final transient int numericCode;


 645             return result;
 646         }
 647 
 648         // use currency code as symbol of last resort
 649         return currencyCode;
 650     }
 651 
 652     /**
 653      * Returns the ISO 4217 currency code of this currency.
 654      *
 655      * @return the ISO 4217 currency code of this currency
 656      */
 657     @Override
 658     public String toString() {
 659         return currencyCode;
 660     }
 661 
 662     /**
 663      * Resolves instances being deserialized to a single instance per currency.
 664      */
 665     @java.io.Serial
 666     private Object readResolve() {
 667         return getInstance(currencyCode);
 668     }
 669 
 670     /**
 671      * Gets the main table entry for the country whose country code consists
 672      * of char1 and char2.
 673      */
 674     private static int getMainTableEntry(char char1, char char2) {
 675         if (char1 < 'A' || char1 > 'Z' || char2 < 'A' || char2 > 'Z') {
 676             throw new IllegalArgumentException();
 677         }
 678         return mainTable[(char1 - 'A') * A_TO_Z + (char2 - 'A')];
 679     }
 680 
 681     /**
 682      * Sets the main table entry for the country whose country code consists
 683      * of char1 and char2.
 684      */
 685     private static void setMainTableEntry(char char1, char char2, int entry) {


< prev index next >