Rename project to “Rhynodge.”
[rhynodge.git] / src / main / java / net / pterodactylus / rhynodge / output / DefaultOutput.java
1 /*
2  * Rhynodge - DefaultOutput.java - Copyright © 2013 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.rhynodge.output;
19
20 import java.util.Map;
21
22 import com.google.common.collect.Maps;
23
24 /**
25  * {@link Output} implementation that stores texts for arbitrary MIME types.
26  *
27  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
28  */
29 public class DefaultOutput implements Output {
30
31         /** The summary of the output. */
32         private final String summary;
33
34         /** The texts for the different MIME types. */
35         private final Map<String, String> mimeTypeTexts = Maps.newHashMap();
36
37         /**
38          * Creates a new default output.
39          *
40          * @param summary
41          *            The summary of the output
42          */
43         public DefaultOutput(String summary) {
44                 this.summary = summary;
45         }
46
47         //
48         // ACTIONS
49         //
50
51         /**
52          * Adds the given text for the given MIME type.
53          *
54          * @param mimeType
55          *            The MIME type to add the text for
56          * @param text
57          *            The text to add
58          * @return This default output
59          */
60         public DefaultOutput addText(String mimeType, String text) {
61                 mimeTypeTexts.put(mimeType, text);
62                 return this;
63         }
64
65         //
66         // OUTPUT METHODS
67         //
68
69         /**
70          * {@inheritDoc}
71          */
72         @Override
73         public String summary() {
74                 return summary;
75         }
76
77         /**
78          * {@inheritDoc}
79          */
80         @Override
81         public String text(String mimeType, int maxLength) {
82                 return mimeTypeTexts.get(mimeType);
83         }
84
85 }