summaryrefslogtreecommitdiff
path: root/android_icu4j/src/main/java/android/icu/impl/number/DecimalFormatProperties.java
blob: 2f12241de130e878b71b394c5c345b426064d577 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
/* GENERATED SOURCE. DO NOT MODIFY. */
// © 2017 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html#License
package android.icu.impl.number;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.text.ParsePosition;
import java.util.ArrayList;
import java.util.Map;

import android.icu.impl.number.Padder.PadPosition;
import android.icu.text.CompactDecimalFormat.CompactStyle;
import android.icu.text.CurrencyPluralInfo;
import android.icu.text.PluralRules;
import android.icu.util.Currency;
import android.icu.util.Currency.CurrencyUsage;

/**
 * @hide Only a subset of ICU is exposed in Android
 */
public class DecimalFormatProperties implements Cloneable, Serializable {

    private static final DecimalFormatProperties DEFAULT = new DecimalFormatProperties();

    /** Auto-generated. */
    private static final long serialVersionUID = 4095518955889349243L;

    /** Controls the set of rules for parsing a string from the old DecimalFormat API. 
     * @hide Only a subset of ICU is exposed in Android*/
    public static enum ParseMode {
        /**
         * Lenient mode should be used if you want to accept malformed user input. It will use heuristics
         * to attempt to parse through typographical errors in the string.
         */
        LENIENT,

        /**
         * Strict mode should be used if you want to require that the input is well-formed. More
         * specifically, it differs from lenient mode in the following ways:
         *
         * <ul>
         * <li>Grouping widths must match the grouping settings. For example, "12,3,45" will fail if the
         * grouping width is 3, as in the pattern "#,##0".
         * <li>The string must contain a complete prefix and suffix. For example, if the pattern is
         * "{#};(#)", then "{123}" or "(123)" would match, but "{123", "123}", and "123" would all fail.
         * (The latter strings would be accepted in lenient mode.)
         * <li>Whitespace may not appear at arbitrary places in the string. In lenient mode, whitespace
         * is allowed to occur arbitrarily before and after prefixes and exponent separators.
         * <li>Leading grouping separators are not allowed, as in ",123".
         * <li>Minus and plus signs can only appear if specified in the pattern. In lenient mode, a plus
         * or minus sign can always precede a number.
         * <li>The set of characters that can be interpreted as a decimal or grouping separator is
         * smaller.
         * <li><strong>If currency parsing is enabled,</strong> currencies must only appear where
         * specified in either the current pattern string or in a valid pattern string for the current
         * locale. For example, if the pattern is "¤0.00", then "$1.23" would match, but "1.23$" would
         * fail to match.
         * </ul>
         */
        STRICT,
    }

    // The setters in this class should NOT have any side-effects or perform any validation. It is
    // up to the consumer of the property bag to deal with property validation.

    // The fields are all marked "transient" because custom serialization is being used.

    /*--------------------------------------------------------------------------------------------+/
    /| IMPORTANT!                                                                                 |/
    /| WHEN ADDING A NEW PROPERTY, add it here, in #_clear(), in #_copyFrom(), in #equals(),      |/
    /| and in #_hashCode().                                                                       |/
    /|                                                                                            |/
    /| The unit test PropertiesTest will catch if you forget to add it to #clear(), #copyFrom(),  |/
    /| or #equals(), but it will NOT catch if you forget to add it to #hashCode().                |/
    /+--------------------------------------------------------------------------------------------*/

    private transient Map<String, Map<String, String>> compactCustomData; // ICU4J-only
    private transient CompactStyle compactStyle;
    private transient Currency currency;
    private transient CurrencyPluralInfo currencyPluralInfo;
    private transient CurrencyUsage currencyUsage;
    private transient boolean decimalPatternMatchRequired;
    private transient boolean decimalSeparatorAlwaysShown;
    private transient boolean exponentSignAlwaysShown;
    private transient int formatWidth;
    private transient int groupingSize;
    private transient boolean groupingUsed;
    private transient int magnitudeMultiplier;
    private transient MathContext mathContext; // ICU4J-only
    private transient int maximumFractionDigits;
    private transient int maximumIntegerDigits;
    private transient int maximumSignificantDigits;
    private transient int minimumExponentDigits;
    private transient int minimumFractionDigits;
    private transient int minimumGroupingDigits;
    private transient int minimumIntegerDigits;
    private transient int minimumSignificantDigits;
    private transient BigDecimal multiplier;
    private transient String negativePrefix;
    private transient String negativePrefixPattern;
    private transient String negativeSuffix;
    private transient String negativeSuffixPattern;
    private transient PadPosition padPosition;
    private transient String padString;
    private transient boolean parseCaseSensitive;
    private transient boolean parseIntegerOnly;
    private transient ParseMode parseMode;
    private transient boolean parseNoExponent;
    private transient boolean parseToBigDecimal;
    private transient PluralRules pluralRules;
    private transient String positivePrefix;
    private transient String positivePrefixPattern;
    private transient String positiveSuffix;
    private transient String positiveSuffixPattern;
    private transient BigDecimal roundingIncrement;
    private transient RoundingMode roundingMode;
    private transient int secondaryGroupingSize;
    private transient boolean signAlwaysShown;

    /*--------------------------------------------------------------------------------------------+/
    /| IMPORTANT!                                                                                 |/
    /| WHEN ADDING A NEW PROPERTY, add it here, in #_clear(), in #_copyFrom(), in #equals(),      |/
    /| and in #_hashCode().                                                                       |/
    /|                                                                                            |/
    /| The unit test PropertiesTest will catch if you forget to add it to #clear(), #copyFrom(),  |/
    /| or #equals(), but it will NOT catch if you forget to add it to #hashCode().                |/
    /+--------------------------------------------------------------------------------------------*/

    public DecimalFormatProperties() {
        clear();
    }

