Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Unified Diff: editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/utilities/general/JsonUtilities.java

Issue 488413003: Initial factory constructors for generated objects in Java server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: review and rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/utilities/general/JsonUtilities.java
diff --git a/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/utilities/general/JsonUtilities.java b/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/utilities/general/JsonUtilities.java
new file mode 100644
index 0000000000000000000000000000000000000000..46cc7d0936fad0d688d3c0dbb1dcded1f2804b6a
--- /dev/null
+++ b/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/utilities/general/JsonUtilities.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2014, the Dart project authors.
+ *
+ * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.dart.server.utilities.general;
+
+import com.google.common.collect.Lists;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * The class {@code JsonUtilities} defines some general utility methods that are useful with the
+ * {@link JsonElement}s.
+ *
+ * @coverage dart.server.utilities
+ */
+public class JsonUtilities {
+
+ public static Boolean[] decodeBooleanArray(JsonArray jsonArray) {
+ if (jsonArray == null) {
+ return new Boolean[0];
+ }
+ int i = 0;
+ Boolean[] booleanArray = new Boolean[jsonArray.size()];
+ Iterator<JsonElement> iterator = jsonArray.iterator();
+ while (iterator.hasNext()) {
+ booleanArray[i] = iterator.next().getAsBoolean();
+ i++;
+ }
+ return booleanArray;
+ }
+
+ public static Integer[] decodeIntegerArray(JsonArray jsonArray) {
+ if (jsonArray == null) {
+ return new Integer[0];
+ }
+ int i = 0;
+ Integer[] intArray = new Integer[jsonArray.size()];
+ Iterator<JsonElement> iterator = jsonArray.iterator();
+ while (iterator.hasNext()) {
+ intArray[i] = iterator.next().getAsInt();
+ i++;
+ }
+ return intArray;
+ }
+
+ public static List<String> decodeStringList(JsonArray jsonArray) {
+ if (jsonArray == null) {
+ return Lists.newArrayList();
+ }
+ List<String> stringList = new ArrayList<String>(jsonArray.size());
+ Iterator<JsonElement> iterator = jsonArray.iterator();
+ while (iterator.hasNext()) {
+ stringList.add(iterator.next().getAsString());
+ }
+ return stringList;
+ }
+
+}

Powered by Google App Engine
This is Rietveld 408576698