• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

javadev / moneytostr-russian / #338

pending completion
#338

push

web-flow
Update pom.xml

258 of 258 relevant lines covered (100.0%)

1.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
src/main/java/com/github/moneytostr/MoneyToStr.java
1
/*
2
 * $Id$
3
 *
4
 * Copyright 2014 Valentyn Kolesnikov
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
package com.github.moneytostr;
19

20
/**
21
 * Converts numbers to symbols.
22
 *
23
 * @author Valentyn Kolesnikov
24
 * @version $Revision$ $Date$
25
 */
26
public class MoneyToStr {
27
    private static final int INDEX_3 = 3;
28
    private static final int INDEX_2 = 2;
29
    private static final int INDEX_1 = 1;
30
    private static final int INDEX_0 = 0;
31
    private static org.w3c.dom.Document xmlDoc;
32
    private static final int NUM0 = 0;
33
    private static final int NUM1 = 1;
34
    private static final int NUM2 = 2;
35
    private static final int NUM3 = 3;
36
    private static final int NUM4 = 4;
37
    private static final int NUM5 = 5;
38
    private static final int NUM6 = 6;
39
    private static final int NUM7 = 7;
40
    private static final int NUM8 = 8;
41
    private static final int NUM9 = 9;
42
    private static final int NUM10 = 10;
43
    private static final int NUM11 = 11;
44
    private static final int NUM14 = 14;
45
    private static final int NUM100 = 100;
46
    private static final int NUM1000 = 1000;
47
    private static final int NUM10000 = 10000;
48
    private static final String CURRENCY_LIST =
49
            "<CurrencyList>\n"
50
                    + " \n"
51
                    + " <language value=\"UKR\"/>\n"
52
                    + " <UKR>\n"
53
                    + " <item value=\"minus\" text=\"\u043C\u0456\u043D\u0443\u0441\"/>\n"
54
                    + " <item value=\"0\" text=\"\u043d\u0443\u043b\u044c\"/>\n"
55
                    + " <item value=\"1000_10\" text=\"\u0442\u0438\u0441\u044f\u0447,\u043c\u0456\u043b\u044c\u0439\u043e\u043d\u0456\u0432,\u043c\u0456\u043b\u044c\u044f\u0440\u0434\u0456\u0432,\u0442\u0440\u0438\u043b\u044c\u0439\u043e\u043d\u0456\u0432\"/>\n"
56
                    + " <item value=\"1000_1\" text=\"\u0442\u0438\u0441\u044f\u0447\u0430,\u043c\u0456\u043b\u044c\u0439\u043e\u043d,\u043c\u0456\u043b\u044c\u044f\u0440\u0434,\u0442\u0440\u0438\u043b\u044c\u0439\u043e\u043d\"/>\n"
57
                    + " <item value=\"1000_234\" text=\"\u0442\u0438\u0441\u044f\u0447\u0456,\u043c\u0456\u043b\u044c\u0439\u043e\u043d\u0430,\u043c\u0456\u043b\u044c\u044f\u0440\u0434\u0430,\u0442\u0440\u0438\u043b\u044c\u0439\u043e\u043d\u0430\"/>\n"
58
                    + " <item value=\"1000_5\" text=\"\u0442\u0438\u0441\u044f\u0447,\u043c\u0456\u043b\u044c\u0439\u043e\u043d\u0456\u0432,\u043c\u0456\u043b\u044c\u044f\u0440\u0434\u0456\u0432,\u0442\u0440\u0438\u043b\u044c\u0439\u043e\u043d\u0456\u0432\"/>\n"
59
                    + " <item value=\"10_19\" text=\"\u0434\u0435\u0441\u044f\u0442\u044c,\u043e\u0434\u0438\u043d\u0430\u0434\u0446\u044f\u0442\u044c,\u0434\u0432\u0430\u043d\u0430\u0434\u0446\u044f\u0442\u044c,\u0442\u0440\u0438\u043d\u0430\u0434\u0446\u044f\u0442\u044c,\u0447\u043e\u0442\u0438\u0440\u043d\u0430\u0434\u0446\u044f\u0442\u044c,\u043f\u2019\u044f\u0442\u043d\u0430\u0434\u0446\u044f\u0442\u044c,\u0448\u0456\u0441\u0442\u043d\u0430\u0434\u0446\u044f\u0442\u044c,\u0441\u0456\u043c\u043d\u0430\u0434\u0446\u044f\u0442\u044c,\u0432\u0456\u0441\u0456\u043c\u043d\u0430\u0434\u0446\u044f\u0442\u044c,\u0434\u0435\u0432\u2019\u044f\u0442\u043d\u0430\u0434\u0446\u044f\u0442\u044c\"/>\n"
60
                    + " <item value=\"1\" text=\"\u043e\u0434\u043d\u0430,\u043e\u0434\u0438\u043d,\u043e\u0434\u0438\u043d,\u043e\u0434\u043d\u0430\"/>\n"
61
                    + " <item value=\"2\" text=\"\u0434\u0432\u0456,\u0434\u0432\u0430,\u0434\u0432\u0430,\u0434\u0432\u0456\"/>\n"
62
                    + " <item value=\"3_9\" text=\"\u0442\u0440\u0438,\u0447\u043e\u0442\u0438\u0440\u0438,\u043f\u2019\u044f\u0442\u044c,\u0448\u0456\u0441\u0442\u044c,\u0441\u0456\u043c,\u0432\u0456\u0441\u0456\u043c,\u0434\u0435\u0432\u2019\u044f\u0442\u044c\"/>\n"
63
                    + " <item value=\"100_900\" text=\"\u0441\u0442\u043e ,\u0434\u0432\u0456\u0441\u0442\u0456 ,\u0442\u0440\u0438\u0441\u0442\u0430 ,\u0447\u043e\u0442\u0438\u0440\u0438\u0441\u0442\u0430 ,\u043f\u2019\u044f\u0442\u0441\u043e\u0442 ,\u0448\u0456\u0441\u0442\u0441\u043e\u0442 ,\u0441\u0456\u043c\u0441\u043e\u0442 ,\u0432\u0456\u0441\u0456\u043c\u0441\u043e\u0442 ,\u0434\u0435\u0432\u2019\u044f\u0442\u0441\u043e\u0442 \"/>\n"
64
                    + " <item value=\"20_90\" text=\"\u0434\u0432\u0430\u0434\u0446\u044f\u0442\u044c ,\u0442\u0440\u0438\u0434\u0446\u044f\u0442\u044c ,\u0441\u043e\u0440\u043e\u043a ,\u043f\u2019\u044f\u0442\u0434\u0435\u0441\u044f\u0442 ,\u0448\u0456\u0441\u0442\u0434\u0435\u0441\u044f\u0442 ,\u0441\u0456\u043c\u0434\u0435\u0441\u044f\u0442 ,\u0432\u0456\u0441\u0456\u043c\u0434\u0435\u0441\u044f\u0442 ,\u0434\u0435\u0432\u2019\u044f\u043d\u043e\u0441\u0442\u043e \"/>\n"
65
                    + " <item value=\"pdv\" text=\"\u0432 \u0442.\u0447. \u041f\u0414\u0412 \"/>\n"
66
                    + " <item value=\"pdv_value\" text=\"20\"/>\n"
67
                    + " </UKR>\n"
68
                    + " <RUS>\n"
69
                    + " <item value=\"minus\" text=\"\u043C\u0438\u043D\u0443\u0441\"/>\n"
70
                    + " <item value=\"0\" text=\"\u043d\u043e\u043b\u044c\"/>\n"
71
                    + " <item value=\"1000_10\" text=\"\u0442\u044b\u0441\u044f\u0447,\u043c\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432,\u043c\u0438\u043b\u043b\u0438\u0430\u0440\u0434\u043e\u0432,\u0442\u0440\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432\"/>\n"
72
                    + " <item value=\"1000_1\" text=\"\u0442\u044b\u0441\u044f\u0447\u0430,\u043c\u0438\u043b\u043b\u0438\u043e\u043d,\u043c\u0438\u043b\u043b\u0438\u0430\u0440\u0434,\u0442\u0440\u0438\u043b\u043b\u0438\u043e\u043d\"/>\n"
73
                    + " <item value=\"1000_234\" text=\"\u0442\u044b\u0441\u044f\u0447\u0438,\u043c\u0438\u043b\u043b\u0438\u043e\u043d\u0430,\u043c\u0438\u043b\u043b\u0438\u0430\u0440\u0434\u0430,\u0442\u0440\u0438\u043b\u043b\u0438\u043e\u043d\u0430\"/>\n"
74
                    + " <item value=\"1000_5\" text=\"\u0442\u044b\u0441\u044f\u0447,\u043c\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432,\u043c\u0438\u043b\u043b\u0438\u0430\u0440\u0434\u043e\u0432,\u0442\u0440\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432\"/>\n"
75
                    + " <item value=\"10_19\" text=\"\u0434\u0435\u0441\u044f\u0442\u044c,\u043e\u0434\u0438\u043d\u043d\u0430\u0434\u0446\u0430\u0442\u044c,\u0434\u0432\u0435\u043d\u0430\u0434\u0446\u0430\u0442\u044c,\u0442\u0440\u0438\u043d\u0430\u0434\u0446\u0430\u0442\u044c,\u0447\u0435\u0442\u044b\u0440\u043d\u0430\u0434\u0446\u0430\u0442\u044c,\u043f\u044f\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u044c,\u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u044c,\u0441\u0435\u043c\u043d\u0430\u0434\u0446\u0430\u0442\u044c,\u0432\u043e\u0441\u0435\u043c\u043d\u0430\u0434\u0446\u0430\u0442\u044c,\u0434\u0435\u0432\u044f\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u044c\"/>\n"
76
                    + " <item value=\"1\" text=\"\u043e\u0434\u043d\u0430,\u043e\u0434\u0438\u043d,\u043e\u0434\u0438\u043d,\u043e\u0434\u043d\u0430\"/>\n"
77
                    + " <item value=\"2\" text=\"\u0434\u0432\u0435,\u0434\u0432\u0430,\u0434\u0432\u0430,\u0434\u0432\u0435\"/>\n"
78
                    + " <item value=\"3_9\" text=\"\u0442\u0440\u0438,\u0447\u0435\u0442\u044b\u0440\u0435,\u043f\u044f\u0442\u044c,\u0448\u0435\u0441\u0442\u044c,\u0441\u0435\u043c\u044c,\u0432\u043e\u0441\u0435\u043c\u044c,\u0434\u0435\u0432\u044f\u0442\u044c\"/>\n"
79
                    + " <item value=\"100_900\" text=\"\u0441\u0442\u043e ,\u0434\u0432\u0435\u0441\u0442\u0438 ,\u0442\u0440\u0438\u0441\u0442\u0430 ,\u0447\u0435\u0442\u044b\u0440\u0435\u0441\u0442\u0430 ,\u043f\u044f\u0442\u044c\u0441\u043e\u0442 ,\u0448\u0435\u0441\u0442\u044c\u0441\u043e\u0442 ,\u0441\u0435\u043c\u044c\u0441\u043e\u0442 ,\u0432\u043e\u0441\u0435\u043c\u044c\u0441\u043e\u0442 ,\u0434\u0435\u0432\u044f\u0442\u044c\u0441\u043e\u0442 \"/>\n"
80
                    + " <item value=\"20_90\" text=\"\u0434\u0432\u0430\u0434\u0446\u0430\u0442\u044c ,\u0442\u0440\u0438\u0434\u0446\u0430\u0442\u044c ,\u0441\u043e\u0440\u043e\u043a ,\u043f\u044f\u0442\u044c\u0434\u0435\u0441\u044f\u0442 ,\u0448\u0435\u0441\u0442\u044c\u0434\u0435\u0441\u044f\u0442 ,\u0441\u0435\u043c\u044c\u0434\u0435\u0441\u044f\u0442 ,\u0432\u043e\u0441\u0435\u043c\u044c\u0434\u0435\u0441\u044f\u0442 ,\u0434\u0435\u0432\u044f\u043d\u043e\u0441\u0442\u043e \"/>\n"
81
                    + " <item value=\"pdv\" text=\"\u0432 \u0442.\u0447. \u041d\u0414\u0421 \"/>\n"
82
                    + " <item value=\"pdv_value\" text=\"18\"/>\n"
83
                    + " </RUS>\n"
84
                    + " <ENG>\n"
85
                    + " <item value=\"minus\" text=\"minus\"/>\n"
86
                    + " <item value=\"0\" text=\"zero\"/>\n"
87
                    + " <item value=\"1000_10\" text=\"thousand,million,billion,trillion\"/>\n"
88
                    + " <item value=\"1000_1\" text=\"thousand,million,billion,trillion\"/>\n"
89
                    + " <item value=\"1000_234\" text=\"thousand,million,billion,trillion\"/>\n"
90
                    + " <item value=\"1000_5\" text=\"thousand,million,billion,trillion\"/>\n"
91
                    + " <item value=\"10_19\" text=\"ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen\"/>\n"
92
                    + " <item value=\"1\" text=\"one,one,one,one\"/>\n"
93
                    + " <item value=\"2\" text=\"two,two,two,two\"/>\n"
94
                    + " <item value=\"3_9\" text=\"three,four,five,six,seven,eight,nine\"/>\n"
95
                    + " <item value=\"100_900\" text=\"one hundred ,two hundred ,three hundred ,four hundred ,five hundred ,six hundred ,seven hundred ,eight hundred ,nine hundred \"/>\n"
96
                    + " <item value=\"20_90\" text=\"twenty-,thirty-,forty-,fifty-,sixty-,seventy-,eighty-,ninety-\"/>\n"
97
                    + " <item value=\"pdv\" text=\"including VAT \"/>\n"
98
                    + " <item value=\"pdv_value\" text=\"10\"/>\n"
99
                    + " </ENG>\n"
100
                    + "\n"
101
                    + " <RUR CurrID=\"810\" CurrName=\"\u0420\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u0438\u0435 \u0440\u0443\u0431\u043b\u0438\" language=\"RUS\"\n"
102
                    + " RubOneUnit=\"\u0440\u0443\u0431\u043b\u044c\" RubTwoUnit=\"\u0440\u0443\u0431\u043b\u044f\" RubFiveUnit=\"\u0440\u0443\u0431\u043b\u0435\u0439\" RubSex=\"M\" RubShortUnit=\"\u0440\u0443\u0431.\"\n"
103
                    + " KopOneUnit=\"\u043a\u043e\u043f\u0435\u0439\u043a\u0430\" KopTwoUnit=\"\u043a\u043e\u043f\u0435\u0439\u043a\u0438\" KopFiveUnit=\"\u043a\u043e\u043f\u0435\u0435\u043a\" KopSex=\"F\"\n"
104
                    + " />\n"
105
                    + " <UAH CurrID=\"980\" CurrName=\"\u0423\u043a\u0440\u0430\u0438\u043d\u0441\u043a\u0456 \u0433\u0440\u0438\u0432\u043d\u0456\" language=\"RUS\"\n"
106
                    + " RubOneUnit=\"\u0433\u0440\u0438\u0432\u043d\u044f\" RubTwoUnit=\"\u0433\u0440\u0438\u0432\u043d\u0438\" RubFiveUnit=\"\u0433\u0440\u0438\u0432\u0435\u043d\u044c\" RubSex=\"F\" RubShortUnit=\"\u0433\u0440\u043d.\"\n"
107
                    + " KopOneUnit=\"\u043a\u043e\u043f\u0435\u0439\u043a\u0430\" KopTwoUnit=\"\u043a\u043e\u043f\u0435\u0439\u043a\u0438\" KopFiveUnit=\"\u043a\u043e\u043f\u0435\u0435\u043a\" KopSex=\"F\"\n"
108
                    + " />\n"
109
                    + " <USD CurrID=\"840\" CurrName=\"\u0414\u043e\u043b\u0430\u0440\u0438 \u0421\u0428\u0410\" language=\"RUS\"\n"
110
                    + " RubOneUnit=\"\u0434\u043e\u043b\u043b\u0430\u0440\" RubTwoUnit=\"\u0434\u043e\u043b\u043b\u0430\u0440\u0430\" RubFiveUnit=\"\u0434\u043e\u043b\u043b\u0430\u0440\u043e\u0432\" RubSex=\"M\" RubShortUnit=\"\u0434\u043e\u043b.\"\n"
111
                    + " KopOneUnit=\"\u0446\u0435\u043d\u0442\" KopTwoUnit=\"\u0446\u0435\u043d\u0442\u0430\" KopFiveUnit=\"\u0446\u0435\u043d\u0442\u043e\u0432\" KopSex=\"M\"\n"
112
                    + " />\n"
113
                    + " <EUR CurrID=\"840\" CurrName=\"\u0415\u0432\u0440\u043E \u0415\u0421\" language=\"RUS\""
114
                    + " RubOneUnit=\"\u0435\u0432\u0440\u043E\" RubTwoUnit=\"\u0435\u0432\u0440\u043E\" RubFiveUnit=\"\u0435\u0432\u0440\u043E\" RubSex=\"M\" RubShortUnit=\"\u0435\u0432\u0440.\""
115
                    + " KopOneUnit=\"\u0446\u0435\u043D\u0442\" KopTwoUnit=\"\u0446\u0435\u043D\u0442\u0430\" KopFiveUnit=\"\u0446\u0435\u043D\u0442\u043E\u0432\" KopSex=\"M\" />"
116
                    + "\n"
117
                    + " <RUR CurrID=\"810\" CurrName=\"\u0420\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u0438\u0435 \u0440\u0443\u0431\u043b\u0438\" language=\"UKR\"\n"
118
                    + " RubOneUnit=\"\u0440\u0443\u0431\u043b\u044c\" RubTwoUnit=\"\u0440\u0443\u0431\u043b\u0456\" RubFiveUnit=\"\u0440\u0443\u0431\u043b\u0456\u0432\" RubSex=\"M\" RubShortUnit=\"\u0440\u0443\u0431.\"\n"
119
                    + " KopOneUnit=\"\u043a\u043e\u043f\u0456\u0439\u043a\u0430\" KopTwoUnit=\"\u043a\u043e\u043f\u0456\u0439\u043a\u0438\" KopFiveUnit=\"\u043a\u043e\u043f\u0456\u0439\u043e\u043a\" KopSex=\"F\"\n"
120
                    + " /> \n"
121
                    + " <UAH CurrID=\"980\" CurrName=\"\u0423\u043a\u0440\u0430\u0438\u043d\u0441\u043a\u0456 \u0433\u0440\u0438\u0432\u043d\u0456\" language=\"UKR\"\n"
122
                    + " RubOneUnit=\"\u0433\u0440\u0438\u0432\u043d\u044f\" RubTwoUnit=\"\u0433\u0440\u0438\u0432\u043d\u0456\" RubFiveUnit=\"\u0433\u0440\u0438\u0432\u0435\u043d\u044c\" RubSex=\"F\" RubShortUnit=\"\u0433\u0440\u043d.\"\n"
123
                    + " KopOneUnit=\"\u043a\u043e\u043f\u0456\u0439\u043a\u0430\" KopTwoUnit=\"\u043a\u043e\u043f\u0456\u0439\u043a\u0438\" KopFiveUnit=\"\u043a\u043e\u043f\u0456\u0439\u043e\u043a\" KopSex=\"F\"\n"
124
                    + " />\n"
125
                    + " <USD CurrID=\"840\" CurrName=\"\u0414\u043e\u043b\u0430\u0440\u0438 \u0421\u0428\u0410\" language=\"UKR\"\n"
126
                    + " RubOneUnit=\"\u0434\u043e\u043b\u0430\u0440\" RubTwoUnit=\"\u0434\u043e\u043b\u0430\u0440\u0430\" RubFiveUnit=\"\u0434\u043e\u043b\u0430\u0440\u0456\u0432\" RubSex=\"M\" RubShortUnit=\"\u0434\u043e\u043b.\"\n"
127
                    + " KopOneUnit=\"\u0446\u0435\u043d\u0442\" KopTwoUnit=\"\u0446\u0435\u043d\u0442\u0430\" KopFiveUnit=\"\u0446\u0435\u043d\u0442\u0456\u0432\" KopSex=\"M\"\n"
128
                    + " />\n"
129
                    + " <EUR CurrID=\"840\" CurrName=\"\u0415\u0432\u0440\u043E \u0415\u0421\" language=\"UKR\""
130
                    + " RubOneUnit=\"\u0454\u0432\u0440\u043E\" RubTwoUnit=\"\u0454\u0432\u0440\u043E\" RubFiveUnit=\"\u0454\u0432\u0440\u043E\" RubSex=\"M\" RubShortUnit=\"\u0454\u0432\u0440.\""
131
                    + " KopOneUnit=\"\u0446\u0435\u043D\u0442\" KopTwoUnit=\"\u0446\u0435\u043D\u0442\u0430\" KopFiveUnit=\"\u0446\u0435\u043D\u0442\u0456\u0432\" KopSex=\"M\" />"
132
                    + "\n"
133
                    + " <RUR CurrID=\"810\" CurrName=\"\u0420\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u0438\u0435 \u0440\u0443\u0431\u043b\u0438\" language=\"ENG\"\n"
134
                    + " RubOneUnit=\"ruble\" RubTwoUnit=\"rubles\" RubFiveUnit=\"rubles\" RubSex=\"M\" RubShortUnit=\"RUR.\"\n"
135
                    + " KopOneUnit=\"kopeck\" KopTwoUnit=\"kopecks\" KopFiveUnit=\"kopecks\" KopSex=\"M\"\n"
136
                    + " /> \n"
137
                    + " <UAH CurrID=\"980\" CurrName=\"\u0423\u043a\u0440\u0430\u0438\u043d\u0441\u043a\u0456 \u0433\u0440\u0438\u0432\u043d\u0456\" language=\"ENG\"\n"
138
                    + " RubOneUnit=\"hryvnia\" RubTwoUnit=\"hryvnias\" RubFiveUnit=\"hryvnias\" RubSex=\"M\" RubShortUnit=\"UAH.\"\n"
139
                    + " KopOneUnit=\"kopeck\" KopTwoUnit=\"kopecks\" KopFiveUnit=\"kopecks\" KopSex=\"M\"\n"
140
                    + " />\n"
141
                    + " <USD CurrID=\"840\" CurrName=\"\u0414\u043e\u043b\u0430\u0440\u0438 \u0421\u0428\u0410\" language=\"ENG\"\n"
142
                    + " RubOneUnit=\"dollar\" RubTwoUnit=\"dollars\" RubFiveUnit=\"dollars\" RubSex=\"M\" RubShortUnit=\"USD.\"\n"
143
                    + " KopOneUnit=\"cent\" KopTwoUnit=\"cents\" KopFiveUnit=\"cents\" KopSex=\"M\"\n"
144
                    + " />\n"
145
                    + " <EUR CurrID=\"840\" CurrName=\"\u0415\u0432\u0440\u043E \u0415\u0421\" language=\"ENG\""
146
                    + " RubOneUnit=\"euro\" RubTwoUnit=\"euros\" RubFiveUnit=\"euros\" RubSex=\"M\" RubShortUnit=\"EUR.\""
147
                    + " KopOneUnit=\"cent\" KopTwoUnit=\"cents\" KopFiveUnit=\"cents\" KopSex=\"M\" />"
148
                    + "\n"
149
                    + " <PER10 CurrID=\"556\" CurrName=\"\u0412i\u0434\u0441\u043e\u0442\u043a\u0438 \u0437 \u0434\u0435\u0441\u044f\u0442\u0438\u043c\u0438 \u0447\u0430\u0441\u0442\u0438\u043d\u0430\u043c\u0438\" language=\"RUS\"\n"
150
                    + " RubOneUnit=\"\u0446\u0435\u043b\u0430\u044f,\" RubTwoUnit=\"\u0446\u0435\u043b\u044b\u0445,\" RubFiveUnit=\"\u0446\u0435\u043b\u044b\u0445,\" RubSex=\"F\"\n"
151
                    + " KopOneUnit=\"\u0434\u0435\u0441\u044f\u0442\u0430\u044f \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430\" KopTwoUnit=\"\u0434\u0435\u0441\u044f\u0442\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430\" KopFiveUnit=\"\u0434\u0435\u0441\u044f\u0442\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430\" KopSex=\"F\"\n"
152
                    + " />\n"
153
                    + "\n"
154
                    + " <PER100 CurrID=\"557\" CurrName=\"\u0412i\u0434\u0441\u043e\u0442\u043a\u0438 \u0437 \u0441\u043e\u0442\u0438\u043c\u0438 \u0447\u0430\u0441\u0442\u0438\u043d\u0430\u043c\u0438\" language=\"RUS\"\n"
155
                    + " RubOneUnit=\"\u0446\u0435\u043b\u0430\u044f,\" RubTwoUnit=\"\u0446\u0435\u043b\u044b\u0445,\" RubFiveUnit=\"\u0446\u0435\u043b\u044b\u0445,\" RubSex=\"F\"\n"
156
                    + " KopOneUnit=\"\u0441\u043e\u0442\u0430\u044f \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430\" KopTwoUnit=\"\u0441\u043e\u0442\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430\" KopFiveUnit=\"\u0441\u043e\u0442\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430\" KopSex=\"F\"\n"
157
                    + " />\n"
158
                    + "\n"
159
                    + " <PER1000 CurrID=\"558\" CurrName=\"\u0412i\u0434\u0441\u043e\u0442\u043a\u0438 \u0437 \u0442\u0438\u0441\u044f\u0447\u043d\u0438\u043c\u0438 \u0447\u0430\u0441\u0442\u0438\u043d\u0430\u043c\u0438\" language=\"RUS\"\n"
160
                    + " RubOneUnit=\"\u0446\u0435\u043b\u0430\u044f,\" RubTwoUnit=\"\u0446\u0435\u043b\u044b\u0445,\" RubFiveUnit=\"\u0446\u0435\u043b\u044b\u0445,\" RubSex=\"F\"\n"
161
                    + " KopOneUnit=\"\u0442\u044b\u0441\u044f\u0447\u043d\u0430\u044f \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430\" KopTwoUnit=\"\u0442\u044b\u0441\u044f\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430\" KopFiveUnit=\"\u0442\u044b\u0441\u044f\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430\" KopSex=\"F\"\n"
162
                    + " />\n"
163
                    + "\n"
164
                    + " <PER10000 CurrID=\"559\" CurrName=\"\u0412i\u0434\u0441\u043e\u0442\u043a\u0438 \u0437 \u0434\u0435\u0441\u044f\u0442\u0438 \u0442\u0438\u0441\u044f\u0447\u043d\u0438\u043c\u0438 \u0447\u0430\u0441\u0442\u0438\u043d\u0430\u043c\u0438\" language=\"RUS\"\n"
165
                    + " RubOneUnit=\"\u0446\u0435\u043b\u0430\u044f,\" RubTwoUnit=\"\u0446\u0435\u043b\u044b\u0445,\" RubFiveUnit=\"\u0446\u0435\u043b\u044b\u0445,\" RubSex=\"F\"\n"
166
                    + " KopOneUnit=\"\u0434\u0435\u0441\u044f\u0442\u0438\u0442\u044b\u0441\u044f\u0447\u043d\u0430\u044f \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430\" KopTwoUnit=\"\u0434\u0435\u0441\u044f\u0442\u0438\u0442\u044b\u0441\u044f\u0447\u043d\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430\" KopFiveUnit=\"\u0434\u0435\u0441\u044f\u0442\u0438\u0442\u044b\u0441\u044f\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430\" KopSex=\"F\"\n"
167
                    + " />\n"
168
                    + "\n"
169
                    + " <PER10 CurrID=\"556\" CurrName=\"\u0412i\u0434\u0441\u043e\u0442\u043a\u0438 \u0437 \u0434\u0435\u0441\u044f\u0442\u0438\u043c\u0438 \u0447\u0430\u0441\u0442\u0438\u043d\u0430\u043c\u0438\" language=\"UKR\"\n"
170
                    + " RubOneUnit=\"\u0446\u0456\u043b\u0430,\" RubTwoUnit=\"\u0446\u0456\u043b\u0438\u0445,\" RubFiveUnit=\"\u0446\u0456\u043b\u0438\u0445,\" RubSex=\"F\"\n"
171
                    + " KopOneUnit=\"\u0434\u0435\u0441\u044f\u0442\u0430 \u0432\u0456\u0434\u0441\u043e\u0442\u043a\u0430\" KopTwoUnit=\"\u0434\u0435\u0441\u044f\u0442\u0438\u0445 \u0432\u0456\u0434\u0441\u043e\u0442\u043a\u0430\" KopFiveUnit=\"\u0434\u0435\u0441\u044f\u0442\u0438\u0445 \u0432\u0456\u0434\u0441\u043e\u0442\u043a\u0430\" KopSex=\"F\"\n"
172
                    + " />\n"
173
                    + "\n"
174
                    + " <PER100 CurrID=\"557\" CurrName=\"\u0412i\u0434\u0441\u043e\u0442\u043a\u0438 \u0437 \u0441\u043e\u0442\u0438\u043c\u0438 \u0447\u0430\u0441\u0442\u0438\u043d\u0430\u043c\u0438\" language=\"UKR\"\n"
175
                    + " RubOneUnit=\"\u0446\u0456\u043b\u0430,\" RubTwoUnit=\"\u0446\u0456\u043b\u0438\u0445,\" RubFiveUnit=\"\u0446\u0456\u043b\u0438\u0445,\" RubSex=\"F\"\n"
176
                    + " KopOneUnit=\"\u0441\u043e\u0442\u0430 \u0432\u0456\u0434\u0441\u043e\u0442\u043a\u0430\" KopTwoUnit=\"\u0441\u043e\u0442\u0438\u0445 \u0432\u0456\u0434\u0441\u043e\u0442\u043a\u0430\" KopFiveUnit=\"\u0441\u043e\u0442\u0438\u0445 \u0432\u0456\u0434\u0441\u043e\u0442\u043a\u0430\" KopSex=\"F\"\n"
177
                    + " />\n"
178
                    + "\n"
179
                    + " <PER1000 CurrID=\"558\" CurrName=\"\u0412i\u0434\u0441\u043e\u0442\u043a\u0438 \u0437 \u0442\u0438\u0441\u044f\u0447\u043d\u0438\u043c\u0438 \u0447\u0430\u0441\u0442\u0438\u043d\u0430\u043c\u0438\" language=\"UKR\"\n"
180
                    + " RubOneUnit=\"\u0446\u0456\u043b\u0430,\" RubTwoUnit=\"\u0446\u0456\u043b\u0438\u0445,\" RubFiveUnit=\"\u0446\u0456\u043b\u0438\u0445,\" RubSex=\"F\"\n"
181
                    + " KopOneUnit=\"\u0442\u0438\u0441\u044f\u0447\u043d\u0430 \u0432\u0456\u0434\u0441\u043e\u0442\u043a\u0430\" KopTwoUnit=\"\u0442\u0438\u0441\u044f\u0447\u043d\u0438\u0445 \u0432\u0456\u0434\u0441\u043e\u0442\u043a\u0430\" KopFiveUnit=\"\u0442\u0438\u0441\u044f\u0447\u043d\u0438\u0445 \u0432\u0456\u0434\u0441\u043e\u0442\u043a\u0430\" KopSex=\"F\"\n"
182
                    + " />\n"
183
                    + "\n"
184
                    + " <PER10000 CurrID=\"559\" CurrName=\"\u0412i\u0434\u0441\u043e\u0442\u043a\u0438 \u0437 \u0434\u0435\u0441\u044f\u0442\u0438 \u0442\u0438\u0441\u044f\u0447\u043d\u0438\u043c\u0438 \u0447\u0430\u0441\u0442\u0438\u043d\u0430\u043c\u0438\" language=\"UKR\"\n"
185
                    + " RubOneUnit=\"\u0446\u0456\u043b\u0430,\" RubTwoUnit=\"\u0446\u0456\u043b\u0438\u0445,\" RubFiveUnit=\"\u0446\u0456\u043b\u0438\u0445,\" RubSex=\"F\"\n"
186
                    + " KopOneUnit=\"\u0434\u0435\u0441\u044f\u0442\u0438\u0442\u0438\u0441\u044f\u0447\u043d\u0430 \u0432\u0456\u0434\u0441\u043e\u0442\u043a\u0430\" KopTwoUnit=\"\u0434\u0435\u0441\u044f\u0442\u0438\u0442\u0438\u0441\u044f\u0447\u043d\u0438\u0445 \u0432\u0456\u0434\u0441\u043e\u0442\u043a\u0430\" KopFiveUnit=\"\u0434\u0435\u0441\u044f\u0442\u0438\u0442\u0438\u0441\u044f\u0447\u043d\u0438\u0445 \u0432\u0456\u0434\u0441\u043e\u0442\u043a\u0430\" KopSex=\"M\"\n"
187
                    + " />\n"
188
                    + "\n"
189
                    + " <PER10 CurrID=\"560\" CurrName=\"\u0412i\u0434\u0441\u043e\u0442\u043a\u0438 \u0437 \u0434\u0435\u0441\u044f\u0442\u0438\u043c\u0438 \u0447\u0430\u0441\u0442\u0438\u043d\u0430\u043c\u0438\" language=\"ENG\"\n"
190
                    + " RubOneUnit=\",\" RubTwoUnit=\"integers,\" RubFiveUnit=\"integers,\" RubSex=\"F\"\n"
191
                    + " KopOneUnit=\"tenth of one percent\" KopTwoUnit=\"tenth of one percent\" KopFiveUnit=\"tenth of one percent\" KopSex=\"F\"\n"
192
                    + " />\n"
193
                    + "\n"
194
                    + " <PER100 CurrID=\"561\" CurrName=\"\u0412i\u0434\u0441\u043e\u0442\u043a\u0438 \u0437 \u0441\u043e\u0442\u0438\u043c\u0438 \u0447\u0430\u0441\u0442\u0438\u043d\u0430\u043c\u0438\" language=\"ENG\"\n"
195
                    + " RubOneUnit=\",\" RubTwoUnit=\"integers,\" RubFiveUnit=\"integers,\" RubSex=\"F\"\n"
196
                    + " KopOneUnit=\"hundred percent\" KopTwoUnit=\"hundredth of percent\" KopFiveUnit=\"hundredth of percent\" KopSex=\"F\"\n"
197
                    + " />\n"
198
                    + "\n"
199
                    + " <PER1000 CurrID=\"562\" CurrName=\"\u0412i\u0434\u0441\u043e\u0442\u043a\u0438 \u0437 \u0442\u0438\u0441\u044f\u0447\u043d\u0438\u043c\u0438 \u0447\u0430\u0441\u0442\u0438\u043d\u0430\u043c\u0438\" language=\"ENG\"\n"
200
                    + " RubOneUnit=\",\" RubTwoUnit=\"integers,\" RubFiveUnit=\"integers,\" RubSex=\"F\"\n"
201
                    + " KopOneUnit=\"thousandth of percent\" KopTwoUnit=\"thousandths of percent\" KopFiveUnit=\"thousandths of percent\" KopSex=\"F\"\n"
202
                    + " />\n"
203
                    + "\n"
204
                    + " <PER10000 CurrID=\"563\" CurrName=\"\u0412i\u0434\u0441\u043e\u0442\u043a\u0438 \u0437 \u0434\u0435\u0441\u044f\u0442\u0438 \u0442\u0438\u0441\u044f\u0447\u043d\u0438\u043c\u0438 \u0447\u0430\u0441\u0442\u0438\u043d\u0430\u043c\u0438\" language=\"ENG\"\n"
205
                    + " RubOneUnit=\",\" RubTwoUnit=\"integers,\" RubFiveUnit=\"integers,\" RubSex=\"F\"\n"
206
                    + " KopOneUnit=\"ten percent\" KopTwoUnit=\"ten-percent\" KopFiveUnit=\"ten-percent\" KopSex=\"F\"\n"
207
                    + " />\n"
208
                    + "\n"
209
                    + "</CurrencyList>\n";
210
    private final java.util.Map<String, String[]> messages =
1✔
211
            new java.util.LinkedHashMap<String, String[]>();
212
    private final String rubOneUnit;
213
    private final String rubTwoUnit;
214
    private final String rubFiveUnit;
215
    private final String rubSex;
216
    private final String kopOneUnit;
217
    private final String kopTwoUnit;
218
    private final String kopFiveUnit;
219
    private final String kopSex;
220
    private final String rubShortUnit;
221
    private final Currency currency;
222
    private final Language language;
223
    private final Pennies pennies;
224

225
    static {
226
        initXmlDoc(CURRENCY_LIST);
1✔
227
    }
1✔
228

229
    public static void initXmlDoc(final String xmlData) {
230
        javax.xml.parsers.DocumentBuilderFactory docFactory =
231
                javax.xml.parsers.DocumentBuilderFactory.newInstance();
1✔
232
        try {
233
            javax.xml.parsers.DocumentBuilder xmlDocBuilder = docFactory.newDocumentBuilder();
1✔
234
            xmlDoc =
1✔
235
                    xmlDocBuilder.parse(new java.io.ByteArrayInputStream(xmlData.getBytes("UTF8")));
1✔
236
        } catch (Exception ex) {
1✔
237
            throw new UnsupportedOperationException(ex);
1✔
238
        }
1✔
239
    }
1✔
240

241
    /** Currency. */
242
    public enum Currency {
1✔
243
        /** . */
244
        RUR,
1✔
245
        /** . */
246
        UAH,
1✔
247
        /** . */
248
        USD,
1✔
249
        /** . */
250
        EUR,
1✔
251
        /** . */
252
        PER10,
1✔
253
        /** . */
254
        PER100,
1✔
255
        /** . */
256
        PER1000,
1✔
257
        /** . */
258
        PER10000,
1✔
259
        /** . */
260
        Custom
1✔
261
    }
262

263
    /** Language. */
264
    public enum Language {
1✔
265
        /** . */
266
        RUS,
1✔
267
        /** . */
268
        UKR,
1✔
269
        /** . */
270
        ENG
1✔
271
    }
272

273
    /** Pennies. */
274
    public enum Pennies {
1✔
275
        /** . */
276
        NUMBER,
1✔
277
        /** . */
278
        TEXT
1✔
279
    }
280

281
    /**
282
     * Inits class with currency. Usage: MoneyToStr moneyToStr = new MoneyToStr(
283
     * MoneyToStr.Currency.UAH, MoneyToStr.Language.UKR, MoneyToStr.Pennies.NUMBER); Definition for
284
     * currency is placed into currlist.xml
285
     *
286
     * @param currency the currency (UAH, RUR, USD, EUR)
287
     * @param language the language (UKR, RUS, ENG)
288
     * @param pennies the pennies (NUMBER, TEXT)
289
     */
290
    public MoneyToStr(Currency currency, Language language, Pennies pennies) {
1✔
291
        if (currency == null) {
1✔
292
            throw new IllegalArgumentException("currency is null");
1✔
293
        }
294
        if (language == null) {
1✔
295
            throw new IllegalArgumentException("language is null");
1✔
296
        }
297
        if (pennies == null) {
1✔
298
            throw new IllegalArgumentException("pennies is null");
1✔
299
        }
300
        this.currency = currency;
1✔
301
        this.language = language;
1✔
302
        this.pennies = pennies;
1✔
303
        String theISOstr = currency.name();
1✔
304
        org.w3c.dom.Element languageElement =
1✔
305
                (org.w3c.dom.Element) (xmlDoc.getElementsByTagName(language.name())).item(0);
1✔
306
        org.w3c.dom.NodeList items = languageElement.getElementsByTagName("item");
1✔
307
        for (int index = 0; index < items.getLength(); index += 1) {
1✔
308
            org.w3c.dom.Element languageItem = (org.w3c.dom.Element) items.item(index);
1✔
309
            messages.put(
1✔
310
                    languageItem.getAttribute("value"),
1✔
311
                    languageItem.getAttribute("text").split(","));
1✔
312
        }
313
        org.w3c.dom.NodeList theISOElements =
1✔
314
                (org.w3c.dom.NodeList) (xmlDoc.getElementsByTagName(theISOstr));
1✔
315
        org.w3c.dom.Element theISOElement = null;
1✔
316
        for (int index = 0; index < theISOElements.getLength(); index += 1) {
1✔
317
            if (((org.w3c.dom.Element) theISOElements.item(index))
1✔
318
                    .getAttribute("language")
1✔
319
                    .equals(language.name())) {
1✔
320
                theISOElement = (org.w3c.dom.Element) theISOElements.item(index);
1✔
321
                break;
1✔
322
            }
323
        }
324
        rubOneUnit = theISOElement.getAttribute("RubOneUnit");
1✔
325
        rubTwoUnit = theISOElement.getAttribute("RubTwoUnit");
1✔
326
        rubFiveUnit = theISOElement.getAttribute("RubFiveUnit");
1✔
327
        kopOneUnit = theISOElement.getAttribute("KopOneUnit");
1✔
328
        kopTwoUnit = theISOElement.getAttribute("KopTwoUnit");
1✔
329
        kopFiveUnit = theISOElement.getAttribute("KopFiveUnit");
1✔
330
        rubSex = theISOElement.getAttribute("RubSex");
1✔
331
        kopSex = theISOElement.getAttribute("KopSex");
1✔
332
        rubShortUnit =
1✔
333
                theISOElement.hasAttribute("RubShortUnit")
1✔
334
                        ? theISOElement.getAttribute("RubShortUnit")
1✔
335
                        : "";
336
    }
1✔
337

338
    /**
339
     * Inits class with currency. Usage: MoneyToStr moneyToStr = new MoneyToStr(
340
     * MoneyToStr.Currency.UAH, MoneyToStr.Language.UKR, MoneyToStr.Pennies.NUMBER);
341
     *
342
     * @param currency the currency (UAH, RUR, USD, EUR)
343
     * @param language the language (UKR, RUS, ENG)
344
     * @param pennies the pennies (NUMBER, TEXT)
345
     * @param names the custom names
346
     */
347
    public MoneyToStr(Currency currency, Language language, Pennies pennies, String[] names) {
1✔
348
        if (currency == null) {
1✔
349
            throw new IllegalArgumentException("currency is null");
1✔
350
        }
351
        if (language == null) {
1✔
352
            throw new IllegalArgumentException("language is null");
1✔
353
        }
354
        if (pennies == null) {
1✔
355
            throw new IllegalArgumentException("pennies is null");
1✔
356
        }
357
        if (names == null || names.length != 8) {
1✔
358
            throw new IllegalArgumentException("names is null");
1✔
359
        }
360
        this.currency = currency;
1✔
361
        this.language = language;
1✔
362
        this.pennies = pennies;
1✔
363
        org.w3c.dom.Element languageElement =
1✔
364
                (org.w3c.dom.Element) (xmlDoc.getElementsByTagName(language.name())).item(0);
1✔
365
        org.w3c.dom.NodeList items = languageElement.getElementsByTagName("item");
1✔
366
        for (int index = 0; index < items.getLength(); index += 1) {
1✔
367
            org.w3c.dom.Element languageItem = (org.w3c.dom.Element) items.item(index);
1✔
368
            messages.put(
1✔
369
                    languageItem.getAttribute("value"),
1✔
370
                    languageItem.getAttribute("text").split(","));
1✔
371
        }
372
        rubOneUnit = names[0];
1✔
373
        rubTwoUnit = names[1];
1✔
374
        rubFiveUnit = names[2];
1✔
375
        rubSex = names[3];
1✔
376
        kopOneUnit = names[4];
1✔
377
        kopTwoUnit = names[5];
1✔
378
        kopFiveUnit = names[6];
1✔
379
        kopSex = names[7];
1✔
380
        rubShortUnit = names[0];
1✔
381
    }
1✔
382

383
    /**
384
     * Converts percent to string.
385
     *
386
     * @param amount the amount of percent
387
     * @param lang the language (RUS, UKR)
388
     * @return the string of percent
389
     */
390
    public static String percentToStr(Double amount, Language lang) {
391
        return percentToStr(amount, lang, Pennies.TEXT);
1✔
392
    }
393

394
    /**
395
     * Converts percent to string.
396
     *
397
     * @param amount the amount of percent
398
     * @param lang the language (RUS, UKR, ENG)
399
     * @param pennies the pennies (NUMBER, TEXT)
400
     * @return the string of percent
401
     */
402
    public static String percentToStr(Double amount, Language lang, Pennies pennies) {
403
        if (amount == null) {
1✔
404
            throw new IllegalArgumentException("amount is null");
1✔
405
        }
406
        if (lang == null) {
1✔
407
            throw new IllegalArgumentException("language is null");
1✔
408
        }
409
        if (pennies == null) {
1✔
410
            throw new IllegalArgumentException("pennies is null");
1✔
411
        }
412
        Long intPart = amount.longValue();
1✔
413
        Long fractPart = 0L;
1✔
414
        String result;
415
        if (amount.floatValue() == amount.intValue()) {
1✔
416
            result = new MoneyToStr(Currency.PER10, lang, pennies).convert(amount.longValue(), 0L);
1✔
417
        } else if (Double.valueOf(amount * NUM10).floatValue()
1✔
418
                == Double.valueOf(amount * NUM10).intValue()) {
1✔
419
            fractPart = Math.round((amount - intPart) * NUM10);
1✔
420
            result = new MoneyToStr(Currency.PER10, lang, pennies).convert(intPart, fractPart);
1✔
421
        } else if (Double.valueOf(amount * NUM100).floatValue()
1✔
422
                == Double.valueOf(amount * NUM100).intValue()) {
1✔
423
            fractPart = Math.round((amount - intPart) * NUM100);
1✔
424
            result = new MoneyToStr(Currency.PER100, lang, pennies).convert(intPart, fractPart);
1✔
425
        } else if (Double.valueOf(amount * NUM1000).floatValue()
1✔
426
                == Double.valueOf(amount * NUM1000).intValue()) {
1✔
427
            fractPart = Math.round((amount - intPart) * NUM1000);
1✔
428
            result = new MoneyToStr(Currency.PER1000, lang, pennies).convert(intPart, fractPart);
1✔
429
        } else {
430
            fractPart = Math.round((amount - intPart) * NUM10000);
1✔
431
            result = new MoneyToStr(Currency.PER10000, lang, pennies).convert(intPart, fractPart);
1✔
432
        }
433
        return result;
1✔
434
    }
435

436
    /**
437
     * Converts double value to the text description.
438
     *
439
     * @param theMoney the amount of money in format major.minor
440
     * @return the string description of money value
441
     */
442
    public String convert(Double theMoney) {
443
        if (theMoney == null) {
1✔
444
            throw new IllegalArgumentException("theMoney is null");
1✔
445
        }
446
        Long intPart = theMoney.longValue();
1✔
447
        Long fractPart = Math.round((theMoney - intPart) * NUM100);
1✔
448
        if (currency == Currency.PER1000) {
1✔
449
            fractPart = Math.round((theMoney - intPart) * NUM1000);
1✔
450
        }
451
        return convert(intPart, fractPart);
1✔
452
    }
453

454
    /**
455
     * Converts amount to words. Usage: MoneyToStr moneyToStr = new
456
     * MoneyToStr(MoneyToStr.Currency.UAH, MoneyToStr.Language.UKR, MoneyToStr.Pennies.NUMBER);
457
     * String result = moneyToStr.convert(123D); Expected: result = сто двадцять три гривні 00
458
     * копійок
459
     *
460
     * @param theMoney the amount of money major currency
461
     * @param theKopeiki the amount of money minor currency
462
     * @return the string description of money value
463
     */
464
    public String convert(Long theMoney, Long theKopeiki) {
465
        if (theMoney == null) {
1✔
466
            throw new IllegalArgumentException("theMoney is null");
1✔
467
        }
468
        if (theKopeiki == null) {
1✔
469
            throw new IllegalArgumentException("theKopeiki is null");
1✔
470
        }
471
        StringBuilder money2str = new StringBuilder();
1✔
472
        Long triadNum = 0L;
1✔
473
        Long theTriad;
474

475
        Long intPart = Math.abs(theMoney);
1✔
476
        if (intPart == 0) {
1✔
477
            money2str.append(messages.get("0")[0] + " ");
1✔
478
        }
479
        do {
480
            theTriad = intPart % NUM1000;
1✔
481
            money2str.insert(0, triad2Word(theTriad, triadNum, rubSex));
1✔
482
            if (triadNum == 0) {
1✔
483
                if ((theTriad % NUM100) / NUM10 == NUM1) {
1✔
484
                    money2str.append(rubFiveUnit);
1✔
485
                } else {
486
                    switch (Long.valueOf(theTriad % NUM10).byteValue()) {
1✔
487
                        case NUM1:
488
                            money2str.append(rubOneUnit);
1✔
489
                            break;
1✔
490
                        case NUM2:
491
                        case NUM3:
492
                        case NUM4:
493
                            money2str.append(rubTwoUnit);
1✔
494
                            break;
1✔
495
                        default:
496
                            money2str.append(rubFiveUnit);
1✔
497
                            break;
498
                    }
499
                }
500
            }
501
            intPart /= NUM1000;
1✔
502
            triadNum++;
1✔
503
        } while (intPart > 0);
1✔
504

505
        if (theMoney < 0) {
1✔
506
            money2str.insert(0, messages.get("minus")[0] + " ");
1✔
507
        }
508
        if (pennies == Pennies.TEXT) {
1✔
509
            money2str
1✔
510
                    .append(language == Language.ENG ? " and " : " ")
1✔
511
                    .append(
1✔
512
                            theKopeiki == 0
1✔
513
                                    ? messages.get("0")[0] + " "
1✔
514
                                    : triad2Word(Math.abs(theKopeiki), 0L, kopSex));
1✔
515
        } else {
516
            money2str.append(
1✔
517
                    " "
518
                            + (Math.abs(theKopeiki) < 10
1✔
519
                                    ? "0" + Math.abs(theKopeiki)
1✔
520
                                    : Math.abs(theKopeiki))
1✔
521
                            + " ");
522
        }
523
        if (theKopeiki >= NUM11 && theKopeiki <= NUM14) {
1✔
524
            money2str.append(kopFiveUnit);
1✔
525
        } else {
526
            switch ((byte) (theKopeiki % NUM10)) {
1✔
527
                case NUM1:
528
                    money2str.append(kopOneUnit);
1✔
529
                    break;
1✔
530
                case NUM2:
531
                case NUM3:
532
                case NUM4:
533
                    money2str.append(kopTwoUnit);
1✔
534
                    break;
1✔
535
                default:
536
                    money2str.append(kopFiveUnit);
1✔
537
                    break;
538
            }
539
        }
540
        return money2str.toString().trim();
1✔
541
    }
542

543
    private String triad2Word(Long triad, Long triadNum, String sex) {
544
        final StringBuilder triadWord = new StringBuilder(NUM100);
1✔
545

546
        if (triad == 0) {
1✔
547
            return "";
1✔
548
        }
549

550
        triadWord.append(
1✔
551
                concat(new String[] {""}, messages.get("100_900"))[
1✔
552
                        Long.valueOf(triad / NUM100).byteValue()]);
1✔
553
        final Long range10 = (triad % NUM100) / NUM10;
1✔
554
        triadWord.append(concat(new String[] {"", ""}, messages.get("20_90"))[range10.byteValue()]);
1✔
555
        if (language == Language.ENG && triadWord.length() > 0 && triad % NUM10 == 0) {
1✔
556
            triadWord.deleteCharAt(triadWord.length() - 1);
1✔
557
            triadWord.append(" ");
1✔
558
        }
559

560
        check2(triadNum, sex, triadWord, triad, range10);
1✔
561
        switch (triadNum.byteValue()) {
1✔
562
            case NUM0:
563
                break;
1✔
564
            case NUM1:
565
            case NUM2:
566
            case NUM3:
567
            case NUM4:
568
                if (range10 == NUM1) {
1✔
569
                    triadWord.append(messages.get("1000_10")[triadNum.byteValue() - 1] + " ");
1✔
570
                } else {
571
                    final Long range = triad % NUM10;
1✔
572
                    switch (range.byteValue()) {
1✔
573
                        case NUM1:
574
                            triadWord.append(
1✔
575
                                    messages.get("1000_1")[triadNum.byteValue() - 1] + " ");
1✔
576
                            break;
1✔
577
                        case NUM2:
578
                        case NUM3:
579
                        case NUM4:
580
                            triadWord.append(
1✔
581
                                    messages.get("1000_234")[triadNum.byteValue() - 1] + " ");
1✔
582
                            break;
1✔
583
                        default:
584
                            triadWord.append(
1✔
585
                                    messages.get("1000_5")[triadNum.byteValue() - 1] + " ");
1✔
586
                            break;
587
                    }
588
                }
589
                break;
1✔
590
            default:
591
                triadWord.append("??? ");
1✔
592
                break;
593
        }
594
        return triadWord.toString();
1✔
595
    }
596

597
    /**
598
     * @param triadNum the triad num
599
     * @param sex the sex
600
     * @param triadWord the triad word
601
     * @param triad the triad
602
     * @param range10 the range 10
603
     */
604
    private void check2(
605
            Long triadNum, String sex, StringBuilder triadWord, Long triad, Long range10) {
606
        final Long range = triad % NUM10;
1✔
607
        if (range10 == 1) {
1✔
608
            triadWord.append(messages.get("10_19")[range.byteValue()] + " ");
1✔
609
        } else {
610
            switch (range.byteValue()) {
1✔
611
                case NUM1:
612
                    if (triadNum == NUM1) {
1✔
613
                        triadWord.append(messages.get("1")[INDEX_0] + " ");
1✔
614
                    } else if (triadNum == NUM2 || triadNum == NUM3 || triadNum == NUM4) {
1✔
615
                        triadWord.append(messages.get("1")[INDEX_1] + " ");
1✔
616
                    } else if ("M".equals(sex)) {
1✔
617
                        triadWord.append(messages.get("1")[INDEX_2] + " ");
1✔
618
                    } else if ("F".equals(sex)) {
1✔
619
                        triadWord.append(messages.get("1")[INDEX_3] + " ");
1✔
620
                    }
621
                    break;
622
                case NUM2:
623
                    if (triadNum == NUM1) {
1✔
624
                        triadWord.append(messages.get("2")[INDEX_0] + " ");
1✔
625
                    } else if (triadNum == NUM2 || triadNum == NUM3 || triadNum == NUM4) {
1✔
626
                        triadWord.append(messages.get("2")[INDEX_1] + " ");
1✔
627
                    } else if ("M".equals(sex)) {
1✔
628
                        triadWord.append(messages.get("2")[INDEX_2] + " ");
1✔
629
                    } else if ("F".equals(sex)) {
1✔
630
                        triadWord.append(messages.get("2")[INDEX_3] + " ");
1✔
631
                    }
632
                    break;
633
                case NUM3:
634
                case NUM4:
635
                case NUM5:
636
                case NUM6:
637
                case NUM7:
638
                case NUM8:
639
                case NUM9:
640
                    triadWord.append(
1✔
641
                            concat(new String[] {"", "", ""}, messages.get("3_9"))[
1✔
642
                                            range.byteValue()]
1✔
643
                                    + " ");
644
                    break;
1✔
645
                default:
646
                    break;
647
            }
648
        }
649
    }
1✔
650

651
    private <T> T[] concat(T[] first, T[] second) {
652
        final T[] result = java.util.Arrays.copyOf(first, first.length + second.length);
1✔
653
        System.arraycopy(second, 0, result, first.length, second.length);
1✔
654
        return result;
1✔
655
    }
656

657
    public static void main(String[] args) {
658
        String amount = "123.25";
1✔
659
        String language = "ENG";
1✔
660
        String currency = "USD";
1✔
661
        String pennies = "TEXT";
1✔
662
        if (args.length == 0) {
1✔
663
            System.out.println(
1✔
664
                    "Usage: java -jar moneytostr.jar --amount=123.25 --language=rus|ukr|eng --currency=rur|uah|usd|eur --pennies=text|number");
665
        } else {
666
            for (String arg : args) {
1✔
667
                if (arg.startsWith("--amount=")) {
1✔
668
                    amount = arg.substring("--amount=".length()).trim().replace(",", ".");
1✔
669
                } else if (arg.startsWith("--language=")) {
1✔
670
                    language = arg.substring("--language=".length()).trim().toUpperCase();
1✔
671
                } else if (arg.startsWith("--currency=")) {
1✔
672
                    currency = arg.substring("--currency=".length()).trim().toUpperCase();
1✔
673
                } else if (arg.startsWith("--pennies=")) {
1✔
674
                    pennies = arg.substring("--pennies=".length()).trim().toUpperCase();
1✔
675
                }
676
            }
677
            String result =
1✔
678
                    new MoneyToStr(
679
                                    Currency.valueOf(currency),
1✔
680
                                    Language.valueOf(language),
1✔
681
                                    Pennies.valueOf(pennies))
1✔
682
                            .convert(Double.valueOf(amount));
1✔
683
            System.out.println(result);
1✔
684
        }
685
    }
1✔
686

687
    public java.util.Map<String, String[]> getMessages() {
688
        return messages;
1✔
689
    }
690

691
    public String getRubShortUnit() {
692
        return rubShortUnit;
1✔
693
    }
694

695
    public Language getLanguage() {
696
        return language;
1✔
697
    }
698
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc