use of lucee.runtime.type.Array in project Lucee by lucee.
the class Map method _call.
public static Collection _call(PageContext pc, Object obj, UDF udf, boolean parallel, int maxThreads, Query resQry, short type) throws PageException {
ExecutorService execute = null;
List<Future<Data<Object>>> futures = null;
if (parallel) {
execute = Executors.newFixedThreadPool(maxThreads);
futures = new ArrayList<Future<Data<Object>>>();
}
Collection coll;
// Array
if (type == TYPE_ARRAY) {
coll = invoke(pc, (Array) obj, udf, execute, futures);
} else // Query
if (type == TYPE_QUERY) {
coll = invoke(pc, (Query) obj, udf, execute, futures, resQry);
} else // Struct
if (type == TYPE_STRUCT) {
coll = invoke(pc, (Struct) obj, udf, execute, futures);
} else // Array
if (obj instanceof Array) {
coll = invoke(pc, (Array) obj, udf, execute, futures);
} else // Query
if (obj instanceof Query) {
coll = invoke(pc, (Query) obj, udf, execute, futures, resQry);
} else // Struct
if (obj instanceof Struct) {
coll = invoke(pc, (Struct) obj, udf, execute, futures);
} else // other Iteratorable
if (obj instanceof Iteratorable) {
coll = invoke(pc, (Iteratorable) obj, udf, execute, futures);
} else // Map
if (obj instanceof java.util.Map) {
coll = invoke(pc, (java.util.Map) obj, udf, execute, futures);
} else // List
if (obj instanceof List) {
coll = invoke(pc, (List) obj, udf, execute, futures);
} else // Iterator
if (obj instanceof Iterator) {
coll = invoke(pc, (Iterator) obj, udf, execute, futures);
} else // Enumeration
if (obj instanceof Enumeration) {
coll = invoke(pc, (Enumeration) obj, udf, execute, futures);
} else // String List
if (obj instanceof StringListData) {
coll = invoke(pc, (StringListData) obj, udf, execute, futures);
} else
throw new FunctionException(pc, "Map", 1, "data", "cannot iterate througth this type " + Caster.toTypeName(obj.getClass()));
if (parallel)
afterCall(pc, coll, futures, execute);
return coll;
}
use of lucee.runtime.type.Array in project Lucee by lucee.
the class Some method _call.
public static boolean _call(PageContext pc, Object obj, UDF udf, boolean parallel, int maxThreads, short type) throws PageException {
ExecutorService execute = null;
List<Future<Data<Object>>> futures = null;
if (parallel) {
execute = Executors.newFixedThreadPool(maxThreads);
futures = new ArrayList<Future<Data<Object>>>();
}
boolean res;
// Array
if (type == TYPE_ARRAY) {
res = invoke(pc, (Array) obj, udf, execute, futures);
} else // Query
if (type == TYPE_QUERY) {
res = invoke(pc, (Query) obj, udf, execute, futures);
} else // Struct
if (type == TYPE_STRUCT) {
res = invoke(pc, (Struct) obj, udf, execute, futures);
} else // Array
if (obj instanceof Array) {
res = invoke(pc, (Array) obj, udf, execute, futures);
} else // Query
if (obj instanceof Query) {
res = invoke(pc, (Query) obj, udf, execute, futures);
} else // Struct
if (obj instanceof Struct) {
res = invoke(pc, (Struct) obj, udf, execute, futures);
} else // other Iteratorable
if (obj instanceof Iteratorable) {
res = invoke(pc, (Iteratorable) obj, udf, execute, futures);
} else // Map
if (obj instanceof java.util.Map) {
res = invoke(pc, (java.util.Map) obj, udf, execute, futures);
} else // List
if (obj instanceof List) {
res = invoke(pc, (List) obj, udf, execute, futures);
} else // Iterator
if (obj instanceof Iterator) {
res = invoke(pc, (Iterator) obj, udf, execute, futures);
} else // Enumeration
if (obj instanceof Enumeration) {
res = invoke(pc, (Enumeration) obj, udf, execute, futures);
} else // String List
if (obj instanceof StringListData) {
res = invoke(pc, (StringListData) obj, udf, execute, futures);
} else
throw new FunctionException(pc, "Some", 1, "data", "cannot iterate througth this type " + Caster.toTypeName(obj.getClass()));
if (parallel)
res = afterCall(pc, futures, execute);
return res;
}
use of lucee.runtime.type.Array 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.Array 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.Array in project Lucee by lucee.
the class DeserializeJSON method toQuery.
// {"COLUMNS":["AAA","BBB"],"DATA":[["a","b"],["c","d"]]}
// {"ROWCOUNT":2,"COLUMNS":["AAA","BBB"],"DATA":{"aaa":["a","c"],"bbb":["b","d"]}}
private static Object toQuery(Object obj) throws PageException {
if (obj instanceof Struct) {
Struct sct = (Struct) obj;
Key[] keys = CollectionUtil.keys(sct);
// Columns
Key[] columns = null;
if (contains(keys, KeyConstants._COLUMNS))
columns = toColumns(sct.get(KeyConstants._COLUMNS, null));
else if (contains(keys, KeyConstants._COLUMNLIST))
columns = toColumnlist(sct.get(KeyConstants._COLUMNLIST, null));
// rowcount
int rowcount = -1;
if (contains(keys, ROWCOUNT))
rowcount = toRowCount(sct.get(ROWCOUNT, null));
else if (contains(keys, KeyConstants._RECORDCOUNT))
rowcount = toRowCount(sct.get(KeyConstants._RECORDCOUNT, null));
if (columns != null) {
if (keys.length == 2 && contains(keys, KeyConstants._DATA)) {
Array[] data = toData(sct.get(KeyConstants._DATA, null), columns);
if (data != null) {
return new QueryImpl(columns, data, "query");
}
} else if (keys.length == 3 && rowcount != -1 && contains(keys, KeyConstants._DATA)) {
Array[] data = toData(sct.get(KeyConstants._DATA, null), columns, rowcount);
if (data != null) {
return new QueryImpl(columns, data, "query");
}
}
}
return toQuery(sct, keys);
} else /*else if(obj instanceof Query) {
return toQuery((Query) obj);
}*/
if (obj instanceof Collection) {
Collection coll = (Collection) obj;
return toQuery(coll, CollectionUtil.keys(coll));
}
return obj;
}
Aggregations