X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FJsonReturnObject.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FJsonReturnObject.java;h=0000000000000000000000000000000000000000;hb=d58ef344b43543fdcfca13c07df87e194f004376;hp=45bbb4f7fb9cc80af2a125eb48544b14a06060c8;hpb=959d2b0a4c4636c73d531d1097f062bf5f8e3edf;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/JsonReturnObject.java b/src/main/java/net/pterodactylus/sone/web/ajax/JsonReturnObject.java deleted file mode 100644 index 45bbb4f..0000000 --- a/src/main/java/net/pterodactylus/sone/web/ajax/JsonReturnObject.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * © 2013 xplosion interactive - */ - -package net.pterodactylus.sone.web.ajax; - -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.BooleanNode; -import com.fasterxml.jackson.databind.node.IntNode; -import com.fasterxml.jackson.databind.node.TextNode; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Maps; - -/** - * JSON return object for AJAX requests. - * - * @author David Roden - */ -public class JsonReturnObject { - - /** Whether the request was successful. */ - @JsonProperty - private final boolean success; - - /** The returned values. */ - private final Map content = Maps.newHashMap(); - - /** - * Creates a new JSON return object. - * - * @param success - * {@code true} if the request was successful, {@code false} otherwise - */ - public JsonReturnObject(boolean success) { - this.success = success; - } - - // - // ACCESSORS - // - - /** - * Returns whether the request was successful. - * - * @return {@code true} if the request was successful, {@code false} otherwise - */ - @VisibleForTesting - public boolean isSuccess() { - return success; - } - - /** - * Returns the value stored under the given key. - * - * @param key - * The key of the value to retrieve - * @return The value of the key, or {@code null} if there is no value for the - * given key - */ - @VisibleForTesting - public JsonNode get(String key) { - return content.get(key); - } - - /** - * Returns the content of this object for serialization. - * - * @return The content of this object - */ - @JsonAnyGetter - public Map getContent() { - return content; - } - - // - // ACTIONS - // - - /** - * Stores the given value under the given key. - * - * @param key - * The key under which to store the value - * @param value - * The value to store - * @return This JSON return object - */ - public JsonReturnObject put(String key, boolean value) { - return put(key, BooleanNode.valueOf(value)); - } - - /** - * Stores the given value under the given key. - * - * @param key - * The key under which to store the value - * @param value - * The value to store - * @return This JSON return object - */ - public JsonReturnObject put(String key, int value) { - return put(key, new IntNode(value)); - } - - /** - * Stores the given value under the given key. - * - * @param key - * The key under which to store the value - * @param value - * The value to store - * @return This JSON return object - */ - public JsonReturnObject put(String key, String value) { - return put(key, TextNode.valueOf(value)); - } - - /** - * Stores the given value under the given key. - * - * @param key - * The key under which to store the value - * @param value - * The value to store - * @return This JSON return object - */ - public JsonReturnObject put(String key, JsonNode value) { - content.put(key, value); - return this; - } - - @Override - public int hashCode() { - return Boolean.valueOf(success).hashCode() ^ content.hashCode(); - } - - @Override - public boolean equals(Object object) { - if ((object == null) || (object.getClass() != getClass())) { - return false; - } - JsonReturnObject other = (JsonReturnObject) object; - return (success == other.success) && content.equals(other.content); - } - -}