blob: edf1897a16e00ae8a0e30e89ca2413845b905d3e (
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
|
package org.spongycastle.asn1.x509.qualified;
import java.math.BigInteger;
import java.util.Enumeration;
import org.spongycastle.asn1.ASN1EncodableVector;
import org.spongycastle.asn1.ASN1Integer;
import org.spongycastle.asn1.ASN1Object;
import org.spongycastle.asn1.ASN1Primitive;
import org.spongycastle.asn1.ASN1Sequence;
import org.spongycastle.asn1.DERSequence;
/**
* The MonetaryValue object.
* <pre>
* MonetaryValue ::= SEQUENCE {
* currency Iso4217CurrencyCode,
* amount INTEGER,
* exponent INTEGER }
* -- value = amount * 10^exponent
* </pre>
*/
public class MonetaryValue
extends ASN1Object
{
private Iso4217CurrencyCode currency;
private ASN1Integer amount;
private ASN1Integer exponent;
public static MonetaryValue getInstance(
Object obj)
{
if (obj instanceof MonetaryValue)
{
return (MonetaryValue)obj;
}
if (obj != null)
{
return new MonetaryValue(ASN1Sequence.getInstance(obj));
}
return null;
}
private MonetaryValue(
ASN1Sequence seq)
{
Enumeration e = seq.getObjects();
// currency
currency = Iso4217CurrencyCode.getInstance(e.nextElement());
// hashAlgorithm
amount = ASN1Integer.getInstance(e.nextElement());
// exponent
exponent = ASN1Integer.getInstance(e.nextElement());
}
public MonetaryValue(
Iso4217CurrencyCode currency,
int amount,
int exponent)
{
this.currency = currency;
this.amount = new ASN1Integer(amount);
this.exponent = new ASN1Integer(exponent);
}
public Iso4217CurrencyCode getCurrency()
{
return currency;
}
public BigInteger getAmount()
{
return amount.getValue();
}
public BigInteger getExponent()
{
return exponent.getValue();
}
public ASN1Primitive toASN1Primitive()
{
ASN1EncodableVector seq = new ASN1EncodableVector();
seq.add(currency);
seq.add(amount);
seq.add(exponent);
return new DERSequence(seq);
}
}
|