Skip to content

Commit 739f63f

Browse files
committed
Moved extras from main repo.
Changed root package.
1 parent 90784e1 commit 739f63f

File tree

10 files changed

+432
-0
lines changed

10 files changed

+432
-0
lines changed

.classpath

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
10+
<attributes>
11+
<attribute name="optional" value="true"/>
12+
<attribute name="maven.pomderived" value="true"/>
13+
</attributes>
14+
</classpathentry>
15+
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
16+
<attributes>
17+
<attribute name="maven.pomderived" value="true"/>
18+
</attributes>
19+
</classpathentry>
20+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
21+
<attributes>
22+
<attribute name="maven.pomderived" value="true"/>
23+
</attributes>
24+
</classpathentry>
25+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
26+
<attributes>
27+
<attribute name="maven.pomderived" value="true"/>
28+
</attributes>
29+
</classpathentry>
30+
<classpathentry kind="output" path="target/classes"/>
31+
</classpath>

.project

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>javamoney-extras</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
21+
<nature>org.eclipse.jdt.core.javanature</nature>
22+
</natures>
23+
</projectDescription>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
3+
org.eclipse.jdt.core.compiler.compliance=1.5
4+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5+
org.eclipse.jdt.core.compiler.source=1.5
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1

pom.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>javax.money</groupId>
6+
<version>1.0-SNAPSHOT</version>
7+
<artifactId>money-extras</artifactId>
8+
<name>JMoney and Currency - Extras not part of JSR 354</name>
9+
<packaging>jar</packaging>
10+
11+
<properties>
12+
<javamoney.version>1.0-SNAPSHOT</javamoney.version>
13+
</properties>
14+
15+
<build>
16+
<plugins>
17+
<!-- ======================================================= -->
18+
<!-- Packaging (OSGi bundle) -->
19+
<!-- ======================================================= -->
20+
<plugin>
21+
<groupId>org.apache.felix</groupId>
22+
<artifactId>maven-bundle-plugin</artifactId>
23+
</plugin>
24+
</plugins>
25+
</build>
26+
<dependencies>
27+
<dependency>
28+
<groupId>javax.money</groupId>
29+
<artifactId>money-platform-ri</artifactId>
30+
<version>${javamoney.version}</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>javax.money</groupId>
34+
<artifactId>money-api-convert</artifactId>
35+
<version>${javamoney.version}</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>javax.money</groupId>
39+
<artifactId>money-api-format</artifactId>
40+
<version>${javamoney.version}</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>javax.money</groupId>
44+
<artifactId>money-api-ext</artifactId>
45+
<version>${javamoney.version}</version>
46+
</dependency>
47+
</dependencies>
48+
</project>

src/etc/header.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
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.
2+
3+
Specification: JSR-354 Money and Currency API ("Specification")
4+
5+
Copyright (c) 2012-2013, Credit Suisse
6+
All rights reserved.
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 net.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 net.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 net.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)