From a00c5ff9f135e00baffbc2901f0ef9dac0c8dda2 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Sun, 20 Nov 2011 20:16:46 +0000 Subject: [PATCH] Simplify inner strategy in LongSerializationPolicy. --- .../google/gson/LongSerializationPolicy.java | 38 ++++++------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/gson/src/main/java/com/google/gson/LongSerializationPolicy.java b/gson/src/main/java/com/google/gson/LongSerializationPolicy.java index aff45263..3d9a2da1 100644 --- a/gson/src/main/java/com/google/gson/LongSerializationPolicy.java +++ b/gson/src/main/java/com/google/gson/LongSerializationPolicy.java @@ -31,44 +31,28 @@ public enum LongSerializationPolicy { * would be: * {@code {"f":123}}. */ - DEFAULT(new DefaultStrategy()), + DEFAULT() { + public JsonElement serialize(Long value) { + return new JsonPrimitive(value); + } + }, /** * Serializes a long value as a quoted string. For example, assume an object has a long field * named "f" then the serialized output would be: * {@code {"f":"123"}}. */ - STRING(new StringStrategy()); + STRING() { + public JsonElement serialize(Long value) { + return new JsonPrimitive(String.valueOf(value)); + } + }; - private final Strategy strategy; - - private LongSerializationPolicy(Strategy strategy) { - this.strategy = strategy; - } - /** * Serialize this {@code value} using this serialization policy. * * @param value the long value to be serialized into a {@link JsonElement} * @return the serialized version of {@code value} */ - public JsonElement serialize(Long value) { - return strategy.serialize(value); - } - - private interface Strategy { - JsonElement serialize(Long value); - } - - private static class DefaultStrategy implements Strategy { - public JsonElement serialize(Long value) { - return new JsonPrimitive(value); - } - } - - private static class StringStrategy implements Strategy { - public JsonElement serialize(Long value) { - return new JsonPrimitive(String.valueOf(value)); - } - } + public abstract JsonElement serialize(Long value); }