Skip to content

Commit d21a73a

Browse files
committed
Merge branch 'master' of
https://github.com/JavaMoney/javamoney-extras.git Conflicts: pom.xml src/main/java/net/java/javamoney/extras/ValidationException.java
2 parents 8fbde4b + 481a602 commit d21a73a

File tree

8 files changed

+333
-58
lines changed

8 files changed

+333
-58
lines changed

.project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
</buildCommand>
1818
</buildSpec>
1919
<natures>
20+
<nature>org.eclipse.pde.PluginNature</nature>
2021
<nature>org.eclipse.m2e.core.maven2Nature</nature>
2122
<nature>org.eclipse.jdt.core.javanature</nature>
2223
</natures>

.settings/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/org.eclipse.pde.core.prefs

pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@
77
<artifactId>money-extras</artifactId>
88
<name>Money and Currency - Extras not part of JSR 354</name>
99
<packaging>bundle</packaging>
10+
<<<<<<< HEAD
1011

12+
=======
13+
14+
>>>>>>> branch 'master' of https://github.com/JavaMoney/javamoney-extras.git
1115
<properties>
16+
<<<<<<< HEAD
1217
<jdkVersion>1.7</jdkVersion>
18+
=======
19+
<jdkVersion>1.7</jdkVersion>
20+
>>>>>>> branch 'master' of https://github.com/JavaMoney/javamoney-extras.git
1321
<maven.compile.targetLevel>${jdkVersion}</maven.compile.targetLevel>
1422
<maven.compile.sourceLevel>${jdkVersion}</maven.compile.sourceLevel>
1523
<javamoney.version>0.5-SNAPSHOT</javamoney.version>
@@ -60,6 +68,14 @@
6068
</plugins>
6169
</build>
6270
<dependencies>
71+
<<<<<<< HEAD
72+
=======
73+
<dependency>
74+
<groupId>javax.money</groupId>
75+
<artifactId>money-ri-platform</artifactId>
76+
<version>${javamoney.version}</version>
77+
</dependency>
78+
>>>>>>> branch 'master' of https://github.com/JavaMoney/javamoney-extras.git
6379
<dependency>
6480
<groupId>javax.money</groupId>
6581
<artifactId>money-api-convert</artifactId>

