Skip to content

Commit d0a2069

Browse files
committed
creates money type
1 parent 3289d9e commit d0a2069

File tree

5 files changed

+110
-0
lines changed

5 files changed

+110
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2019 Otávio Santana and others
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
16+
package org.eclipse.jnosql.diana.mongodb.document.type;
17+
18+
import java.math.BigDecimal;
19+
20+
public class Money {
21+
22+
private final String currency;
23+
24+
private final BigDecimal value;
25+
26+
Money(String currency, BigDecimal value) {
27+
this.currency = currency;
28+
this.value = value;
29+
}
30+
31+
public String getCurrency() {
32+
return currency;
33+
}
34+
35+
public BigDecimal getValue() {
36+
return value;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return currency + ' ' + value;
42+
}
43+
44+
public static Money parse(String text) {
45+
String[] texts = text.split(" ");
46+
return new Money(texts[0], BigDecimal.valueOf(Double.valueOf(texts[1])));
47+
}
48+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2019 Otávio Santana and others
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.eclipse.jnosql.diana.mongodb.document.type;
16+
17+
import jakarta.nosql.ValueReader;
18+
19+
public class MoneyValueReader implements ValueReader {
20+
21+
@Override
22+
public boolean isCompatible(Class clazz) {
23+
return Money.class.equals(clazz);
24+
}
25+
26+
@Override
27+
public <T> T read(Class<T> clazz, Object value) {
28+
return (T) Money.parse(value.toString());
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2019 Otávio Santana and others
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.eclipse.jnosql.diana.mongodb.document.type;
16+
17+
import jakarta.nosql.ValueWriter;
18+
19+
public class MoneyValueWriter implements ValueWriter<Money, String> {
20+
21+
@Override
22+
public boolean isCompatible(Class clazz) {
23+
return Money.class.equals(clazz);
24+
}
25+
26+
@Override
27+
public String write(Money money) {
28+
return money.toString();
29+
}
30+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.eclipse.jnosql.diana.mongodb.document.type.MoneyValueReader
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.eclipse.jnosql.diana.mongodb.document.type.MoneyValueWriter

0 commit comments

Comments
 (0)