Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
InternalSubjectRepository |
|
| 1.3333333333333333;1.333 |
1 | /* | |
2 | * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport | |
3 | * (http://www.vbs.admin.ch) | |
4 | * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch) | |
5 | * All rights reserved. | |
6 | * | |
7 | * Licensed under the Open Permis License which accompanies this distribution, | |
8 | * and is available at http://www.openpermis.org/BSDlicenceKent.txt | |
9 | */ | |
10 | package org.openpermis.repository.basic; | |
11 | ||
12 | import java.net.URI; | |
13 | import java.util.HashMap; | |
14 | import java.util.Map; | |
15 | ||
16 | import org.openpermis.Subject; | |
17 | import org.openpermis.basic.InternalSubject; | |
18 | import org.openpermis.repository.SubjectRepository; | |
19 | import org.openpermis.repository.SubjectRepositoryException; | |
20 | ||
21 | ||
22 | /** | |
23 | * A subject repository that retrieves subjects for a set of explicitly configured persons. | |
24 | * @since 0.1.0 | |
25 | */ | |
26 | public class InternalSubjectRepository | |
27 | implements SubjectRepository | |
28 | { | |
29 | ||
30 | //---- State | |
31 | ||
32 | /** | |
33 | * @since 0.1.0 | |
34 | */ | |
35 | private final Map<URI, Subject> subjectMap; | |
36 | ||
37 | //---- Constructors | |
38 | ||
39 | /** | |
40 | * Creates an empty repository. | |
41 | * @since 0.1.0 | |
42 | */ | |
43 | 5 | public InternalSubjectRepository () { |
44 | 5 | this.subjectMap = new HashMap<URI, Subject>(); |
45 | 5 | } |
46 | ||
47 | //---- Methods | |
48 | ||
49 | /** | |
50 | * Stores the specified subject in this repository. | |
51 | * @param subject a {@link Subject} that will be returned by {@link #retrieveSubject(URI)} | |
52 | * for URIs that matche {@link Subject#getIdentity()}. | |
53 | * @since 0.1.0 | |
54 | */ | |
55 | public void storeSubject (Subject subject) { | |
56 | 1 | this.subjectMap.put(subject.getIdentity(), subject); |
57 | 1 | } |
58 | ||
59 | //---- SubjectRepository | |
60 | ||
61 | /** | |
62 | * @since 0.1.0 | |
63 | */ | |
64 | public Subject retrieveSubject (URI identity) | |
65 | throws SubjectRepositoryException | |
66 | { | |
67 | 3 | final Subject subject = this.subjectMap.get(identity); |
68 | 3 | return subject != null ? subject : new InternalSubject(identity); |
69 | } | |
70 | ||
71 | } |