use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.
the class ArrayFunctions method _asort_impl.
protected static boolean _asort_impl(Environment env, TraceInfo trace, @Reference Memory array, Comparator comparator) {
if (expecting(env, trace, 1, array, ARRAY)) {
ArrayMemory arrayMemory = array.toValue(ArrayMemory.class);
Memory[] values = new Memory[arrayMemory.size()];
ForeachIterator iterator = arrayMemory.getNewIterator(env);
int i = 0;
while (iterator.next()) {
values[i++] = new KeyValueMemory(iterator.getMemoryKey(), iterator.getValue());
}
arrayMemory.clear();
try {
Arrays.sort(values, comparator);
} catch (IllegalArgumentException e) {
return false;
}
for (Memory value : values) {
arrayMemory.add(value);
}
return true;
} else {
return false;
}
}
use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.
the class ArrayFunctions method _array_walk_recursive.
public static boolean _array_walk_recursive(Environment env, TraceInfo trace, Memory input, Invoker invoker, Memory userData, Set<Integer> used) throws Throwable {
if (used == null)
used = new HashSet<Integer>();
ForeachIterator iterator = input.getNewIterator(env, true, false);
while (iterator.next()) {
Memory item = iterator.getValue();
if (item.isArray()) {
if (used.add(item.getPointer())) {
boolean result = _array_walk_recursive(env, trace, item, invoker, userData, used);
used.remove(item.getPointer());
if (!result)
return false;
} else {
env.warning(trace, "array_walk_recursive(): recursion detected");
}
} else {
Memory key = iterator.getMemoryKey();
invoker.call(item, key, userData);
}
}
return true;
}
use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.
the class UISlider method __setLabelTable.
@Signature(@Arg(value = "value", type = HintType.ARRAY))
protected Memory __setLabelTable(Environment env, Memory... args) {
Hashtable<Integer, JLabel> table = new Hashtable<Integer, JLabel>();
ForeachIterator iterator = args[0].getNewIterator(env, false, false);
while (iterator.next()) {
int index = iterator.getMemoryKey().toInteger();
table.put(index, new JLabel(iterator.getValue().toString()));
}
component.setLabelTable(table);
return Memory.NULL;
}
use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.
the class ArrayFunctions method array_combine.
public static Memory array_combine(Environment env, TraceInfo trace, Memory keys, Memory values) {
if (expecting(env, trace, 1, keys, ARRAY) && expecting(env, trace, 2, values, ARRAY)) {
ArrayMemory _keys = keys.toValue(ArrayMemory.class);
ArrayMemory _values = values.toValue(ArrayMemory.class);
int size1 = _keys.size();
int size2 = _values.size();
if (size1 != size2) {
env.warning(trace, "array_combine(): Both parameters should have an equal number of elements");
return Memory.FALSE;
}
ArrayMemory result = new ArrayMemory();
if (size1 == 0)
return result.toConstant();
ForeachIterator iteratorKeys = _keys.getNewIterator(env, false, false);
ForeachIterator iteratorValues = _values.getNewIterator(env, false, false);
while (iteratorKeys.next()) {
iteratorValues.next();
result.refOfIndex(iteratorKeys.getValue()).assign(iteratorValues.getValue().toImmutable());
}
return result.toConstant();
} else
return Memory.FALSE;
}
use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.
the class ArrayFunctions method array_fill_keys.
public static Memory array_fill_keys(Environment env, TraceInfo trace, Memory keys, Memory value) {
if (expecting(env, trace, 1, keys, ARRAY)) {
ForeachIterator iterator = keys.getNewIterator(env);
ArrayMemory result = new ArrayMemory();
while (iterator.next()) {
result.refOfIndex(iterator.getValue()).assign(value.toImmutable());
}
return result.toConstant();
} else {
return new ArrayMemory().toConstant();
}
}
Aggregations