1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.joda.money.format;
17
18 import java.io.IOException;
19 import java.io.Serializable;
20
21 import org.joda.money.BigMoney;
22
23
24
25
26
27
28 final class LiteralPrinterParser implements MoneyPrinter, MoneyParser, Serializable {
29
30
31 private static final long serialVersionUID = 1L;
32
33
34 private final String literal;
35
36
37
38
39
40 LiteralPrinterParser(String literal) {
41 this.literal = literal;
42 }
43
44
45 public void print(MoneyPrintContext context, Appendable appendable, BigMoney money) throws IOException {
46 appendable.append(literal);
47 }
48
49 public void parse(MoneyParseContext context) {
50 int endPos = context.getIndex() + literal.length();
51 if (endPos <= context.getTextLength() &&
52 context.getTextSubstring(context.getIndex(), endPos).equals(literal)) {
53 context.setIndex(endPos);
54 } else {
55 context.setError();
56 }
57 }
58
59 @Override
60 public String toString() {
61 return "'" + literal + "'";
62 }
63
64 }