    /**
     * Sets all properties to their defaults (unset).
     *
     * <p>
     * All integers default to -1 EXCEPT FOR MAGNITUDE MULTIPLIER which has a default of 0 (since
     * negative numbers are important).
     *
     * <p>
     * All booleans default to false.
     *
     * <p>
     * All non-primitive types default to null.
     *
     * @return The property bag, for chaining.
     */
    private DecimalFormatProperties _clear() {
        compactCustomData = null;
        compactStyle = null;
        currency = null;
        currencyPluralInfo = null;
        currencyUsage = null;
        decimalPatternMatchRequired = false;
        decimalSeparatorAlwaysShown = false;
        exponentSignAlwaysShown = false;
        formatWidth = -1;
        groupingSize = -1;
        groupingUsed = true;
        magnitudeMultiplier = 0;
        mathContext = null;
        maximumFractionDigits = -1;
        maximumIntegerDigits = -1;
        maximumSignificantDigits = -1;
        minimumExponentDigits = -1;
        minimumFractionDigits = -1;
        minimumGroupingDigits = -1;
        minimumIntegerDigits = -1;
        minimumSignificantDigits = -1;
        multiplier = null;
        negativePrefix = null;
        negativePrefixPattern = null;
        negativeSuffix = null;
        negativeSuffixPattern = null;
        padPosition = null;
        padString = null;
        parseCaseSensitive = false;
        parseIntegerOnly = false;
        parseMode = null;
        parseNoExponent = false;
        parseToBigDecimal = false;
        pluralRules = null;
        positivePrefix = null;
        positivePrefixPattern = null;
        positiveSuffix = null;
        positiveSuffixPattern = null;
        roundingIncrement = null;
        roundingMode = null;
        secondaryGroupingSize = -1;
        signAlwaysShown = false;
        return this;
    }

    private DecimalFormatProperties _copyFrom(DecimalFormatProperties other) {
        compactCustomData = other.compactCustomData;
        compactStyle = other.compactStyle;
        currency = other.currency;
        currencyPluralInfo = other.currencyPluralInfo;
        currencyUsage = other.currencyUsage;
        decimalPatternMatchRequired = other.decimalPatternMatchRequired;
        decimalSeparatorAlwaysShown = other.decimalSeparatorAlwaysShown;
        exponentSignAlwaysShown = other.exponentSignAlwaysShown;
        formatWidth = other.formatWidth;
        groupingSize = other.groupingSize;
        groupingUsed = other.groupingUsed;
        magnitudeMultiplier = other.magnitudeMultiplier;
        mathContext = other.mathContext;
        maximumFractionDigits = other.maximumFractionDigits;
        maximumIntegerDigits = other.maximumIntegerDigits;
        maximumSignificantDigits = other.maximumSignificantDigits;
        minimumExponentDigits = other.minimumExponentDigits;
        minimumFractionDigits = other.minimumFractionDigits;
        minimumGroupingDigits = other.minimumGroupingDigits;
        minimumIntegerDigits = other.minimumIntegerDigits;
        minimumSignificantDigits = other.minimumSignificantDigits;
        multiplier = other.multiplier;
        negativePrefix = other.negativePrefix;
        negativePrefixPattern = other.negativePrefixPattern;
        negativeSuffix = other.negativeSuffix;
        negativeSuffixPattern = other.negativeSuffixPattern;
        padPosition = other.padPosition;
        padString = other.padString;
        parseCaseSensitive = other.parseCaseSensitive;
        parseIntegerOnly = other.parseIntegerOnly;
        parseMode = other.parseMode;
        parseNoExponent = other.parseNoExponent;
        parseToBigDecimal = other.parseToBigDecimal;
        pluralRules = other.pluralRules;
        positivePrefix = other.positivePrefix;
        positivePrefixPattern = other.positivePrefixPattern;
        positiveSuffix = other.positiveSuffix;
        positiveSuffixPattern = other.positiveSuffixPattern;
        roundingIncrement = other.roundingIncrement;
        roundingMode = other.roundingMode;
        secondaryGroupingSize = other.secondaryGroupingSize;
        signAlwaysShown = other.signAlwaysShown;
        return this;
    }

    private boolean _equals(DecimalFormatProperties other) {
        boolean eq = true;
        eq = eq && _equalsHelper(compactCustomData, other.compactCustomData);
        eq = eq && _equalsHelper(compactStyle, other.compactStyle);
        eq = eq && _equalsHelper(currency, other.currency);
        eq = eq && _equalsHelper(currencyPluralInfo, other.currencyPluralInfo);
        eq = eq && _equalsHelper(currencyUsage, other.currencyUsage);
        eq = eq && _equalsHelper(decimalPatternMatchRequired, other.decimalPatternMatchRequired);
        eq = eq && _equalsHelper(decimalSeparatorAlwaysShown, other.decimalSeparatorAlwaysShown);
        eq = eq && _equalsHelper(exponentSignAlwaysShown, other.exponentSignAlwaysShown);
        eq = eq && _equalsHelper(formatWidth, other.formatWidth);
        eq = eq && _equalsHelper(groupingSize, other.groupingSize);
        eq = eq && _equalsHelper(groupingUsed, other.groupingUsed);
        eq = eq && _equalsHelper(magnitudeMultiplier, other.magnitudeMultiplier);
        eq = eq && _equalsHelper(mathContext, other.mathContext);
        eq = eq && _equalsHelper(maximumFractionDigits, other.maximumFractionDigits);
        eq = eq && _equalsHelper(maximumIntegerDigits, other.maximumIntegerDigits);
        eq = eq && _equalsHelper(maximumSignificantDigits, other.maximumSignificantDigits);
        eq = eq && _equalsHelper(minimumExponentDigits, other.minimumExponentDigits);
        eq = eq && _equalsHelper(minimumFractionDigits, other.minimumFractionDigits);
        eq = eq && _equalsHelper(minimumGroupingDigits, other.minimumGroupingDigits);
        eq = eq && _equalsHelper(minimumIntegerDigits, other.minimumIntegerDigits);
        eq = eq && _equalsHelper(minimumSignificantDigits, other.minimumSignificantDigits);
        eq = eq && _equalsHelper(multiplier, other.multiplier);
        eq = eq && _equalsHelper(negativePrefix, other.negativePrefix);
        eq = eq && _equalsHelper(negativePrefixPattern, other.negativePrefixPattern);
        eq = eq && _equalsHelper(negativeSuffix, other.negativeSuffix);
        eq = eq && _equalsHelper(negativeSuffixPattern, other.negativeSuffixPattern);
        eq = eq && _equalsHelper(padPosition, other.padPosition);
        eq = eq && _equalsHelper(padString, other.padString);
        eq = eq && _equalsHelper(parseCaseSensitive, other.parseCaseSensitive);
        eq = eq && _equalsHelper(parseIntegerOnly, other.parseIntegerOnly);
        eq = eq && _equalsHelper(parseMode, other.parseMode);
        eq = eq && _equalsHelper(parseNoExponent, other.parseNoExponent);
        eq = eq && _equalsHelper(parseToBigDecimal, other.parseToBigDecimal);
        eq = eq && _equalsHelper(pluralRules, other.pluralRules);
        eq = eq && _equalsHelper(positivePrefix, other.positivePrefix);
        eq = eq && _equalsHelper(positivePrefixPattern, other.positivePrefixPattern);
        eq = eq && _equalsHelper(positiveSuffix, other.positiveSuffix);
        eq = eq && _equalsHelper(positiveSuffixPattern, other.positiveSuffixPattern);
        eq = eq && _equalsHelper(roundingIncrement, other.roundingIncrement);
        eq = eq && _equalsHelper(roundingMode, other.roundingMode);
        eq = eq && _equalsHelper(secondaryGroupingSize, other.secondaryGroupingSize);
        eq = eq && _equalsHelper(signAlwaysShown, other.signAlwaysShown);
        return eq;
    }

