File tree Expand file tree Collapse file tree 5 files changed +110
-0
lines changed
java/org/eclipse/jnosql/diana/mongodb/document/type
resources/META-INF/services Expand file tree Collapse file tree 5 files changed +110
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ org.eclipse.jnosql.diana.mongodb.document.type.MoneyValueReader
Original file line number Diff line number Diff line change 1+ org.eclipse.jnosql.diana.mongodb.document.type.MoneyValueWriter
You can’t perform that action at this time.
0 commit comments