From: Leif Åstrand Date: Wed, 30 May 2012 14:57:48 +0000 (+0300) Subject: Extract duplicated code for decoding collections X-Git-Tag: 7.0.0.alpha3~205 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6526c870a3b5d8fbb22c8c80cb06fa25ab62ed97;p=vaadin-framework.git Extract duplicated code for decoding collections --- diff --git a/src/com/vaadin/terminal/gwt/client/communication/JsonDecoder.java b/src/com/vaadin/terminal/gwt/client/communication/JsonDecoder.java index 9ed20b6c79..8df92a141e 100644 --- a/src/com/vaadin/terminal/gwt/client/communication/JsonDecoder.java +++ b/src/com/vaadin/terminal/gwt/client/communication/JsonDecoder.java @@ -5,6 +5,7 @@ package com.vaadin.terminal.gwt.client.communication; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -144,22 +145,24 @@ public class JsonDecoder { private static List decodeList(JSONArray jsonArray, ConnectorMap idMapper, ApplicationConnection connection) { List tokens = new ArrayList(); - for (int i = 0; i < jsonArray.size(); ++i) { - // each entry always has two elements: type and value - JSONArray entryArray = (JSONArray) jsonArray.get(i); - tokens.add(decodeValue(entryArray, null, idMapper, connection)); - } + decodeIntoCollection(jsonArray, idMapper, connection, tokens); return tokens; } private static Set decodeSet(JSONArray jsonArray, ConnectorMap idMapper, ApplicationConnection connection) { Set tokens = new HashSet(); + decodeIntoCollection(jsonArray, idMapper, connection, tokens); + return tokens; + } + + private static void decodeIntoCollection(JSONArray jsonArray, + ConnectorMap idMapper, ApplicationConnection connection, + Collection tokens) { for (int i = 0; i < jsonArray.size(); ++i) { // each entry always has two elements: type and value JSONArray entryArray = (JSONArray) jsonArray.get(i); tokens.add(decodeValue(entryArray, null, idMapper, connection)); } - return tokens; } }