7 package com.google.appinventor.components.runtime.util;
10 import gnu.lists.LList;
11 import gnu.lists.Pair;
12 import gnu.math.IntNum;
13 import java.util.ArrayList;
14 import java.util.Collection;
15 import java.util.List;
17 import org.json.JSONException;
25 @SuppressWarnings(
"rawtypes")
60 LList newCdr = Pair.
makeList(objects, 0);
76 List valsList =
new ArrayList(vals);
78 LList newCdr = Pair.makeList(valsList);
87 List valsList =
new ArrayList(vals);
89 LList newCdr = Pair.makeList(valsList);
98 if (cdr instanceof Pair) {
99 return ((Pair) cdr).toArray();
100 }
else if (cdr instanceof LList) {
101 return ((LList) cdr).toArray();
103 throw new YailRuntimeError(
"YailList cannot be represented as an array",
"YailList Error.");
115 int size = this.size();
116 String[] objects =
new String[size];
117 for (
int i = 1; i <= size; i++) {
118 objects[i - 1] = YailListElementToString(
get(i));
132 if (element instanceof IntNum) {
133 return ((IntNum) element).toString(10);
134 }
else if (element instanceof Long) {
135 return Long.toString((Long) element);
136 }
else if (Number.class.isInstance(element)) {
139 return String.valueOf(element);
150 StringBuilder json =
new StringBuilder();
151 String separator =
"";
153 int size = this.size();
154 for (
int i = 1; i <= size; i++) {
155 Object value =
get(i);
161 return json.toString();
163 }
catch (JSONException e) {
164 throw new YailRuntimeError(
"List failed to convert to JSON.",
"JSON Creation Error.");
173 return super.size() - 1;
181 if (cdr instanceof Pair) {
182 return ((Pair) cdr).toString();
183 }
else if (cdr instanceof LList) {
184 return ((LList) cdr).toString();
186 throw new RuntimeException(
"YailList cannot be represented as a String");
194 return get(index + 1).toString();
201 return get(index + 1);