use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class Caster method toArray.
/**
* cast a Object to a Array Object
* @param o Object to cast
* @param defaultValue
* @return casted Array
*/
public static Array toArray(Object o, Array defaultValue) {
if (o instanceof Array)
return (Array) o;
else if (o instanceof Object[]) {
return new ArrayImpl((Object[]) o);
} else if (o instanceof List) {
return new ArrayImpl(((List) o).toArray());
} else if (o instanceof Set) {
return new ArrayImpl(((Set) o).toArray());
} else if (o instanceof XMLStruct) {
Array arr = new ArrayImpl();
arr.appendEL(o);
return arr;
} else if (o instanceof ObjectWrap) {
return toArray(((ObjectWrap) o).getEmbededObject(defaultValue), defaultValue);
// if(io!=null)return toArray(io,defaultValue);
} else if (o instanceof Struct) {
Struct sct = (Struct) o;
Array arr = new ArrayImpl();
Iterator<Entry<Key, Object>> it = sct.entryIterator();
Entry<Key, Object> e = null;
try {
while (it.hasNext()) {
e = it.next();
arr.setEL(toIntValue(e.getKey().getString()), e.getValue());
}
} catch (ExpressionException ee) {
return defaultValue;
}
return arr;
} else if (o instanceof boolean[])
return new ArrayImpl(ArrayUtil.toReferenceType((boolean[]) o));
else if (o instanceof byte[])
return new ArrayImpl(ArrayUtil.toReferenceType((byte[]) o));
else if (o instanceof char[])
return new ArrayImpl(ArrayUtil.toReferenceType((char[]) o));
else if (o instanceof short[])
return new ArrayImpl(ArrayUtil.toReferenceType((short[]) o));
else if (o instanceof int[])
return new ArrayImpl(ArrayUtil.toReferenceType((int[]) o));
else if (o instanceof long[])
return new ArrayImpl(ArrayUtil.toReferenceType((long[]) o));
else if (o instanceof float[])
return new ArrayImpl(ArrayUtil.toReferenceType((float[]) o));
else if (o instanceof double[])
return new ArrayImpl(ArrayUtil.toReferenceType((double[]) o));
return defaultValue;
}
use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class GetFunctionData method javaBasedFunction.
private static Struct javaBasedFunction(FunctionLibFunction function) throws PageException {
Struct sct = new StructImpl();
sct.set(KeyConstants._name, function.getName());
sct.set(KeyConstants._status, TagLibFactory.toStatus(function.getStatus()));
if (function.getIntroduced() != null)
sct.set(INTRODUCED, function.getIntroduced().toString());
// else if(inside.equals("introduced")) att.setIntroduced(value);
sct.set(KeyConstants._description, StringUtil.emptyIfNull(function.getDescription()));
if (!ArrayUtil.isEmpty(function.getKeywords()))
sct.set("keywords", Caster.toArray(function.getKeywords()));
sct.set(RETURN_TYPE, StringUtil.emptyIfNull(function.getReturnTypeAsString()));
sct.set(ARGUMENT_TYPE, StringUtil.emptyIfNull(function.getArgTypeAsString()));
sct.set(ARG_MIN, Caster.toDouble(function.getArgMin()));
sct.set(ARG_MAX, Caster.toDouble(function.getArgMax()));
sct.set(KeyConstants._type, "java");
String[] names = function.getMemberNames();
if (!ArrayUtil.isEmpty(names) && function.getMemberType() != CFTypes.TYPE_UNKNOW) {
StructImpl mem = new StructImpl();
sct.set(KeyConstants._member, mem);
mem.set(KeyConstants._name, names[0]);
mem.set(KeyConstants._chaining, Caster.toBoolean(function.getMemberChaining()));
mem.set(KeyConstants._type, function.getMemberTypeAsString());
mem.set("position", Caster.toDouble(function.getMemberPosition()));
}
Array _args = new ArrayImpl();
sct.set(KeyConstants._arguments, _args);
if (function.getArgType() != FunctionLibFunction.ARG_DYNAMIC) {
ArrayList<FunctionLibFunctionArg> args = function.getArg();
for (int i = 0; i < args.size(); i++) {
FunctionLibFunctionArg arg = args.get(i);
Struct _arg = new StructImpl();
_arg.set(KeyConstants._required, arg.getRequired() ? Boolean.TRUE : Boolean.FALSE);
_arg.set(KeyConstants._type, StringUtil.emptyIfNull(arg.getTypeAsString()));
_arg.set(KeyConstants._name, StringUtil.emptyIfNull(arg.getName()));
_arg.set(KeyConstants._status, TagLibFactory.toStatus(arg.getStatus()));
if (arg.getIntroduced() != null)
_arg.set(INTRODUCED, arg.getIntroduced().toString());
_arg.set("defaultValue", arg.getDefaultValue());
_arg.set(KeyConstants._description, StringUtil.toStringEmptyIfNull(arg.getDescription()));
_args.append(_arg);
}
}
return sct;
}
use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class QueryNew method _populate.
private static Query _populate(PageContext pc, Query qry, Struct data) throws PageException {
Iterator<Entry<Key, Object>> it = data.entryIterator();
Entry<Key, Object> e;
Object v;
Array arr;
int rows = qry.getRecordcount();
while (it.hasNext()) {
e = it.next();
if (qry.getColumn(e.getKey(), null) != null) {
v = e.getValue();
arr = Caster.toArray(v, null);
if (arr == null)
arr = new ArrayImpl(new Object[] { v });
populateColumn(qry, e.getKey(), arr, rows);
}
}
return qry;
}
use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class FontUtil method getAvailableFontsAsStringArray.
public static Array getAvailableFontsAsStringArray() {
Iterator<Object> it = getAvailableFonts(false).valueIterator();
Array arr = new ArrayImpl();
while (it.hasNext()) {
arr.appendEL(((Font) it.next()).getFontName());
}
return arr;
}
use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class FontUtil method getAvailableFonts.
private static Array getAvailableFonts(boolean duplicate) {
synchronized (sync) {
if (fonts == null) {
fonts = new ArrayImpl();
GraphicsEnvironment graphicsEvn = GraphicsEnvironment.getLocalGraphicsEnvironment();
Font[] availableFonts = graphicsEvn.getAllFonts();
for (int i = 0; i < availableFonts.length; i++) {
fonts.appendEL(availableFonts[i]);
}
}
if (!duplicate)
return fonts;
return (Array) Duplicator.duplicate(fonts, false);
}
}
Aggregations