use of lucee.runtime.type.Array in project Lucee by lucee.
the class ArrayFindAll method find.
public static Array find(Array array, Object value, boolean caseSensitive) throws PageException {
Array rtn = new ArrayImpl();
int len = array.size();
boolean valueIsSimple = Decision.isSimpleValue(value);
Object o;
for (int i = 1; i <= len; i++) {
o = array.get(i, null);
if (o != null && Operator.equals(o, value, caseSensitive, !valueIsSimple)) {
rtn.appendEL(Caster.toDouble(i));
}
}
return rtn;
}
use of lucee.runtime.type.Array in project Lucee by lucee.
the class ArrayReverse method call.
public static Array call(PageContext pc, Array array) throws ExpressionException {
Array rev = ArrayUtil.getInstance(array.getDimension());
int len = array.size();
for (int i = 0; i < len; i++) {
try {
rev.setE(len - i, array.getE(i + 1));
} catch (PageException e) {
}
}
return rev;
}
use of lucee.runtime.type.Array in project Lucee by lucee.
the class ArraySlice method get.
private static Array get(Array arr, int from, int to) throws PageException {
Array rtn = ArrayUtil.getInstance(arr.getDimension());
int[] keys = arr.intKeys();
for (int i = 0; i < keys.length; i++) {
int key = keys[i];
if (key < from)
continue;
if (to > 0 && key > to)
break;
rtn.append(arr.getE(key));
}
return rtn;
}
use of lucee.runtime.type.Array in project Lucee by lucee.
the class CacheClear method _call.
private static double _call(PageContext pc, Object filterOrTags, String cacheName) throws PageException {
try {
Object filter = FILTER;
// tags
boolean isArray = false;
String dsn = null;
if ((isArray = Decision.isArray(filterOrTags)) || Decision.isStruct(filterOrTags)) {
// read tags from collection and datasource (optional)
String[] tags;
if (!isArray) {
Struct sct = Caster.toStruct(filterOrTags);
Array arr = Caster.toArray(sct.get("tags", null), null);
if (arr == null)
throw new FunctionException(pc, "CacheClear", 1, "tags", "if you pass the tags within a struct, that struct need to have a key [tags] containing the tags in an array.");
tags = ListUtil.toStringArray(arr);
dsn = Caster.toString(sct.get(KeyConstants._datasource, null), null);
} else {
tags = ListUtil.toStringArray(Caster.toArray(filterOrTags));
}
// get default datasource
if (StringUtil.isEmpty(dsn)) {
Object tmp = pc.getApplicationContext().getDefDataSource();
dsn = tmp instanceof CharSequence ? Caster.toString(tmp, null) : null;
}
filter = new QueryTagFilter(tags, StringUtil.isEmpty(dsn) ? null : dsn);
} else // filter
{
String strFilter = Caster.toString(filterOrTags);
if (CacheGetAllIds.isFilter(strFilter))
filter = new WildCardFilter(strFilter, true);
}
Cache cache = CacheUtil.getCache(pc, cacheName, Config.CACHE_TYPE_OBJECT);
if (filter instanceof CacheKeyFilter)
return cache.remove((CacheKeyFilter) filter);
return cache.remove((CacheEntryFilter) filter);
} catch (Exception e) {
throw Caster.toPageException(e);
}
}
use of lucee.runtime.type.Array in project Lucee by lucee.
the class CacheGetAllIds method call.
public static Array call(PageContext pc, String filter, String cacheName) throws PageException {
try {
Cache cache = CacheUtil.getCache(pc, cacheName, Config.CACHE_TYPE_OBJECT);
List<String> keys = isFilter(filter) ? cache.keys(new WildCardFilter(filter, true)) : cache.keys();
Iterator<String> it = keys.iterator();
Array arr = new ArrayImpl();
while (it.hasNext()) {
arr.append(it.next());
}
return arr;
} catch (Exception e) {
throw Caster.toPageException(e);
}
}
Aggregations