    private boolean _equalsHelper(boolean mine, boolean theirs) {
        return mine == theirs;
    }

    private boolean _equalsHelper(int mine, int theirs) {
        return mine == theirs;
    }

    private boolean _equalsHelper(Object mine, Object theirs) {
        if (mine == theirs)
            return true;
        if (mine == null)
            return false;
        return mine.equals(theirs);
    }

    private int _hashCode() {
        int hashCode = 0;
        hashCode ^= _hashCodeHelper(compactCustomData);
        hashCode ^= _hashCodeHelper(compactStyle);
        hashCode ^= _hashCodeHelper(currency);
        hashCode ^= _hashCodeHelper(currencyPluralInfo);
        hashCode ^= _hashCodeHelper(currencyUsage);
        hashCode ^= _hashCodeHelper(decimalPatternMatchRequired);
        hashCode ^= _hashCodeHelper(decimalSeparatorAlwaysShown);
        hashCode ^= _hashCodeHelper(exponentSignAlwaysShown);
        hashCode ^= _hashCodeHelper(formatWidth);
        hashCode ^= _hashCodeHelper(groupingSize);
        hashCode ^= _hashCodeHelper(groupingUsed);
        hashCode ^= _hashCodeHelper(magnitudeMultiplier);
        hashCode ^= _hashCodeHelper(mathContext);
        hashCode ^= _hashCodeHelper(maximumFractionDigits);
        hashCode ^= _hashCodeHelper(maximumIntegerDigits);
        hashCode ^= _hashCodeHelper(maximumSignificantDigits);
        hashCode ^= _hashCodeHelper(minimumExponentDigits);
        hashCode ^= _hashCodeHelper(minimumFractionDigits);
        hashCode ^= _hashCodeHelper(minimumGroupingDigits);
        hashCode ^= _hashCodeHelper(minimumIntegerDigits);
        hashCode ^= _hashCodeHelper(minimumSignificantDigits);
        hashCode ^= _hashCodeHelper(multiplier);
        hashCode ^= _hashCodeHelper(negativePrefix);
        hashCode ^= _hashCodeHelper(negativePrefixPattern);
        hashCode ^= _hashCodeHelper(negativeSuffix);
        hashCode ^= _hashCodeHelper(negativeSuffixPattern);
        hashCode ^= _hashCodeHelper(padPosition);
        hashCode ^= _hashCodeHelper(padString);
        hashCode ^= _hashCodeHelper(parseCaseSensitive);
        hashCode ^= _hashCodeHelper(parseIntegerOnly);
        hashCode ^= _hashCodeHelper(parseMode);
        hashCode ^= _hashCodeHelper(parseNoExponent);
        hashCode ^= _hashCodeHelper(parseToBigDecimal);
        hashCode ^= _hashCodeHelper(pluralRules);
        hashCode ^= _hashCodeHelper(positivePrefix);
        hashCode ^= _hashCodeHelper(positivePrefixPattern);
        hashCode ^= _hashCodeHelper(positiveSuffix);
        hashCode ^= _hashCodeHelper(positiveSuffixPattern);
        hashCode ^= _hashCodeHelper(roundingIncrement);
        hashCode ^= _hashCodeHelper(roundingMode);
        hashCode ^= _hashCodeHelper(secondaryGroupingSize);
        hashCode ^= _hashCodeHelper(signAlwaysShown);
        return hashCode;
    }

    private int _hashCodeHelper(boolean value) {
        return value ? 1 : 0;
    }

    private int _hashCodeHelper(int value) {
        return value * 13;
    }

    private int _hashCodeHelper(Object value) {
        if (value == null)
            return 0;
        return value.hashCode();
    }

    public DecimalFormatProperties clear() {
        return _clear();
    }

    /** Creates and returns a shallow copy of the property bag. */
    @Override
    public DecimalFormatProperties clone() {
        // super.clone() returns a shallow copy.
        try {
            return (DecimalFormatProperties) super.clone();
        } catch (CloneNotSupportedException e) {
            // Should never happen since super is Object
            throw new UnsupportedOperationException(e);
        }
    }

    /**
     * Shallow-copies the properties from the given property bag into this property bag.
     *
     * @param other
     *            The property bag from which to copy and which will not be modified.
     * @return The current property bag (the one modified by this operation), for chaining.
     */
    public DecimalFormatProperties copyFrom(DecimalFormatProperties other) {
        return _copyFrom(other);
    }

    @Override
    public boolean equals(Object other) {
        if (other == null)
            return false;
        if (this == other)
            return true;
        if (!(other instanceof DecimalFormatProperties))
            return false;
        return _equals((DecimalFormatProperties) other);
    }

    /// BEGIN GETTERS/SETTERS ///

    public Map<String, Map<String, String>> getCompactCustomData() {
        return compactCustomData;
    }

    public CompactStyle getCompactStyle() {
        return compactStyle;
    }

    public Currency getCurrency() {
        return currency;
    }

    public CurrencyPluralInfo getCurrencyPluralInfo() {
        return currencyPluralInfo;
    }

    public CurrencyUsage getCurrencyUsage() {
        return currencyUsage;
    }

