author | duke |
Wed, 05 Jul 2017 21:44:52 +0200 | |
changeset 38481 | c81b0662f43a |
parent 38440 | 9e77c5b81def |
permissions | -rw-r--r-- |
2 | 1 |
/* |
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
2 |
* Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 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. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
import java.io.*; |
|
13790
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
25 |
import java.text.*; |
2 | 26 |
import java.util.*; |
27 |
import java.util.regex.*; |
|
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
28 |
import java.util.stream.Collectors; |
2 | 29 |
|
30 |
public class PropertiesTest { |
|
14697
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
31 |
public static void main(String[] args) throws Exception { |
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
32 |
if (args.length == 2 && args[0].equals("-d")) { |
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
33 |
dump(args[1]); |
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
34 |
} else if (args.length == 4 && args[0].equals("-c")) { |
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
35 |
compare(args[1], args[2], args[3]); |
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
36 |
} else if (args.length == 1 && args[0].equals("bug7102969")) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
37 |
bug7102969(); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
38 |
} else if (args.length == 1 && args[0].equals("bug8157138")) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
39 |
bug8157138(); |
14697
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
40 |
} else { |
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
41 |
System.err.println("Usage: java PropertiesTest -d <dumpfile>"); |
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
42 |
System.err.println(" java PropertiesTest -c <beforedump> <afterdump> <propsfile>"); |
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
43 |
System.err.println(" java PropertiesTest bug[JBS bug id number] e.g. bug7102969"); |
14697
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
44 |
System.exit(-1); |
2 | 45 |
} |
46 |
} |
|
47 |
||
48 |
private static void dump(String outfile) { |
|
49 |
File f = new File(outfile); |
|
50 |
PrintWriter pw; |
|
51 |
try { |
|
52 |
f.createNewFile(); |
|
53 |
pw = new PrintWriter(f); |
|
54 |
} catch (Exception fnfe) { |
|
55 |
throw new RuntimeException(fnfe); |
|
56 |
} |
|
57 |
for (char c1 = 'A'; c1 <= 'Z'; c1++) { |
|
58 |
for (char c2 = 'A'; c2 <= 'Z'; c2++) { |
|
59 |
String ctry = new StringBuilder().append(c1).append(c2).toString(); |
|
60 |
try { |
|
61 |
Currency c = Currency.getInstance(new Locale("", ctry)); |
|
62 |
if (c != null) { |
|
63 |
pw.printf(Locale.ROOT, "%s=%s,%03d,%1d\n", |
|
64 |
ctry, |
|
65 |
c.getCurrencyCode(), |
|
66 |
c.getNumericCode(), |
|
67 |
c.getDefaultFractionDigits()); |
|
68 |
} |
|
69 |
} catch (IllegalArgumentException iae) { |
|
70 |
// invalid country code |
|
71 |
continue; |
|
72 |
} |
|
73 |
} |
|
74 |
} |
|
75 |
pw.flush(); |
|
76 |
pw.close(); |
|
77 |
} |
|
78 |
||
14697
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
79 |
private static void compare(String beforeFile, String afterFile, String propsFile) |
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
80 |
throws IOException |
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
81 |
{ |
2 | 82 |
// load file contents |
83 |
Properties before = new Properties(); |
|
14697
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
84 |
try (Reader reader = new FileReader(beforeFile)) { |
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
85 |
before.load(reader); |
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
86 |
} |
2 | 87 |
Properties after = new Properties(); |
14697
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
88 |
try (Reader reader = new FileReader(afterFile)) { |
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
89 |
after.load(reader); |
2 | 90 |
} |
91 |
||
92 |
// remove the same contents from the 'after' properties |
|
93 |
Set<String> keys = before.stringPropertyNames(); |
|
94 |
for (String key: keys) { |
|
95 |
String beforeVal = before.getProperty(key); |
|
96 |
String afterVal = after.getProperty(key); |
|
97 |
System.out.printf("Removing country: %s. before: %s, after: %s", key, beforeVal, afterVal); |
|
98 |
if (beforeVal.equals(afterVal)) { |
|
99 |
after.remove(key); |
|
100 |
System.out.printf(" --- removed\n"); |
|
101 |
} else { |
|
102 |
System.out.printf(" --- NOT removed\n"); |
|
103 |
} |
|
104 |
} |
|
105 |
||
106 |
// now look at the currency.properties |
|
107 |
Properties p = new Properties(); |
|
14697
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
108 |
try (Reader reader = new FileReader(propsFile)) { |
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
13790
diff
changeset
|
109 |
p.load(reader); |
2 | 110 |
} |
111 |
||
112 |
// test each replacements |
|
113 |
keys = p.stringPropertyNames(); |
|
114 |
Pattern propertiesPattern = |
|
13790
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
115 |
Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*" + |
29524
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
14697
diff
changeset
|
116 |
"(\\d+)\\s*,?\\s*(\\d{4}-\\d{2}-\\d{2}T\\d{2}:" + |
13790
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
117 |
"\\d{2}:\\d{2})?"); |
2 | 118 |
for (String key: keys) { |
119 |
String val = p.getProperty(key); |
|
13790
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
120 |
try { |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
121 |
if (countOccurrences(val, ',') == 3 && !isPastCutoverDate(val)) { |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
122 |
System.out.println("Skipping since date is in future"); |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
123 |
continue; // skip since date in future (no effect) |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
124 |
} |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
125 |
} catch (ParseException pe) { |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
126 |
// swallow - currency class should not honour this value |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
127 |
continue; |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
128 |
} |
2 | 129 |
String afterVal = after.getProperty(key); |
130 |
System.out.printf("Testing key: %s, val: %s... ", key, val); |
|
13790
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
131 |
System.out.println("AfterVal is : " + afterVal); |
2 | 132 |
|
133 |
Matcher m = propertiesPattern.matcher(val.toUpperCase(Locale.ROOT)); |
|
134 |
if (!m.find()) { |
|
135 |
// format is not recognized. |
|
136 |
System.out.printf("Format is not recognized.\n"); |
|
137 |
if (afterVal != null) { |
|
138 |
throw new RuntimeException("Currency data replacement for "+key+" failed: It was incorrectly altered to "+afterVal); |
|
139 |
} |
|
140 |
||
141 |
// ignore this |
|
142 |
continue; |
|
143 |
} |
|
29524
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
14697
diff
changeset
|
144 |
|
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
14697
diff
changeset
|
145 |
String code = m.group(1); |
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
14697
diff
changeset
|
146 |
int numeric = Integer.parseInt(m.group(2)); |
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
14697
diff
changeset
|
147 |
int fraction = Integer.parseInt(m.group(3)); |
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
14697
diff
changeset
|
148 |
if (fraction > 9) { |
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
14697
diff
changeset
|
149 |
System.out.println("Skipping since the fraction is greater than 9"); |
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
14697
diff
changeset
|
150 |
continue; |
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
14697
diff
changeset
|
151 |
} |
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
14697
diff
changeset
|
152 |
|
2 | 153 |
Matcher mAfter = propertiesPattern.matcher(afterVal); |
154 |
mAfter.find(); |
|
155 |
||
156 |
String codeAfter = mAfter.group(1); |
|
157 |
int numericAfter = Integer.parseInt(mAfter.group(2)); |
|
158 |
int fractionAfter = Integer.parseInt(mAfter.group(3)); |
|
159 |
if (code.equals(codeAfter) && |
|
160 |
(numeric == numericAfter)&& |
|
161 |
(fraction == fractionAfter)) { |
|
162 |
after.remove(key); |
|
163 |
} else { |
|
164 |
throw new RuntimeException("Currency data replacement for "+key+" failed: actual: (alphacode: "+codeAfter+", numcode: "+numericAfter+", fraction: "+fractionAfter+"), expected: (alphacode: "+code+", numcode: "+numeric+", fraction: "+fraction+")"); |
|
165 |
} |
|
166 |
System.out.printf("Success!\n"); |
|
167 |
} |
|
168 |
if (!after.isEmpty()) { |
|
169 |
StringBuilder sb = new StringBuilder() |
|
170 |
.append("Currency data replacement failed. Unnecessary modification was(were) made for the following currencies:\n"); |
|
171 |
keys = after.stringPropertyNames(); |
|
172 |
for (String key : keys) { |
|
173 |
sb.append(" country: ") |
|
174 |
.append(key) |
|
175 |
.append(" currency: ") |
|
176 |
.append(after.getProperty(key)) |
|
177 |
.append("\n"); |
|
178 |
} |
|
179 |
throw new RuntimeException(sb.toString()); |
|
180 |
} |
|
181 |
} |
|
13790
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
182 |
|
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
183 |
private static void bug7102969() { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
184 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
185 |
// check the correct overriding of special case entries |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
186 |
Currency cur = Currency.getInstance(new Locale("", "JP")); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
187 |
if (!cur.getCurrencyCode().equals("ABC")) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
188 |
throw new RuntimeException("[Expected: ABC as currency code of JP, found: " |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
189 |
+ cur.getCurrencyCode() + "]"); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
190 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
191 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
192 |
/* check if the currency instance is returned by |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
193 |
* getAvailableCurrencies() method |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
194 |
*/ |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
195 |
if (!Currency.getAvailableCurrencies().contains(cur)) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
196 |
throw new RuntimeException("[The Currency instance [" |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
197 |
+ cur.getCurrencyCode() + ", " |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
198 |
+ cur.getNumericCode() + ", " |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
199 |
+ cur.getDefaultFractionDigits() |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
200 |
+ "] is not available in the currencies list]"); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
201 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
202 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
203 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
204 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
205 |
private static void bug8157138() { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
206 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
207 |
/* check the currencies which exist only as a special case are |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
208 |
* accessible i.e. it should not throw IllegalArgumentException |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
209 |
*/ |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
210 |
try { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
211 |
Currency.getInstance("MAD"); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
212 |
} catch (IllegalArgumentException ex) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
213 |
throw new RuntimeException("Test Failed: " |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
214 |
+ "special case currency instance MAD not found" |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
215 |
+ " via Currency.getInstance(\"MAD\")"); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
216 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
217 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
218 |
try { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
219 |
Currency.getInstance("ABC"); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
220 |
} catch (IllegalArgumentException ex) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
221 |
throw new RuntimeException("Test Failed: " |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
222 |
+ "special case currency instance ABC not found" |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
223 |
+ " via Currency.getInstance(\"ABC\")"); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
224 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
225 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
226 |
/* check the currency value is returned by getAvailableCurrencies() |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
227 |
* method |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
228 |
*/ |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
229 |
List<Currency> list = Currency.getAvailableCurrencies().stream() |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
230 |
.filter(cur -> cur.getCurrencyCode().equals("MAD")) |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
231 |
.collect(Collectors.toList()); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
232 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
233 |
if (list.isEmpty()) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
234 |
throw new RuntimeException("Test Failed: " |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
235 |
+ "special case currency instance MAD not found" |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
236 |
+ " in Currency.getAvailableCurrencies() list"); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
237 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
238 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
239 |
list = Currency.getAvailableCurrencies().stream() |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
240 |
.filter(cur -> cur.getCurrencyCode().equals("ABC")) |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
241 |
.collect(Collectors.toList()); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
242 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
243 |
if (list.isEmpty()) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
244 |
throw new RuntimeException("Test Failed: " |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
245 |
+ "special case currency instance ABC not found" |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
246 |
+ " in Currency.getAvailableCurrencies() list"); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
247 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
248 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
249 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
29524
diff
changeset
|
250 |
|
13790
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
251 |
private static boolean isPastCutoverDate(String s) |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
252 |
throws IndexOutOfBoundsException, NullPointerException, ParseException { |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
253 |
String dateString = s.substring(s.lastIndexOf(',')+1, s.length()).trim(); |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
254 |
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ROOT); |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
255 |
format.setTimeZone(TimeZone.getTimeZone("GMT")); |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
256 |
format.setLenient(false); |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
257 |
|
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
258 |
long time = format.parse(dateString).getTime(); |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
259 |
if (System.currentTimeMillis() - time >= 0L) { |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
260 |
return true; |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
261 |
} else { |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
262 |
return false; |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
263 |
} |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
264 |
} |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
265 |
|
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
266 |
private static int countOccurrences(String value, char match) { |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
267 |
int count = 0; |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
268 |
for (char c : value.toCharArray()) { |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
269 |
if (c == match) { |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
270 |
++count; |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
271 |
} |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
272 |
} |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
273 |
return count; |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
5506
diff
changeset
|
274 |
} |
2 | 275 |
} |