From: David ‘Bombe’ Roden Date: Thu, 3 Jan 2013 15:37:22 +0000 (+0100) Subject: Add default Output implementation. X-Git-Tag: 0.1~88 X-Git-Url: https://git.pterodactylus.net/?p=rhynodge.git;a=commitdiff_plain;h=50b03cf6c97a2f639e7630738f279eee17f670b6 Add default Output implementation. --- diff --git a/src/main/java/net/pterodactylus/reactor/output/DefaultOutput.java b/src/main/java/net/pterodactylus/reactor/output/DefaultOutput.java new file mode 100644 index 0000000..36d836c --- /dev/null +++ b/src/main/java/net/pterodactylus/reactor/output/DefaultOutput.java @@ -0,0 +1,85 @@ +/* + * Reactor - DefaultOutput.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.reactor.output; + +import java.util.Map; + +import com.google.common.collect.Maps; + +/** + * {@link Output} implementation that stores texts for arbitrary MIME types. + * + * @author David ‘Bombe’ Roden + */ +public class DefaultOutput implements Output { + + /** The summary of the output. */ + private final String summary; + + /** The texts for the different MIME types. */ + private final Map mimeTypeTexts = Maps.newHashMap(); + + /** + * Creates a new default output. + * + * @param summary + * The summary of the output + */ + public DefaultOutput(String summary) { + this.summary = summary; + } + + // + // ACTIONS + // + + /** + * Adds the given text for the given MIME type. + * + * @param mimeType + * The MIME type to add the text for + * @param text + * The text to add + * @return This default output + */ + public DefaultOutput addText(String mimeType, String text) { + mimeTypeTexts.put(mimeType, text); + return this; + } + + // + // OUTPUT METHODS + // + + /** + * {@inheritDoc} + */ + @Override + public String summary() { + return summary; + } + + /** + * {@inheritDoc} + */ + @Override + public String text(String mimeType, int maxLength) { + return mimeTypeTexts.get(mimeType); + } + +}