    public boolean getDecimalPatternMatchRequired() {
        return decimalPatternMatchRequired;
    }

    public boolean getDecimalSeparatorAlwaysShown() {
        return decimalSeparatorAlwaysShown;
    }

    public boolean getExponentSignAlwaysShown() {
        return exponentSignAlwaysShown;
    }

    public int getFormatWidth() {
        return formatWidth;
    }

    public int getGroupingSize() {
        return groupingSize;
    }

    public boolean getGroupingUsed() {
        return groupingUsed;
    }

    public int getMagnitudeMultiplier() {
        return magnitudeMultiplier;
    }

    public MathContext getMathContext() {
        return mathContext;
    }

    public int getMaximumFractionDigits() {
        return maximumFractionDigits;
    }

    public int getMaximumIntegerDigits() {
        return maximumIntegerDigits;
    }

    public int getMaximumSignificantDigits() {
        return maximumSignificantDigits;
    }

    public int getMinimumExponentDigits() {
        return minimumExponentDigits;
    }

    public int getMinimumFractionDigits() {
        return minimumFractionDigits;
    }

    public int getMinimumGroupingDigits() {
        return minimumGroupingDigits;
    }

    public int getMinimumIntegerDigits() {
        return minimumIntegerDigits;
    }

    public int getMinimumSignificantDigits() {
        return minimumSignificantDigits;
    }

    public BigDecimal getMultiplier() {
        return multiplier;
    }

    public String getNegativePrefix() {
        return negativePrefix;
    }

    public String getNegativePrefixPattern() {
        return negativePrefixPattern;
    }

    public String getNegativeSuffix() {
        return negativeSuffix;
    }

    public String getNegativeSuffixPattern() {
        return negativeSuffixPattern;
    }

    public PadPosition getPadPosition() {
        return padPosition;
    }

    public String getPadString() {
        return padString;
    }

    public boolean getParseCaseSensitive() {
        return parseCaseSensitive;
    }

    public boolean getParseIntegerOnly() {
        return parseIntegerOnly;
    }

    public ParseMode getParseMode() {
        return parseMode;
    }

    public boolean getParseNoExponent() {
        return parseNoExponent;
    }

    public boolean getParseToBigDecimal() {
        return parseToBigDecimal;
    }

    public PluralRules getPluralRules() {
        return pluralRules;
    }

    public String getPositivePrefix() {
        return positivePrefix;
    }

    public String getPositivePrefixPattern() {
        return positivePrefixPattern;
    }

    public String getPositiveSuffix() {
        return positiveSuffix;
    }

    public String getPositiveSuffixPattern() {
        return positiveSuffixPattern;
    }

    public BigDecimal getRoundingIncrement() {
        return roundingIncrement;
    }

    public RoundingMode getRoundingMode() {
        return roundingMode;
    }

    public int getSecondaryGroupingSize() {
        return secondaryGroupingSize;
    }

    public boolean getSignAlwaysShown() {
        return signAlwaysShown;
    }

    @Override
    public int hashCode() {
        return _hashCode();
    }

