Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BasicLetterboxService |
|
| 1.6666666666666667;1.667 |
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.examples.simple; | |
11 | ||
12 | import java.util.ArrayList; | |
13 | import java.util.List; | |
14 | ||
15 | import org.slf4j.Logger; | |
16 | import org.slf4j.LoggerFactory; | |
17 | ||
18 | ||
19 | /** | |
20 | * Basic implementation of a letterbox for inserting and collecting letters. | |
21 | * @since 0.1.0 | |
22 | */ | |
23 | public class BasicLetterboxService | |
24 | implements LetterboxService | |
25 | { | |
26 | //---- Static | |
27 | ||
28 | 1 | private static final Logger LOGGER = LoggerFactory.getLogger(BasicLetterboxService.class); |
29 | ||
30 | //---- State | |
31 | ||
32 | private List<String> letterbox; | |
33 | ||
34 | //---- Constructors | |
35 | ||
36 | /** | |
37 | * Creates a new letter box service. | |
38 | * @since 0.4.0 | |
39 | */ | |
40 | 5 | public BasicLetterboxService () { |
41 | 5 | this.letterbox = new ArrayList<String>(); |
42 | 5 | } |
43 | ||
44 | //---- LetterboxService | |
45 | ||
46 | /** | |
47 | * @since 0.4.0 | |
48 | */ | |
49 | public List<String> collectLetters (String principal) { | |
50 | 3 | final List<String> result = this.letterbox; |
51 | 3 | this.letterbox = new ArrayList<String>(); |
52 | 3 | return result; |
53 | } | |
54 | ||
55 | /** | |
56 | * @since 0.4.0 | |
57 | */ | |
58 | public void insertLetter (String principal, String letter) { | |
59 | 3 | if (letter == null) { |
60 | 0 | throw new IllegalArgumentException("Letter is null."); |
61 | } | |
62 | 3 | LOGGER.debug("Principal [{}] inserts letter [{}]." + new Object[] {principal, letter}); |
63 | 3 | this.letterbox.add(letter); |
64 | 3 | } |
65 | ||
66 | } |