|
15 | 15 | */
|
16 | 16 | package org.contextmapper.contextmap.generator.model;
|
17 | 17 |
|
| 18 | +import org.contextmapper.contextmap.generator.model.exception.BoundedContextAlreadyPartOfContextMapException; |
| 19 | +import org.contextmapper.contextmap.generator.model.exception.BoundedContextNotPartOfContextMapException; |
| 20 | + |
18 | 21 | import java.util.*;
|
19 | 22 |
|
| 23 | +/** |
| 24 | + * Represents a Context Map for which a graphical representation shall be created. |
| 25 | + * |
| 26 | + * @author Stefan Kapferer |
| 27 | + */ |
20 | 28 | public class ContextMap {
|
21 | 29 |
|
22 |
| - private List<BoundedContext> boundedContexts; |
23 |
| - private List<Relationship> relationships; |
| 30 | + private Set<BoundedContext> boundedContexts; |
| 31 | + private Set<Relationship> relationships; |
24 | 32 |
|
25 | 33 | public ContextMap() {
|
26 |
| - this.boundedContexts = new ArrayList<>(); |
27 |
| - this.relationships = new ArrayList<>(); |
| 34 | + this.boundedContexts = new HashSet<>(); |
| 35 | + this.relationships = new HashSet<>(); |
28 | 36 | }
|
29 | 37 |
|
30 |
| - public void addBoundedContext(BoundedContext boundedContext) { |
| 38 | + /** |
| 39 | + * Adds a new Bounded Context to the Context Map. |
| 40 | + * |
| 41 | + * @param boundedContext the Bounded Context to be added to the Context Map |
| 42 | + */ |
| 43 | + public ContextMap addBoundedContext(BoundedContext boundedContext) { |
| 44 | + if (this.boundedContexts.contains(boundedContext)) |
| 45 | + throw new BoundedContextAlreadyPartOfContextMapException(boundedContext.getName()); |
31 | 46 | this.boundedContexts.add(boundedContext);
|
| 47 | + return this; |
32 | 48 | }
|
33 | 49 |
|
34 |
| - public void addRelationship(Relationship relationship) { |
| 50 | + /** |
| 51 | + * Adds a new relationship to the Context Map. |
| 52 | + * |
| 53 | + * @param relationship the relationship to be added to the Context Map |
| 54 | + */ |
| 55 | + public ContextMap addRelationship(Relationship relationship) { |
35 | 56 | if (!this.boundedContexts.contains(relationship.getFirstParticipant()))
|
36 | 57 | throw new BoundedContextNotPartOfContextMapException(relationship.getFirstParticipant());
|
37 | 58 | if (!this.boundedContexts.contains(relationship.getSecondParticipant()))
|
38 | 59 | throw new BoundedContextNotPartOfContextMapException(relationship.getSecondParticipant());
|
39 | 60 | this.relationships.add(relationship);
|
| 61 | + return this; |
40 | 62 | }
|
41 | 63 |
|
42 |
| - public List<BoundedContext> getBoundedContexts() { |
43 |
| - List<BoundedContext> set = new ArrayList<>(); |
| 64 | + /** |
| 65 | + * Gets the set of Bounded Contexts on the Context Map. |
| 66 | + * |
| 67 | + * @return the set of Bounded Contexts on the Context Map |
| 68 | + */ |
| 69 | + public Set<BoundedContext> getBoundedContexts() { |
| 70 | + Set<BoundedContext> set = new HashSet<>(); |
44 | 71 | set.addAll(this.boundedContexts);
|
45 | 72 | return set;
|
46 | 73 | }
|
47 | 74 |
|
48 |
| - public List<Relationship> getRelationships() { |
49 |
| - List<Relationship> set = new ArrayList<>(); |
| 75 | + /** |
| 76 | + * Gets the set of relationships on the Context Map. |
| 77 | + * |
| 78 | + * @return the set of relationships on the Context Map |
| 79 | + */ |
| 80 | + public Set<Relationship> getRelationships() { |
| 81 | + Set<Relationship> set = new HashSet<>(); |
50 | 82 | set.addAll(this.relationships);
|
51 | 83 | return set;
|
52 | 84 | }
|
|
0 commit comments