src/main/java/net/java/javamoney/extras/ValidationException.java

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* CREDIT SUISSE IS WILLING TO LICENSE THIS SPECIFICATION TO YOU ONLY UPON THE CONDITION THAT YOU ACCEPT ALL OF THE TERMS CONTAINED IN THIS AGREEMENT. PLEASE READ THE TERMS AND CONDITIONS OF THIS AGREEMENT CAREFULLY. BY DOWNLOADING THIS SPECIFICATION, YOU ACCEPT THE TERMS AND CONDITIONS OF THE AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY IT, SELECT THE "DECLINE" BUTTON AT THE BOTTOM OF THIS PAGE.
3+
*
4+
* Specification: JSR-354 Money and Currency API ("Specification")
5+
*
6+
* Copyright (c) 2012-2013, Credit Suisse
7+
* All rights reserved.
8+
*/
9+
package org.javamoney.extras;
10+
11+
import java.util.Map;
12+
13+
/**
14+
* Defines a {@link CompoundType} containing several results. Hereby the
15+
* different results are identified by arbitrary keys. Additionally each
16+
* {@link CompoundType} has a <i>leading</i> item that identifies the type of
17+
* result.<br/>
18+
* A {@link CompoundType} instance is defined to be implemented as immutable
19+
* object and therefore is very useful for modeling multidimensional results
20+
* objects or input parameters as they are common in financial applications.
21+
*
22+
* @author Anatole Tresch
23+
*/
24+
public interface CompoundType extends Map<String, Class<?>> {
25+
26+
/**
27+
* A {@link CompoundType}may have a type identifier that helps to identify,
28+
* what type of items object is returned.
29+
*
30+
* @return the {@link CompoundType}'s type, never null.
31+
*/
32+
public String getId();
33+
34+
/**
35+
* This method allows to check if a key within the {@code CompoundType} is a
36+
* required value, so a corresponding {@link CompoundValue} is valid.
37+
*
38+
* @param key
39+
* the key
40+
* @return true, if the corresponding value is required, false otherwise.
41+
*/
42+
public boolean isRequired(String key);
43+
44+
/**
45+
* Validates if the given {@link CompoundValue} defines all the attributes
46+
* as required by this {@link CompoundType} instance.
47+
*
48+
* @param compundValueMap
49+
* the {@link Map} to be validated before a {@link CompoundValue}
50+
* is created.
51+
* @see #isValid(CompoundValue)
52+
* @throws IllegalArgumentException
53+
* if validation fails.
54+
*/
55+
public void validate(Map<String, Object> compundValueMap)
56+
throws ValidationException;
57+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* CREDIT SUISSE IS WILLING TO LICENSE THIS SPECIFICATION TO YOU ONLY UPON THE CONDITION THAT YOU ACCEPT ALL OF THE TERMS CONTAINED IN THIS AGREEMENT. PLEASE READ THE TERMS AND CONDITIONS OF THIS AGREEMENT CAREFULLY. BY DOWNLOADING THIS SPECIFICATION, YOU ACCEPT THE TERMS AND CONDITIONS OF THE AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY IT, SELECT THE "DECLINE" BUTTON AT THE BOTTOM OF THIS PAGE.
3+
*
4+
* Specification: JSR-354 Money and Currency API ("Specification")
5+
*
6+
* Copyright (c) 2012-2013, Credit Suisse
7+
* All rights reserved.
8+
*/
9+
package org.javamoney.extras;
10+
11+
import java.util.Map;
12+
13+
/**
14+
* Defines a {@link CompoundValue} containing several results. Hereby the
15+
* different results are identified by arbitrary keys. Additionally each
16+
* {@link CompoundValue} has a <i>leading</i> item that identifies the type of
17+
* result.<br/>
18+
* A {@link CompoundValue} instance is defined to be implemented as immutable
19+
* object and therefore is very useful for modeling multidimensional results
20+
* objects or input parameters as they are common in financial applications.
21+
*
22+
* @author Anatole Tresch
23+
*/
24+
public interface CompoundValue extends Map<String,Object>{
25+
26+
/**
27+
* A {@link CompoundValue} may have an identifier that helps to identify,
28+
* what type of items object is returned.
29+
*
30+
* @return the {@link CompoundValue}'s type, never null.
31+
*/
32+
public String getId();
33+
34+
/**
35+
* Get the compound type of this instance.
36+
*
37+
* @return the compound type, never {@code null}.
38+
*/
39+
public CompoundType getCompoundType();
40+
41+
}
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*
2+
* Copyright (c) 2012, 2013, Werner Keil, Credit Suisse (Anatole Tresch).
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Contributors:
17+
* Anatole Tresch - initial version.
18+
*/
19+
package org.javamoney.extras;
20+
21+
import java.util.HashMap;
22+
import java.util.Map;
23+
24+
/**
25+
* Defines a {@link MultiValue} containing T instances.
26+
*
27+
* @see CompoundValue
28+
* @author Anatole Tresch
29+
*/
30+
public class MultiValue extends HashMap<String, Object> implements
31+
CompoundValue {
32+
33+
/**
34+
* serialVersionUID.
35+
*/
36+
private static final long serialVersionUID = 5511830637352838197L;
37+
private final String id;
38+
private CompoundType type;
39+
40+
protected MultiValue(String id, CompoundType type) {
41+
if (id == null) {
42+
throw new IllegalArgumentException("id can not bve null.");
43+
}
44+
this.id = id;
45+
if (type == null) {
46+
throw new IllegalArgumentException("type can not bve null.");
47+
}
48+
this.type = type;
49+
}
50+
51+
protected MultiValue(String id, CompoundType type, Map<String, Object> items) {
52+
this(id, type);
53+
type.validate(items);
54+
this.putAll(items);
55+
}
56+
57+
public CompoundType getCompoundType() {
58+
return this.type;
59+
}
60+
61+
/**
62+
* A compound item may have a type identifier that helps to identify, what
63+
* type of compound items object is returned.
64+
*
65+
* @return the compound item's type, never null.
66+
*/
67+
public String getId() {
68+
return this.id;
69+
}
70+
71+
public Builder toBuilder() {
72+
return new Builder(this);
73+
}
74+
75+
/**
76+
* A CompoundItemBuilder T is an CompoundItemBuilder that holds several
77+
* instances of a type T. In financial applications this is very useful
78+
* regarding several aspects:<br/>
79+
* <li>Passing several instance of T as one parameter into methods <li>
80+
* Returning several instance of T as result, e.g. from a complex financial
81+
* calculation. <li>Accessing series of data, e.g. by time or other
82+
* classification. <li>
83+
* Accessing multiple data from different providers.
84+
*
85+
*
86+
* @author Anatole Tresch
87+
*/
88+
public static class Builder {
89+
90+
private String id;
91+
private CompoundType type;
92+
private Map<String, Object> items = new HashMap<String, Object>();
93+
94+
public Builder(String id) {
95+
setId(id);
96+
}
97+
98+
public Builder(String id, CompoundType type) {
99+
setId(id);
100+
setCompoundType(type);
101+
}
102+
103+
public Builder setCompoundType(CompoundType type) {
104+
if (type == null) {
105+
throw new IllegalArgumentException("Compound type required.");
106+
}
107+
this.type = type;
108+
return this;
109+
}
110+
111+
public CompoundType getCompoundType() {
112+
return this.type;
113+
}
114+
115+
public Builder(CompoundValue baseItem) {
116+
if (baseItem != null) {
117+
setId(baseItem.getId());
118+
this.items.putAll(baseItem);
119+
}
120+
}
121+
122+
public String getId() {
123+
return this.id;
124+
}
125+
126+
public Builder setId(String id) {
127+
if (id == null) {
128+
throw new IllegalArgumentException("id may not be null.");
129+
}
130+
this.id = id;
131+
return this;
132+
}
133+
134+
public Map<String, Object> getItems() {
135+
return this.items;
136+
}
137+
138+
public Object set(String key, Object item) {
139+
if (item == null) {
140+
throw new IllegalArgumentException("item may not be null.");
141+
}
142+
if (key == null) {
143+
throw new IllegalArgumentException("key may not be null.");
144+
}
145+
return this.items.put(key, item);
146+
}
147+
148+
public void set(Map<String, Object> items) {
149+
if (items == null) {
150+
throw new IllegalArgumentException("items may not be null.");
151+
}
152+
this.items.putAll(items);
153+
}
154+
155+
public Object remove(Object key) {
156+
return this.items.remove(key);
157+
}
158+
159+
public void removeAll() {
160+
this.items.clear();
161+
}
162+
163+
public CompoundValue build() {
164+
return new MultiValue(this.id, this.type, this.items);
165+
}
166+
167+
}
168+
169+
}

0 commit comments

Comments
 (0)