]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - jars/icu4j-52_1/main/classes/currdata/src/com/ibm/icu/impl/ICUCurrencyMetaInfo.java
Upgrade ICU4J.
[Dictionary.git] / jars / icu4j-52_1 / main / classes / currdata / src / com / ibm / icu / impl / ICUCurrencyMetaInfo.java
similarity index 83%
rename from jars/icu4j-4_8_1_1/main/classes/currdata/src/com/ibm/icu/impl/ICUCurrencyMetaInfo.java
rename to jars/icu4j-52_1/main/classes/currdata/src/com/ibm/icu/impl/ICUCurrencyMetaInfo.java
index 26d5585e6f244c0043a10a5965825cad5514b5d2..3eca2de98dcdaab778a8c6ee8a78e80c55341c46 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *******************************************************************************
- * Copyright (C) 2009-2010, International Business Machines Corporation and    *
+ * Copyright (C) 2009-2013, International Business Machines Corporation and    *
  * others. All Rights Reserved.                                                *
  *******************************************************************************
  */
@@ -72,6 +72,9 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
         if (filter.from != Long.MIN_VALUE || filter.to != Long.MAX_VALUE) {
             needed |= Date;
         }
+        if (filter.tenderOnly) {
+            needed |= Tender;
+        }
 
         if (needed != 0) {
             if (filter.region != null) {
@@ -93,8 +96,8 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
             int needed, ICUResourceBundle b) {
 
         String region = b.getKey();
-        if ((needed & nonRegion) == 0) {
-            collector.collect(b.getKey(), null, 0, 0, -1);
+        if (needed == Region) {
+            collector.collect(b.getKey(), null, 0, 0, -1, false);
             return;
         }
 
@@ -109,6 +112,7 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
             String currency = null;
             long from = Long.MIN_VALUE;
             long to = Long.MAX_VALUE;
+            boolean tender = true;
 
             if ((needed & Currency) != 0) {
                 ICUResourceBundle currBundle = r.at("id");
@@ -119,32 +123,39 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
             }
 
             if ((needed & Date) != 0) {
-                from = getDate(r.at("from"), Long.MIN_VALUE);
-                to = getDate(r.at("to"), Long.MAX_VALUE);
+                from = getDate(r.at("from"), Long.MIN_VALUE, false);
+                to = getDate(r.at("to"), Long.MAX_VALUE, true);
                 // In the data, to is always > from.  This means that when we have a range
                 // from == to, the comparisons below will always do the right thing, despite
                 // the range being technically empty.  It really should be [from, from+1) but
                 // this way we don't need to fiddle with it.
-                if (filter.from >= to) {
+                if (filter.from > to) {
                     continue;
                 }
-                if (filter.to <= from) {
+                if (filter.to < from) {
+                    continue;
+                }
+            }
+            if ((needed & Tender) != 0) {
+                ICUResourceBundle tenderBundle = r.at("tender");
+                tender = tenderBundle == null || "true".equals(tenderBundle.getString());
+                if (filter.tenderOnly && !tender) {
                     continue;
                 }
             }
 
             // data lists elements in priority order, so 'i' suffices
-            collector.collect(region, currency, from, to, i);
+            collector.collect(region, currency, from, to, i, tender);
         }
     }
 
     private static final long MASK = 4294967295L;
-    private long getDate(ICUResourceBundle b, long defaultValue) {
+    private long getDate(ICUResourceBundle b, long defaultValue, boolean endOfDay) {
         if (b == null) {
             return defaultValue;
         }
         int[] values = b.getIntVector();
-        return ((long) values[0] << 32) | ((long) values[1] & MASK);
+        return ((long) values[0] << 32) | (((long) values[1]) & MASK);
     }
 
     // Utility, just because I don't like the n^2 behavior of using list.contains to build a
@@ -174,8 +185,8 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
         // about duplicates.
         private List<CurrencyInfo> result = new ArrayList<CurrencyInfo>();
 
-        public void collect(String region, String currency, long from, long to, int priority) {
-            result.add(new CurrencyInfo(region, currency, from, to, priority));
+        public void collect(String region, String currency, long from, long to, int priority, boolean tender) {
+            result.add(new CurrencyInfo(region, currency, from, to, priority, tender));
         }
 
         public List<CurrencyInfo> getList() {
@@ -183,14 +194,15 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
         }
 
         public int collects() {
-            return Region | Currency | Date;
+            return Everything;
         }
     }
 
     private static class RegionCollector implements Collector<String> {
         private final UniqueList<String> result = UniqueList.create();
 
-        public void collect(String region, String currency, long from, long to, int priority) {
+        public void collect(
+                String region, String currency, long from, long to, int priority, boolean tender) {
             result.add(region);
         }
 
@@ -206,7 +218,8 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
     private static class CurrencyCollector implements Collector<String> {
         private final UniqueList<String> result = UniqueList.create();
 
-        public void collect(String region, String currency, long from, long to, int priority) {
+        public void collect(
+                String region, String currency, long from, long to, int priority, boolean tender) {
             result.add(currency);
         }
 
@@ -222,8 +235,8 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
     private static final int Region = 1;
     private static final int Currency = 2;
     private static final int Date = 4;
-
-    private static final int nonRegion = Currency | Date;
+    private static final int Tender = 8;
+    private static final int Everything = Integer.MAX_VALUE;
 
     private static interface Collector<T> {
         /**
@@ -239,8 +252,9 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
          * @param from start time (0 if ignored)
          * @param to end time (0 if ignored)
          * @param priority priority (-1 if ignored)
+         * @param tender true if currency is legal tender.
          */
-        void collect(String region, String currency, long from, long to, int priority);
+        void collect(String region, String currency, long from, long to, int priority, boolean tender);
 
         /**
          * Return the list of unique items in the order in which we encountered them for the