use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class Map method invoke.
private static Collection invoke(PageContext pc, Array arr, UDF udf, ExecutorService es, List<Future<Data<Object>>> futures) throws CasterException, PageException {
Array rtn = new ArrayImpl();
Iterator it = (arr instanceof ArrayPro ? ((ArrayPro) arr).entryArrayIterator() : arr.entryIterator());
Entry e;
boolean async = es != null;
Object res;
while (it.hasNext()) {
e = (Entry) it.next();
res = _inv(pc, udf, new Object[] { e.getValue(), Caster.toDoubleValue(e.getKey()), arr }, e.getKey(), es, futures);
if (!async)
rtn.set(Caster.toString(e.getKey()), res);
}
return rtn;
}
use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class Map method invoke.
private static Array invoke(PageContext pc, Iterator it, UDF udf, ExecutorService es, List<Future<Data<Object>>> futures) throws PageException {
Array rtn = new ArrayImpl();
Object v;
boolean async = es != null;
Object res;
int count = 0;
ArgumentIntKey k;
while (it.hasNext()) {
v = it.next();
k = ArgumentIntKey.init(++count);
res = _inv(pc, udf, new Object[] { v }, k, es, futures);
if (!async)
rtn.set(k, res);
}
return rtn;
}
use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class ComponentListPackage method call.
public static Array call(PageContext pc, String packageName) throws PageException {
Set<String> names;
try {
names = _call(pc, packageName);
} catch (IOException e) {
throw Caster.toPageException(e);
}
Array arr = new ArrayImpl();
String name;
Iterator<String> it = names.iterator();
while (it.hasNext()) {
name = it.next();
if (Constants.isComponentExtension(ResourceUtil.getExtension(name, ""))) {
name = ResourceUtil.removeExtension(name, name);
}
arr.appendEL(name);
}
return arr;
}
use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class DeserializeJSON method toData.
private static Array[] toData(Object obj, Key[] columns) throws PageException {
if (columns == null)
return null;
Array arr = Caster.toArray(obj, null);
if (arr != null) {
Array[] datas = new Array[columns.length];
for (int i = 0; i < datas.length; i++) {
datas[i] = new ArrayImpl();
}
Array data;
Iterator<Object> it = arr.valueIterator();
while (it.hasNext()) {
data = Caster.toArray(it.next(), null);
if (data == null || data.size() != datas.length)
return null;
for (int i = 0; i < datas.length; i++) {
datas[i].appendEL(toQuery(data.get(i + 1, null)));
}
}
return datas;
}
return null;
}
use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class SerializeJSON method _call.
private static String _call(PageContext pc, Object var, Object options, Charset charset) throws PageException {
try {
JSONConverter json = new JSONConverter(true, charset);
if (Decision.isBoolean(options))
return json.serialize(pc, var, Caster.toBoolean(options));
if (Decision.isQuery(var)) {
if (Decision.isSimpleValue(options)) {
String opt = Caster.toString(options);
if ("struct".equalsIgnoreCase(opt)) {
Array arr = new ArrayImpl();
ForEachQueryIterator it = new ForEachQueryIterator((Query) var, pc.getId());
try {
while (it.hasNext()) {
// append each record from the query as a struct
arr.append(it.next());
}
} finally {
it.reset();
}
return json.serialize(pc, arr, false);
}
} else if (Decision.isBoolean(options)) {
return json.serialize(pc, var, Caster.toBoolean(options));
} else
throw new FunctionException(pc, SerializeJSON.class.getSimpleName(), 2, "options", "When var is a Query, argument [options] must be either a boolean value or a string with the value of [struct]");
}
// var is not a query so options doesn't make a difference here
return json.serialize(pc, var, false);
} catch (ConverterException e) {
throw Caster.toPageException(e);
}
}
Aggregations