Search in sources :

Example 66 with Array

use of lucee.runtime.type.Array in project Lucee by lucee.

the class StructFindKey method _call.

private static Array _call(PageContext pc, Struct struct, String value, boolean all) throws PageException {
    Array array = new ArrayImpl();
    getValues(array, struct, value, all, "");
    return array;
}
Also used : ListAsArray(lucee.runtime.type.wrap.ListAsArray) Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl)

Example 67 with Array

use of lucee.runtime.type.Array in project Lucee by lucee.

the class StructFindValue method call.

public static Array call(PageContext pc, Struct struct, String value, String scope) throws PageException {
    // Scope
    boolean all = false;
    if (scope.equalsIgnoreCase("one"))
        all = false;
    else if (scope.equalsIgnoreCase("all"))
        all = true;
    else
        throw new FunctionException(pc, "structFindValue", 3, "scope", "invalid scope definition [" + scope + "], valid scopes are [one, all]");
    Array array = new ArrayImpl();
    getValues(pc, array, struct, value, all, "");
    return array;
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl) FunctionException(lucee.runtime.exp.FunctionException)

Example 68 with Array

use of lucee.runtime.type.Array in project Lucee by lucee.

the class StructSort method call.

public static Array call(PageContext pc, Struct base, String sortType, String sortOrder, String pathToSubElement) throws PageException {
    boolean isAsc = true;
    PageException ee = null;
    if (sortOrder.equalsIgnoreCase("asc"))
        isAsc = true;
    else if (sortOrder.equalsIgnoreCase("desc"))
        isAsc = false;
    else
        throw new ExpressionException("invalid sort order type [" + sortOrder + "], sort order types are [asc and desc]");
    Collection.Key[] keys = CollectionUtil.keys(base);
    SortRegister[] arr = new SortRegister[keys.length];
    boolean hasSubDef = pathToSubElement != null;
    for (int i = 0; i < keys.length; i++) {
        Object value = base.get(keys[i], null);
        if (hasSubDef) {
            value = VariableInterpreter.getVariable(pc, Caster.toCollection(value), pathToSubElement);
        }
        arr[i] = new SortRegister(i, value);
    }
    ExceptionComparator comp = null;
    // text
    if (sortType.equalsIgnoreCase("text"))
        comp = new SortRegisterComparator(pc, isAsc, false, true);
    else // text no case
    if (sortType.equalsIgnoreCase("textnocase"))
        comp = new SortRegisterComparator(pc, isAsc, true, true);
    else // numeric
    if (sortType.equalsIgnoreCase("numeric"))
        comp = new NumberSortRegisterComparator(isAsc);
    else {
        throw new ExpressionException("invalid sort type [" + sortType + "], sort types are [text, textNoCase, numeric]");
    }
    Arrays.sort(arr, 0, arr.length, comp);
    ee = comp.getPageException();
    if (ee != null) {
        throw ee;
    }
    Array rtn = new ArrayImpl();
    for (int i = 0; i < arr.length; i++) {
        rtn.append(keys[arr[i].getOldPosition()].getString());
    }
    return rtn;
}
Also used : PageException(lucee.runtime.exp.PageException) ArrayImpl(lucee.runtime.type.ArrayImpl) ExpressionException(lucee.runtime.exp.ExpressionException) SortRegister(lucee.runtime.type.comparator.SortRegister) ExceptionComparator(lucee.runtime.type.comparator.ExceptionComparator) Array(lucee.runtime.type.Array) SortRegisterComparator(lucee.runtime.type.comparator.SortRegisterComparator) NumberSortRegisterComparator(lucee.runtime.type.comparator.NumberSortRegisterComparator) NumberSortRegisterComparator(lucee.runtime.type.comparator.NumberSortRegisterComparator)

Example 69 with Array

use of lucee.runtime.type.Array in project Lucee by lucee.

the class BundleInfo method toArray2.

private static Array toArray2(List<PackageQuery> list) {
    Struct sct, _sct;
    Array arr = new ArrayImpl(), _arr;
    Iterator<PackageQuery> it = list.iterator();
    PackageQuery pd;
    Iterator<VersionDefinition> _it;
    VersionDefinition vd;
    while (it.hasNext()) {
        pd = it.next();
        sct = new StructImpl();
        sct.setEL(KeyConstants._package, pd.getName());
        sct.setEL("versions", _arr = new ArrayImpl());
        _it = pd.getVersionDefinitons().iterator();
        while (_it.hasNext()) {
            vd = _it.next();
            _sct = new StructImpl();
            _sct.setEL(KeyConstants._bundleVersion, vd.getVersion().toString());
            _sct.setEL("operator", vd.getOpAsString());
            _arr.appendEL(_sct);
        }
        arr.appendEL(sct);
    }
    return arr;
}
Also used : Array(lucee.runtime.type.Array) VersionDefinition(lucee.runtime.osgi.OSGiUtil.VersionDefinition) StructImpl(lucee.runtime.type.StructImpl) PackageQuery(lucee.runtime.osgi.OSGiUtil.PackageQuery) ArrayImpl(lucee.runtime.type.ArrayImpl) Struct(lucee.runtime.type.Struct)

Example 70 with Array

use of lucee.runtime.type.Array in project Lucee by lucee.

the class BundleInfo method toArray1.

private static Array toArray1(List<BundleDefinition> list) {
    Struct sct;
    Array arr = new ArrayImpl();
    Iterator<BundleDefinition> it = list.iterator();
    BundleDefinition bd;
    VersionDefinition vd;
    while (it.hasNext()) {
        bd = it.next();
        sct = new StructImpl();
        sct.setEL(KeyConstants._bundleName, bd.getName());
        vd = bd.getVersionDefiniton();
        if (vd != null) {
            sct.setEL(KeyConstants._bundleVersion, vd.getVersionAsString());
            sct.setEL("operator", vd.getOpAsString());
        }
        arr.appendEL(sct);
    }
    return arr;
}
Also used : Array(lucee.runtime.type.Array) BundleDefinition(lucee.runtime.osgi.OSGiUtil.BundleDefinition) VersionDefinition(lucee.runtime.osgi.OSGiUtil.VersionDefinition) StructImpl(lucee.runtime.type.StructImpl) ArrayImpl(lucee.runtime.type.ArrayImpl) Struct(lucee.runtime.type.Struct)

Aggregations

Array (lucee.runtime.type.Array)169 ArrayImpl (lucee.runtime.type.ArrayImpl)79 Struct (lucee.runtime.type.Struct)49 StructImpl (lucee.runtime.type.StructImpl)25 Iterator (java.util.Iterator)24 PageException (lucee.runtime.exp.PageException)23 Entry (java.util.Map.Entry)22 ArrayList (java.util.ArrayList)20 Key (lucee.runtime.type.Collection.Key)20 ListIterator (java.util.ListIterator)16 Query (lucee.runtime.type.Query)16 List (java.util.List)14 ApplicationException (lucee.runtime.exp.ApplicationException)14 FunctionException (lucee.runtime.exp.FunctionException)14 ForEachQueryIterator (lucee.runtime.type.it.ForEachQueryIterator)14 Resource (lucee.commons.io.res.Resource)13 IOException (java.io.IOException)12 Collection (lucee.runtime.type.Collection)10 QueryImpl (lucee.runtime.type.QueryImpl)10 JavaObject (lucee.runtime.java.JavaObject)8