    /** Custom serialization: re-create object from serialized properties. */
    private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
        readObjectImpl(ois);
    }

    /* package-private */ void readObjectImpl(ObjectInputStream ois)
            throws IOException, ClassNotFoundException {
        ois.defaultReadObject();

        // Initialize to empty
        clear();

        // Extra int for possible future use
        ois.readInt();

        // 1) How many fields were serialized?
        int count = ois.readInt();

        // 2) Read each field by its name and value
        for (int i = 0; i < count; i++) {
            String name = (String) ois.readObject();
            Object value = ois.readObject();

            // Get the field reference
            Field field = null;
            try {
                field = DecimalFormatProperties.class.getDeclaredField(name);
            } catch (NoSuchFieldException e) {
                // The field name does not exist! Possibly corrupted serialization. Ignore this entry.
                continue;
            } catch (SecurityException e) {
                // Should not happen
                throw new AssertionError(e);
            }

            // NOTE: If the type of a field were changed in the future, this would be the place to check:
            // If the variable `value` is the old type, perform any conversions necessary.

            // Save value into the field
            try {
                field.set(this, value);
            } catch (IllegalArgumentException e) {
                // Should not happen
                throw new AssertionError(e);
            } catch (IllegalAccessException e) {
                // Should not happen
                throw new AssertionError(e);
            }
        }
    }

    /**
     * Specifies custom data to be used instead of CLDR data when constructing a CompactDecimalFormat.
     * The argument should be a map with the following structure:
     *
     * <pre>
     * {
     *   "1000": {
     *     "one": "0 thousand",
     *     "other": "0 thousand"
     *   },
     *   "10000": {
     *     "one": "00 thousand",
     *     "other": "00 thousand"
     *   },
     *   // ...
     * }
     * </pre>
     *
     * This API endpoint is used by the CLDR Survey Tool.
     *
     * @param compactCustomData
     *            A map with the above structure.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setCompactCustomData(
            Map<String, Map<String, String>> compactCustomData) {
        // TODO: compactCustomData is not immutable.
        this.compactCustomData = compactCustomData;
        return this;
    }

    /**
     * Use compact decimal formatting with the specified {@link CompactStyle}. CompactStyle.SHORT
     * produces output like "10K" in locale <em>en-US</em>, whereas CompactStyle.LONG produces output
     * like "10 thousand" in that locale.
     *
     * @param compactStyle
     *            The style of prefixes/suffixes to append.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setCompactStyle(CompactStyle compactStyle) {
        this.compactStyle = compactStyle;
        return this;
    }

    /**
     * Use the specified currency to substitute currency placeholders ('¤') in the pattern string.
     *
     * @param currency
     *            The currency.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setCurrency(Currency currency) {
        this.currency = currency;
        return this;
    }

    /**
     * Use the specified {@link CurrencyPluralInfo} instance when formatting currency long names.
     *
     * @param currencyPluralInfo
     *            The currency plural info object.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setCurrencyPluralInfo(CurrencyPluralInfo currencyPluralInfo) {
        // TODO: In order to maintain immutability, we have to perform a clone here.
        // It would be better to just retire CurrencyPluralInfo entirely.
        if (currencyPluralInfo != null) {
            currencyPluralInfo = (CurrencyPluralInfo) currencyPluralInfo.clone();
        }
        this.currencyPluralInfo = currencyPluralInfo;
        return this;
    }

    /**
     * Use the specified {@link CurrencyUsage} instance, which provides default rounding rules for the
     * currency in two styles, CurrencyUsage.CASH and CurrencyUsage.STANDARD.
     *
     * <p>
     * The CurrencyUsage specified here will not be used unless there is a currency placeholder in the
     * pattern.
     *
     * @param currencyUsage
     *            The currency usage. Defaults to CurrencyUsage.STANDARD.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setCurrencyUsage(CurrencyUsage currencyUsage) {
        this.currencyUsage = currencyUsage;
        return this;
    }

    /**
     * PARSING: Whether to require that the presence of decimal point matches the pattern. If a decimal
     * point is not present, but the pattern contained a decimal point, parse will not succeed: null will
     * be returned from <code>parse()</code>, and an error index will be set in the
     * {@link ParsePosition}.
     *
     * @param decimalPatternMatchRequired
     *            true to set an error if decimal is not present
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setDecimalPatternMatchRequired(boolean decimalPatternMatchRequired) {
        this.decimalPatternMatchRequired = decimalPatternMatchRequired;
        return this;
    }

    /**
     * Sets whether to always show the decimal point, even if the number doesn't require one. For
     * example, if always show decimal is true, the number 123 would be formatted as "123." in locale
     * <em>en-US</em>.
     *
     * @param alwaysShowDecimal
     *            Whether to show the decimal point when it is optional.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setDecimalSeparatorAlwaysShown(boolean alwaysShowDecimal) {
        this.decimalSeparatorAlwaysShown = alwaysShowDecimal;
        return this;
    }

    /**
     * Sets whether to show the plus sign in the exponent part of numbers with a zero or positive
     * exponent. For example, the number "1200" with the pattern "0.0E0" would be formatted as "1.2E+3"
     * instead of "1.2E3" in <em>en-US</em>.
     *
     * @param exponentSignAlwaysShown
     *            Whether to show the plus sign in positive exponents.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setExponentSignAlwaysShown(boolean exponentSignAlwaysShown) {
        this.exponentSignAlwaysShown = exponentSignAlwaysShown;
        return this;
    }

    /**
     * Sets the minimum width of the string output by the formatting pipeline. For example, if padding is
     * enabled and paddingWidth is set to 6, formatting the number "3.14159" with the pattern "0.00" will
     * result in "··3.14" if '·' is your padding string.
     *
     * <p>
     * If the number is longer than your padding width, the number will display as if no padding width
     * had been specified, which may result in strings longer than the padding width.
     *
     * <p>
     * Width is counted in UTF-16 code units.
     *
     * @param paddingWidth
     *            The output width.
     * @return The property bag, for chaining.
     * @see #setPadPosition
     * @see #setPadString
     */
    public DecimalFormatProperties setFormatWidth(int paddingWidth) {
        this.formatWidth = paddingWidth;
        return this;
    }

    /**
     * Sets the number of digits between grouping separators. For example, the <em>en-US</em> locale uses
     * a grouping size of 3, so the number 1234567 would be formatted as "1,234,567". For locales whose
     * grouping sizes vary with magnitude, see {@link #setSecondaryGroupingSize(int)}.
     *
     * @param groupingSize
     *            The primary grouping size.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setGroupingSize(int groupingSize) {
        this.groupingSize = groupingSize;
        return this;
    }

    /**
     * Sets whether to enable grouping when formatting.
     *
     * @param groupingUsed
     *            true to enable the display of grouping separators; false to disable.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setGroupingUsed(boolean groupingUsed) {
        this.groupingUsed = groupingUsed;
        return this;
    }

    /**
     * Multiply all numbers by this power of ten before formatting. Negative multipliers reduce the
     * magnitude and make numbers smaller (closer to zero).
     *
     * @param magnitudeMultiplier
     *            The number of powers of ten to scale.
     * @return The property bag, for chaining.
     * @see #setMultiplier
     */
    public DecimalFormatProperties setMagnitudeMultiplier(int magnitudeMultiplier) {
        this.magnitudeMultiplier = magnitudeMultiplier;
        return this;
    }

    /**
     * Sets the {@link MathContext} to be used during math and rounding operations. A MathContext
     * encapsulates a RoundingMode and the number of significant digits in the output.
     *
     * @param mathContext
     *            The math context to use when rounding is required.
     * @return The property bag, for chaining.
     * @see MathContext
     * @see #setRoundingMode
     */
    public DecimalFormatProperties setMathContext(MathContext mathContext) {
        this.mathContext = mathContext;
        return this;
    }

    /**
     * Sets the maximum number of digits to display after the decimal point. If the number has fewer than
     * this number of digits, the number will be rounded off using the rounding mode specified by
     * {@link #setRoundingMode(RoundingMode)}. The pattern "#00.0#", for example, corresponds to 2
     * maximum fraction digits, and the number 456.789 would be formatted as "456.79" in locale
     * <em>en-US</em> with the default rounding mode. Note that the number 456.999 would be formatted as
     * "457.0" given the same configurations.
     *
     * @param maximumFractionDigits
     *            The maximum number of fraction digits to output.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setMaximumFractionDigits(int maximumFractionDigits) {
        this.maximumFractionDigits = maximumFractionDigits;
        return this;
    }

    /**
     * Sets the maximum number of digits to display before the decimal point. If the number has more than
     * this number of digits, the extra digits will be truncated. For example, if maximum integer digits
     * is 2, and you attempt to format the number 1970, you will get "70" in locale <em>en-US</em>. It is
     * not possible to specify the maximum integer digits using a pattern string, except in the special
     * case of a scientific format pattern.
     *
     * @param maximumIntegerDigits
     *            The maximum number of integer digits to output.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setMaximumIntegerDigits(int maximumIntegerDigits) {
        this.maximumIntegerDigits = maximumIntegerDigits;
        return this;
    }

    /**
     * Sets the maximum number of significant digits to display. The number of significant digits is
     * equal to the number of digits counted from the leftmost nonzero digit through the rightmost
     * nonzero digit; for example, the number "2010" has 3 significant digits. If the number has more
     * significant digits than specified here, the extra significant digits will be rounded off using the
     * rounding mode specified by {@link #setRoundingMode(RoundingMode)}. For example, if maximum
     * significant digits is 3, the number 1234.56 will be formatted as "1230" in locale <em>en-US</em>
     * with the default rounding mode.
     *
     * <p>
     * If both maximum significant digits and maximum integer/fraction digits are set at the same time,
     * the behavior is undefined.
     *
     * <p>
     * The number of significant digits can be specified in a pattern string using the '@' character. For
     * example, the pattern "@@#" corresponds to a minimum of 2 and a maximum of 3 significant digits.
     *
     * @param maximumSignificantDigits
     *            The maximum number of significant digits to display.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setMaximumSignificantDigits(int maximumSignificantDigits) {
        this.maximumSignificantDigits = maximumSignificantDigits;
        return this;
    }

    /**
     * Sets the minimum number of digits to display in the exponent. For example, the number "1200" with
     * the pattern "0.0E00", which has 2 exponent digits, would be formatted as "1.2E03" in
     * <em>en-US</em>.
     *
     * @param minimumExponentDigits
     *            The minimum number of digits to display in the exponent field.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setMinimumExponentDigits(int minimumExponentDigits) {
        this.minimumExponentDigits = minimumExponentDigits;
        return this;
    }

    /**
     * Sets the minimum number of digits to display after the decimal point. If the number has fewer than
     * this number of digits, the number will be padded with zeros. The pattern "#00.0#", for example,
     * corresponds to 1 minimum fraction digit, and the number 456 would be formatted as "456.0" in
     * locale <em>en-US</em>.
     *
     * @param minimumFractionDigits
     *            The minimum number of fraction digits to output.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setMinimumFractionDigits(int minimumFractionDigits) {
        this.minimumFractionDigits = minimumFractionDigits;
        return this;
    }

    /**
     * Sets the minimum number of digits required to be beyond the first grouping separator in order to
     * enable grouping. For example, if the minimum grouping digits is 2, then 1234 would be formatted as
     * "1234" but 12345 would be formatted as "12,345" in <em>en-US</em>. Note that 1234567 would still
     * be formatted as "1,234,567", not "1234,567".
     *
     * @param minimumGroupingDigits
     *            How many digits must appear before a grouping separator before enabling grouping.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setMinimumGroupingDigits(int minimumGroupingDigits) {
        this.minimumGroupingDigits = minimumGroupingDigits;
        return this;
    }

    /**
     * Sets the minimum number of digits to display before the decimal point. If the number has fewer
     * than this number of digits, the number will be padded with zeros. The pattern "#00.0#", for
     * example, corresponds to 2 minimum integer digits, and the number 5.3 would be formatted as "05.3"
     * in locale <em>en-US</em>.
     *
     * @param minimumIntegerDigits
     *            The minimum number of integer digits to output.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setMinimumIntegerDigits(int minimumIntegerDigits) {
        this.minimumIntegerDigits = minimumIntegerDigits;
        return this;
    }

    /**
     * Sets the minimum number of significant digits to display. If, after rounding to the number of
     * significant digits specified by {@link #setMaximumSignificantDigits}, the number of remaining
     * significant digits is less than the minimum, the number will be padded with zeros. For example, if
     * minimum significant digits is 3, the number 5.8 will be formatted as "5.80" in locale
     * <em>en-US</em>. Note that minimum significant digits is relevant only when numbers have digits
     * after the decimal point.
     *
     * <p>
     * If both minimum significant digits and minimum integer/fraction digits are set at the same time,
     * both values will be respected, and the one that results in the greater number of padding zeros
     * will be used. For example, formatting the number 73 with 3 minimum significant digits and 2
     * minimum fraction digits will produce "73.00".
     *
     * <p>
     * The number of significant digits can be specified in a pattern string using the '@' character. For
     * example, the pattern "@@#" corresponds to a minimum of 2 and a maximum of 3 significant digits.
     *
     * @param minimumSignificantDigits
     *            The minimum number of significant digits to display.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setMinimumSignificantDigits(int minimumSignificantDigits) {
        this.minimumSignificantDigits = minimumSignificantDigits;
        return this;
    }

    /**
     * Multiply all numbers by this amount before formatting.
     *
     * @param multiplier
     *            The amount to multiply by.
     * @return The property bag, for chaining.
     * @see #setMagnitudeMultiplier
     */
    public DecimalFormatProperties setMultiplier(BigDecimal multiplier) {
        this.multiplier = multiplier;
        return this;
    }

    /**
     * Sets the prefix to prepend to negative numbers. The prefix will be interpreted literally. For
     * example, if you set a negative prefix of <code>n</code>, then the number -123 will be formatted as
     * "n123" in the locale <em>en-US</em>. Note that if the negative prefix is left unset, the locale's
     * minus sign is used.
     *
     * <p>
     * For more information on prefixes and suffixes, see {@link MutablePatternModifier}.
     *
     * @param negativePrefix
     *            The CharSequence to prepend to negative numbers.
     * @return The property bag, for chaining.
     * @see #setNegativePrefixPattern
     */
    public DecimalFormatProperties setNegativePrefix(String negativePrefix) {
        this.negativePrefix = negativePrefix;
        return this;
    }

    /**
     * Sets the prefix to prepend to negative numbers. Locale-specific symbols will be substituted into
     * the string according to Unicode Technical Standard #35 (LDML).
     *
     * <p>
     * For more information on prefixes and suffixes, see {@link MutablePatternModifier}.
     *
     * @param negativePrefixPattern
     *            The CharSequence to prepend to negative numbers after locale symbol substitutions take
     *            place.
     * @return The property bag, for chaining.
     * @see #setNegativePrefix
     */
    public DecimalFormatProperties setNegativePrefixPattern(String negativePrefixPattern) {
        this.negativePrefixPattern = negativePrefixPattern;
        return this;
    }

    /**
     * Sets the suffix to append to negative numbers. The suffix will be interpreted literally. For
     * example, if you set a suffix prefix of <code>n</code>, then the number -123 will be formatted as
     * "-123n" in the locale <em>en-US</em>. Note that the minus sign is prepended by default unless
     * otherwise specified in either the pattern string or in one of the {@link #setNegativePrefix}
     * methods.
     *
     * <p>
     * For more information on prefixes and suffixes, see {@link MutablePatternModifier}.
     *
     * @param negativeSuffix
     *            The CharSequence to append to negative numbers.
     * @return The property bag, for chaining.
     * @see #setNegativeSuffixPattern
     */
    public DecimalFormatProperties setNegativeSuffix(String negativeSuffix) {
        this.negativeSuffix = negativeSuffix;
        return this;
    }

    /**
     * Sets the suffix to append to negative numbers. Locale-specific symbols will be substituted into
     * the string according to Unicode Technical Standard #35 (LDML).
     *
     * <p>
     * For more information on prefixes and suffixes, see {@link MutablePatternModifier}.
     *
     * @param negativeSuffixPattern
     *            The CharSequence to append to negative numbers after locale symbol substitutions take
     *            place.
     * @return The property bag, for chaining.
     * @see #setNegativeSuffix
     */
    public DecimalFormatProperties setNegativeSuffixPattern(String negativeSuffixPattern) {
        this.negativeSuffixPattern = negativeSuffixPattern;
        return this;
    }

    /**
     * Sets the location where the padding string is to be inserted to maintain the padding width: one of
     * BEFORE_PREFIX, AFTER_PREFIX, BEFORE_SUFFIX, or AFTER_SUFFIX.
     *
     * <p>
     * Must be used in conjunction with {@link #setFormatWidth}.
     *
     * @param paddingLocation
     *            The output width.
     * @return The property bag, for chaining.
     * @see #setFormatWidth
     */
    public DecimalFormatProperties setPadPosition(PadPosition paddingLocation) {
        this.padPosition = paddingLocation;
        return this;
    }

    /**
     * Sets the string used for padding. The string should contain a single character or grapheme
     * cluster.
     *
     * <p>
     * Must be used in conjunction with {@link #setFormatWidth}.
     *
     * @param paddingString
     *            The padding string. Defaults to an ASCII space (U+0020).
     * @return The property bag, for chaining.
     * @see #setFormatWidth
     */
    public DecimalFormatProperties setPadString(String paddingString) {
        this.padString = paddingString;
        return this;
    }

    /**
     * Whether to require cases to match when parsing strings; default is true. Case sensitivity applies
     * to prefixes, suffixes, the exponent separator, the symbol "NaN", and the infinity symbol. Grouping
     * separators, decimal separators, and padding are always case-sensitive. Currencies are always
     * case-insensitive.
     *
     * <p>
     * This setting is ignored in fast mode. In fast mode, strings are always compared in a
     * case-sensitive way.
     *
     * @param parseCaseSensitive
     *            true to be case-sensitive when parsing; false to allow any case.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setParseCaseSensitive(boolean parseCaseSensitive) {
        this.parseCaseSensitive = parseCaseSensitive;
        return this;
    }

    /**
     * Whether to ignore the fractional part of numbers. For example, parses "123.4" to "123" instead of
     * "123.4".
     *
     * @param parseIntegerOnly
     *            true to parse integers only; false to parse integers with their fraction parts
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setParseIntegerOnly(boolean parseIntegerOnly) {
        this.parseIntegerOnly = parseIntegerOnly;
        return this;
    }

    /**
     * Controls certain rules for how strict this parser is when reading strings. See
     * {@link ParseMode#LENIENT} and {@link ParseMode#STRICT}.
     *
     * @param parseMode
     *            Either {@link ParseMode#LENIENT} or {@link ParseMode#STRICT}.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setParseMode(ParseMode parseMode) {
        this.parseMode = parseMode;
        return this;
    }

    /**
     * Whether to ignore the exponential part of numbers. For example, parses "123E4" to "123" instead of
     * "1230000".
     *
     * @param parseNoExponent
     *            true to ignore exponents; false to parse them.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setParseNoExponent(boolean parseNoExponent) {
        this.parseNoExponent = parseNoExponent;
        return this;
    }

    /**
     * Whether to always return a BigDecimal from parse methods. By default, a Long or a BigInteger are
     * returned when possible.
     *
     * @param parseToBigDecimal
     *            true to always return a BigDecimal; false to return a Long or a BigInteger when
     *            possible.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setParseToBigDecimal(boolean parseToBigDecimal) {
        this.parseToBigDecimal = parseToBigDecimal;
        return this;
    }

    /**
     * Sets the PluralRules object to use instead of the default for the locale.
     *
     * @param pluralRules
     *            The object to reference.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setPluralRules(PluralRules pluralRules) {
        this.pluralRules = pluralRules;
        return this;
    }

    /**
     * Sets the prefix to prepend to positive numbers. The prefix will be interpreted literally. For
     * example, if you set a positive prefix of <code>p</code>, then the number 123 will be formatted as
     * "p123" in the locale <em>en-US</em>.
     *
     * <p>
     * For more information on prefixes and suffixes, see {@link MutablePatternModifier}.
     *
     * @param positivePrefix
     *            The CharSequence to prepend to positive numbers.
     * @return The property bag, for chaining.
     * @see #setPositivePrefixPattern
     */
    public DecimalFormatProperties setPositivePrefix(String positivePrefix) {
        this.positivePrefix = positivePrefix;
        return this;
    }

    /**
     * Sets the prefix to prepend to positive numbers. Locale-specific symbols will be substituted into
     * the string according to Unicode Technical Standard #35 (LDML).
     *
     * <p>
     * For more information on prefixes and suffixes, see {@link MutablePatternModifier}.
     *
     * @param positivePrefixPattern
     *            The CharSequence to prepend to positive numbers after locale symbol substitutions take
     *            place.
     * @return The property bag, for chaining.
     * @see #setPositivePrefix
     */
    public DecimalFormatProperties setPositivePrefixPattern(String positivePrefixPattern) {
        this.positivePrefixPattern = positivePrefixPattern;
        return this;
    }

    /**
     * Sets the suffix to append to positive numbers. The suffix will be interpreted literally. For
     * example, if you set a positive suffix of <code>p</code>, then the number 123 will be formatted as
     * "123p" in the locale <em>en-US</em>.
     *
     * <p>
     * For more information on prefixes and suffixes, see {@link MutablePatternModifier}.
     *
     * @param positiveSuffix
     *            The CharSequence to append to positive numbers.
     * @return The property bag, for chaining.
     * @see #setPositiveSuffixPattern
     */
    public DecimalFormatProperties setPositiveSuffix(String positiveSuffix) {
        this.positiveSuffix = positiveSuffix;
        return this;
    }

    /**
     * Sets the suffix to append to positive numbers. Locale-specific symbols will be substituted into
     * the string according to Unicode Technical Standard #35 (LDML).
     *
     * <p>
     * For more information on prefixes and suffixes, see {@link MutablePatternModifier}.
     *
     * @param positiveSuffixPattern
     *            The CharSequence to append to positive numbers after locale symbol substitutions take
     *            place.
     * @return The property bag, for chaining.
     * @see #setPositiveSuffix
     */
    public DecimalFormatProperties setPositiveSuffixPattern(String positiveSuffixPattern) {
        this.positiveSuffixPattern = positiveSuffixPattern;
        return this;
    }

    /**
     * Sets the increment to which to round numbers. For example, with a rounding interval of 0.05, the
     * number 11.17 would be formatted as "11.15" in locale <em>en-US</em> with the default rounding
     * mode.
     *
     * <p>
     * You can use either a rounding increment or significant digits, but not both at the same time.
     *
     * <p>
     * The rounding increment can be specified in a pattern string. For example, the pattern "#,##0.05"
     * corresponds to a rounding interval of 0.05 with 1 minimum integer digit and a grouping size of 3.
     *
     * @param roundingIncrement
     *            The interval to which to round.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setRoundingIncrement(BigDecimal roundingIncrement) {
        this.roundingIncrement = roundingIncrement;
        return this;
    }

    /**
     * Sets the rounding mode, which determines under which conditions extra decimal places are rounded
     * either up or down. See {@link RoundingMode} for details on the choices of rounding mode. The
     * default if not set explicitly is {@link RoundingMode#HALF_EVEN}.
     *
     * <p>
     * This setting is ignored if {@link #setMathContext} is used.
     *
     * @param roundingMode
     *            The rounding mode to use when rounding is required.
     * @return The property bag, for chaining.
     * @see RoundingMode
     * @see #setMathContext
     */
    public DecimalFormatProperties setRoundingMode(RoundingMode roundingMode) {
        this.roundingMode = roundingMode;
        return this;
    }

    /**
     * Sets the number of digits between grouping separators higher than the least-significant grouping
     * separator. For example, the locale <em>hi</em> uses a primary grouping size of 3 and a secondary
     * grouping size of 2, so the number 1234567 would be formatted as "12,34,567".
     *
     * <p>
     * The two levels of grouping separators can be specified in the pattern string. For example, the
     * <em>hi</em> locale's default decimal format pattern is "#,##,##0.###".
     *
     * @param secondaryGroupingSize
     *            The secondary grouping size.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setSecondaryGroupingSize(int secondaryGroupingSize) {
        this.secondaryGroupingSize = secondaryGroupingSize;
        return this;
    }

    /**
     * Sets whether to always display of a plus sign on positive numbers.
     *
     * <p>
     * If the location of the negative sign is specified by the decimal format pattern (or by the
     * negative prefix/suffix pattern methods), a plus sign is substituted into that location, in
     * accordance with Unicode Technical Standard #35 (LDML) section 3.2.1. Otherwise, the plus sign is
     * prepended to the number. For example, if the decimal format pattern <code>#;#-</code> is used,
     * then formatting 123 would result in "123+" in the locale <em>en-US</em>.
     *
     * <p>
     * This method should be used <em>instead of</em> setting the positive prefix/suffix. The behavior is
     * undefined if alwaysShowPlusSign is set but the positive prefix/suffix already contains a plus
     * sign.
     *
     * @param signAlwaysShown
     *            Whether positive numbers should display a plus sign.
     * @return The property bag, for chaining.
     */
    public DecimalFormatProperties setSignAlwaysShown(boolean signAlwaysShown) {
        this.signAlwaysShown = signAlwaysShown;
        return this;
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        result.append("<Properties");
        toStringBare(result);
        result.append(">");
        return result.toString();
    }

    /**
     * Appends a string containing properties that differ from the default, but without being surrounded
     * by &lt;Properties&gt;.
     */
    public void toStringBare(StringBuilder result) {
        Field[] fields = DecimalFormatProperties.class.getDeclaredFields();
        for (Field field : fields) {
            Object myValue, defaultValue;
            try {
                myValue = field.get(this);
                defaultValue = field.get(DEFAULT);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
                continue;
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                continue;
            }
            if (myValue == null && defaultValue == null) {
                continue;
            } else if (myValue == null || defaultValue == null) {
                result.append(" " + field.getName() + ":" + myValue);
            } else if (!myValue.equals(defaultValue)) {
                result.append(" " + field.getName() + ":" + myValue);
            }
        }
    }

    /**
     * Custom serialization: save fields along with their name, so that fields can be easily added in the
     * future in any order. Only save fields that differ from their default value.
     */
    private void writeObject(ObjectOutputStream oos) throws IOException {
        writeObjectImpl(oos);
    }

    /* package-private */ void writeObjectImpl(ObjectOutputStream oos) throws IOException {
        oos.defaultWriteObject();

        // Extra int for possible future use
        oos.writeInt(0);

        ArrayList<Field> fieldsToSerialize = new ArrayList<Field>();
        ArrayList<Object> valuesToSerialize = new ArrayList<Object>();
        Field[] fields = DecimalFormatProperties.class.getDeclaredFields();
        for (Field field : fields) {
            if (Modifier.isStatic(field.getModifiers())) {
                continue;
            }
            try {
                Object myValue = field.get(this);
                if (myValue == null) {
                    // All *Object* values default to null; no need to serialize.
                    continue;
                }
                Object defaultValue = field.get(DEFAULT);
                if (!myValue.equals(defaultValue)) {
                    fieldsToSerialize.add(field);
                    valuesToSerialize.add(myValue);
                }
            } catch (IllegalArgumentException e) {
                // Should not happen
                throw new AssertionError(e);
            } catch (IllegalAccessException e) {
                // Should not happen
                throw new AssertionError(e);
            }
        }

        // 1) How many fields are to be serialized?
        int count = fieldsToSerialize.size();
        oos.writeInt(count);

        // 2) Write each field with its name and value
        for (int i = 0; i < count; i++) {
            Field field = fieldsToSerialize.get(i);
            Object value = valuesToSerialize.get(i);
            oos.writeObject(field.getName());
            oos.writeObject(value);
        }
    }
}